Loading node.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ void NBinaryOperator::printNode(std::ostream &o) { void NUnaryOperator::printNode(std::ostream &o) { o << tokenToString(op) << " "; exp->printNode(o); } Loading parser.y +25 −5 Original line number Diff line number Diff line Loading @@ -81,11 +81,30 @@ std::unique_ptr<T> UNIQUE(T *ptr) { return std::unique_ptr<T>(ptr); } %type <cond> cond %type <token> unop %type <token> binop /*%type <token> unop %type <token> binop*/ %type <token> compop /* precedence to solve shift/reduce conflicts explicitly */ %precedence TOK_THEN %precedence TOK_ELSE /* operator associativity to avoid shift/reduce conflicts */ /* %left TOK_OR %left TOK_AND %left TOK_LSHIFT TOK_RSHIFT %left TOK_PLUS TOK_MINUS %left TOK_MUL TOK_DIV */ %left TOK_OR TOK_AND TOK_LSHIFT TOK_RSHIFT TOK_PLUS TOK_MINUS TOK_MUL TOK_DIV ANY_BINOP %type <token> binop %type <token> unop %right UNARY_MINUS %start program Loading Loading @@ -160,7 +179,8 @@ ident : TOK_ID { $$ = new NIdentifier(*$1); delete $1; } literal : TOK_INT { $$ = new NInteger(*$1); delete $1; } ; binop : TOK_PLUS | TOK_MINUS | TOK_MUL | TOK_DIV | TOK_AND | TOK_OR ; binop : TOK_PLUS | TOK_MINUS | TOK_MUL | TOK_DIV | TOK_AND | TOK_OR | TOK_LSHIFT | TOK_RSHIFT; compop : TOK_EQ | TOK_NE | TOK_GT | TOK_GE | TOK_LT | TOK_LE ; Loading @@ -175,8 +195,8 @@ variable : ident { $$ = new NBitfieldVariable(UNIQUE($1)); } expr : variable { $$ = $1; } | literal { $$ = $1; } | unop expr { $$ = new NUnaryOperator($1, UNIQUE($2)); } | expr binop expr { $$ = new NBinaryOperator($2, UNIQUE($1), UNIQUE($3)); } | unop expr %prec UNARY_MINUS { $$ = new NUnaryOperator($1, UNIQUE($2)); } | expr binop expr %prec ANY_BINOP { $$ = new NBinaryOperator($2, UNIQUE($1), UNIQUE($3)); } | TOK_LPAR expr TOK_RPAR { $$ = $2; } ; Loading Loading
node.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,7 @@ void NBinaryOperator::printNode(std::ostream &o) { void NUnaryOperator::printNode(std::ostream &o) { o << tokenToString(op) << " "; exp->printNode(o); } Loading
parser.y +25 −5 Original line number Diff line number Diff line Loading @@ -81,11 +81,30 @@ std::unique_ptr<T> UNIQUE(T *ptr) { return std::unique_ptr<T>(ptr); } %type <cond> cond %type <token> unop %type <token> binop /*%type <token> unop %type <token> binop*/ %type <token> compop /* precedence to solve shift/reduce conflicts explicitly */ %precedence TOK_THEN %precedence TOK_ELSE /* operator associativity to avoid shift/reduce conflicts */ /* %left TOK_OR %left TOK_AND %left TOK_LSHIFT TOK_RSHIFT %left TOK_PLUS TOK_MINUS %left TOK_MUL TOK_DIV */ %left TOK_OR TOK_AND TOK_LSHIFT TOK_RSHIFT TOK_PLUS TOK_MINUS TOK_MUL TOK_DIV ANY_BINOP %type <token> binop %type <token> unop %right UNARY_MINUS %start program Loading Loading @@ -160,7 +179,8 @@ ident : TOK_ID { $$ = new NIdentifier(*$1); delete $1; } literal : TOK_INT { $$ = new NInteger(*$1); delete $1; } ; binop : TOK_PLUS | TOK_MINUS | TOK_MUL | TOK_DIV | TOK_AND | TOK_OR ; binop : TOK_PLUS | TOK_MINUS | TOK_MUL | TOK_DIV | TOK_AND | TOK_OR | TOK_LSHIFT | TOK_RSHIFT; compop : TOK_EQ | TOK_NE | TOK_GT | TOK_GE | TOK_LT | TOK_LE ; Loading @@ -175,8 +195,8 @@ variable : ident { $$ = new NBitfieldVariable(UNIQUE($1)); } expr : variable { $$ = $1; } | literal { $$ = $1; } | unop expr { $$ = new NUnaryOperator($1, UNIQUE($2)); } | expr binop expr { $$ = new NBinaryOperator($2, UNIQUE($1), UNIQUE($3)); } | unop expr %prec UNARY_MINUS { $$ = new NUnaryOperator($1, UNIQUE($2)); } | expr binop expr %prec ANY_BINOP { $$ = new NBinaryOperator($2, UNIQUE($1), UNIQUE($3)); } | TOK_LPAR expr TOK_RPAR { $$ = $2; } ; Loading