File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -861,11 +861,7 @@ conditionalExpression:
861861 debugYacc("BooleanExpression from variable "+ $1, AT);
862862 $$ = new BooleanExpression($1);
863863 }
864- // | LEFT_PARENTHESIS conditionalExpression RIGHT_PARENTHESIS {
865- // TranslatedNode* parenthCond= new TranslatedNode("("+ $2->translate() +")");
866- // delete $2;
867- // $$ = parenthCond;
868- // }
864+ | LEFT_PARENTHESIS conditionalExpression RIGHT_PARENTHESIS { $$ = $2; }
869865| conditionalExpression logicalOperator conditionalExpression {
870866 BooleanExpression* expr= new BooleanExpression($2,$1,$3);
871867 $$ = expr;
@@ -1015,12 +1011,6 @@ integerExpression:
10151011| NAME { $$ = new TranslatedNode($1); }
10161012;
10171013
1018- // numberExpression:
1019- // NUM_INTEGER { /* $$ = Integer(to_string($1)); */ }
1020- // | NUM_REAL { /* $$ = Real($1); */ }
1021- // | NAME { /* $$ = String($1); */ }
1022- // ;
1023-
10241014/* ******************
10251015 * OPERATORS *
10261016 * ******************/
Original file line number Diff line number Diff line change @@ -18,9 +18,7 @@ If::~If()
1818
1919string If::preTranslate () const
2020{
21- string res=" if(" + mCondition ->translate () + " ) " ;
22-
23- res+= " {\n " ;
21+ string res=" if " + mCondition ->translate () + " {\n " ;
2422
2523 // the instructions are in the left_son (the first one IS the left son)
2624
Original file line number Diff line number Diff line change @@ -19,5 +19,5 @@ string Repeat::preTranslate() const
1919
2020string Repeat::postTranslate () const
2121{
22- return " } while( " + mCondition ->translate () + " ) ;\n " ;
22+ return " } while " + mCondition ->translate () + " ;\n " ;
2323}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ While::~While()
1414
1515
1616string While::preTranslate () const {
17- return " while ( " + mCondition ->translate () + " ) {\n " ;
17+ return " while " + mCondition ->translate () + " {\n " ;
1818}
1919
2020string While::postTranslate () const
Original file line number Diff line number Diff line change @@ -29,21 +29,27 @@ BooleanExpression::~BooleanExpression()
2929}
3030
3131string BooleanExpression::preTranslate () const {
32- string res= " " ;
32+ string res= " ( " ;
3333
3434 if (value != " " ) {
3535 debug (" Cond. Expr., just value" , AT);
3636 res+= value;
3737 } else {
3838 // Two operandes case
3939 if (left_part != nullptr ) {
40- debug (" Cond. Expr.: binary operator" , AT);
4140 res+= left_part->translate () +" " ;
4241 }
43- if (right_part != nullptr && mOperator != nullptr ) res+= mOperator ->translate () + " " + right_part->translate ();
42+ if (right_part != nullptr && mOperator != nullptr ) {
43+ debug (" Cond. Expr.: binary operator" , AT);
44+ res+= mOperator ->translate () + " " + right_part->translate ();
45+ }
4446 // There is no right part or operator whereas there is a left part
4547 else error (" BooleanExpression is not correctly initialized (no operator or right part)" , AT);
48+
4649 }
50+
51+ res+= " )" ;
52+
4753 return res;
4854
4955}
Original file line number Diff line number Diff line change @@ -64,4 +64,18 @@ a multiple lines comment
6464 m is map of <string, integer>
6565 s is set of string
6666
67+
68+ if true or true and false
69+ then print "Cond expr with no parenthesis priority working"
70+ else print "Cond expr with no parenthesis priority not working"
71+ end if
72+
73+ if (false and true) or true
74+ then print "Cond expr with parenthesis left first working"
75+ end if
76+
77+ if true or (true and false)
78+ then print "Cond expr with parenthesis right first working"
79+ end if
80+
6781end
You can’t perform that action at this time.
0 commit comments