Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Subato Learning System
SubatoScript
Commits
8fa0c06f
Commit
8fa0c06f
authored
Feb 19, 2022
by
Sven Eric Panitz
Browse files
Negation was missing (and still missing in java version)
parent
038f2033
Changes
3
Hide whitespace changes
Inline
Side-by-side
subscripJS/lib/org/subato/script/parser/BuildTree.dart
View file @
8fa0c06f
...
...
@@ -50,8 +50,9 @@ class BuildTree extends SubatoScriptBaseVisitor<STree> {
}
return
OneOf
(
es
);
}
else
{
}
else
if
(
ctx
.
NOT
()
!=
null
)
{
return
Negation
(
visit
(
ctx
.
expression
(
0
)!)!);
}
else
{
var
result
=
visit
(
ctx
.
expression
(
0
)!)!;
if
(
ctx
.
relop
()
!=
null
)
{
result
=
OpEx
(
result
,
(
visit
(
ctx
.
relop
()!)!
as
TOp
).
op
,
visit
(
ctx
.
expression
(
1
)!)!);
...
...
subscripJS/lib/org/subato/script/tree/Eval.dart
View file @
8fa0c06f
...
...
@@ -72,6 +72,16 @@ class Eval implements Visitor<Val> {
return
r
;
}
@override
Val
visitNegation
(
Negation
il
){
var
l
=
il
.
expression
.
welcome
(
this
);
if
(
l
is
BoolVal
){
return
BoolVal
(!(
l
as
BoolVal
).
b
);
}
else
{
throw
Exception
(
"logical operator needs boolean values"
);
}
}
@override
Val
visitUnaryOpEx
(
UnaryOpEx
il
)
{
var
r
=
il
.
expression
.
welcome
(
this
);
...
...
@@ -201,9 +211,10 @@ class Eval implements Visitor<Val> {
var
left
=
(
l
as
BoolVal
).
b
;
var
right
=
(
r
as
BoolVal
).
b
;
return
BoolVal
(
il
.
op
==
Op
.
AND
?
left
&&
right:
left
||
right
);
}
else
{
throw
Exception
(
"logical operator needs boolean values"
);
}
}
if
(!(
l
.
isNum
()
&&
r
.
isNum
()))
{
throw
Exception
(
"arithmetic Operator needs numeric values"
);
}
...
...
subscripJS/lib/org/subato/script/tree/Tree.dart
View file @
8fa0c06f
...
...
@@ -3,6 +3,7 @@ abstract class Visitor<R> {
R
visitIntNum
(
IntNum
il
);
R
visitDoubleNum
(
DoubleNum
il
);
R
visitVar
(
Var
il
);
R
visitNegation
(
Negation
il
);
R
visitUnaryOpEx
(
UnaryOpEx
il
);
R
visitOpEx
(
OpEx
il
);
R
visitOneOf
(
OneOf
il
);
...
...
@@ -56,6 +57,16 @@ enum Op {
EQEQ
,
NEQ
,
LT
,
LE
,
GT
,
GE
,
ADD
,
SUB
,
MUL
,
DIV
,
MOD
,
POW
,
AND
,
OR
,
NOT
}
class
Negation
implements
STree
{
STree
expression
;
Negation
(
this
.
expression
);
@override
R
welcome
<
R
>(
Visitor
<
R
>
v
){
return
v
.
visitNegation
(
this
);
}
}
class
UnaryOpEx
implements
STree
{
STree
expression
;
bool
isAdd
=
false
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment