diff --git a/src/parser/grammatical.y b/src/parser/grammatical.y index a48f188..e9cc152 100644 --- a/src/parser/grammatical.y +++ b/src/parser/grammatical.y @@ -49,15 +49,18 @@ inline void conferror(YYLTYPE *locp, yyscan_t sc, const char * str) %token IDENTIFIER %token STRING +%left DELIM +%precedence ASSIGN +%precedence IDENTIFIER /* low-priority for just identifier */ %left '-' '+' %left '*' '/' %precedence UNARY /* negation--unary minus */ %right '^' /* exponentiation */ %left '.' +%precedence OBRACE CBRACE %type longidentifier %type expression -%type call %type object %type pair %type list @@ -115,23 +118,20 @@ object: STRING {COUT(DEBUG)<<" STRING\n"; $$=new ObjectString($1); delete $1;} | BOOL {COUT(DEBUG)<<" BOOL\n"; $$=new ObjectBool($1);} | OBRACE list CBRACE {COUT(DEBUG)<<" OBRACE list CBRACE\n"; $$=$2;} - | expression {COUT(DEBUG)<<" expression\n"; $$=$1;} + | expression %prec ASSIGN {COUT(DEBUG)<<" expression\n"; $$=$1;} | pair {COUT(DEBUG)<<" pair\n"; $$=$1;} | OBRACE object CBRACE {COUT(DEBUG)<<" OBRACE object CBRACE\n"; $$=$2;} | object DELIM {COUT(DEBUG)<<" OBJECT DELIM\n"; $$=$1;} ; -call: - IDENTIFIER OBRACE object CBRACE {COUT(DEBUG)<<" IDENTIFIER OBRACE object CBRACE\n"; $$=new OFunc($1,$3); delete $1;} - | IDENTIFIER OBRACE list CBRACE {COUT(DEBUG)<<" IDENTIFIER OBRACE list CBRACE\n"; $$=new OFunc($1,$3); delete $1;} - - longidentifier: IDENTIFIER '.' IDENTIFIER {COUT(DEBUG)<<" IDENTIFIER DOT IDENTIFIER\n"; $$=new OFunc("GET",(new ObjectList(new OId($1)))->PushBack(new ObjectString($3))); delete $1; delete $3;} | longidentifier '.' IDENTIFIER {COUT(DEBUG)<<" longidentifier '.' IDENTIFIER\n"; $$=new OFunc("GET",(new ObjectList($1))->PushBack(new ObjectString($3))); delete $3;} expression: IDENTIFIER {COUT(DEBUG)<<" IDENTIFIER\n"; $$=new OId($1); delete $1;} + | IDENTIFIER OBRACE object CBRACE {COUT(DEBUG)<<" IDENTIFIER OBRACE object CBRACE\n"; $$=new OFunc($1,$3); delete $1;} + | IDENTIFIER OBRACE list CBRACE {COUT(DEBUG)<<" IDENTIFIER OBRACE list CBRACE\n"; $$=new OFunc($1,$3); delete $1;} | longidentifier {COUT(DEBUG)<<" longidentifier\n"; $$=$1;} | REAL {COUT(DEBUG)<<" REAL\n"; $$=new ObjectReal($1);} | INTEGER {COUT(DEBUG)<<" INTEGER\n"; $$=new ObjectInt($1);} @@ -143,5 +143,4 @@ expression: | '-' expression %prec UNARY {COUT(DEBUG)<<" unary -\n"; $$=new OFunc("NEG",$2);} | '+' expression %prec UNARY {COUT(DEBUG)<<" unary +\n"; $$=new OFunc("POS",$2);} | OBRACE expression CBRACE {COUT(DEBUG)<<" OBRACE expression CBRACE\n"; $$=$2;} - | call {COUT(DEBUG)<<" call\n"; $$=$1;} ;