From 75473317051a58958bbee0d441d935248e76b5ef Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 29 Apr 2024 12:39:44 +0200 Subject: [PATCH 1/3] added rules for operators --- src/yacc/parser.y | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 2ee4e7d..7e3ef61 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -55,6 +55,13 @@ %token FunLineno %token FunExtsupport +/* Operator associativity */ +%right '=' +%left '+' '-' '*' '/' +%left OpEquals OpNot +%left OpAnd OpOr OpXor +%left OpBitand OpBitor OpBitxor OpBitnot + %% program: assign | definition; @@ -63,7 +70,8 @@ expr: ValFloat | ValInt | ValMultistr | ValStr - | Ident; + | Ident + | operation; assign: Ident '=' expr { DEBUG("Assignment"); }; @@ -89,7 +97,28 @@ type: sign scale Ident | sign scale KeyInt | sign scale KeyFloat; +operation: oparith + | oplogic + | opbool + | opbit; +oparith: expr '+' expr + | expr '-' expr + | expr '*' expr + | expr '/' expr + | '-' expr %prec '*'; + +oplogic: expr OpEquals expr; + +opbool: expr OpAnd expr + | expr OpOr expr + | expr OpXor expr + | OpNot expr %prec OpAnd; + +opbit: expr OpBitand expr + | expr OpBitor expr + | expr OpBitxor expr + | OpBitnot expr %prec OpBitand; %% From 970b45ac3c90a3b43ec1b353dd77999a4138aff3 Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 30 Apr 2024 11:51:59 +0200 Subject: [PATCH 2/3] added less and greater operator --- prog.gem | 1 + src/yacc/parser.y | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 prog.gem diff --git a/prog.gem b/prog.gem new file mode 100644 index 0000000..d4504b9 --- /dev/null +++ b/prog.gem @@ -0,0 +1 @@ +foo(1,2,bar) \ No newline at end of file diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 7e3ef61..4941825 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -58,7 +58,7 @@ /* Operator associativity */ %right '=' %left '+' '-' '*' '/' -%left OpEquals OpNot +%left OpEquals OpNot '<' '>' %left OpAnd OpOr OpXor %left OpBitand OpBitor OpBitxor OpBitnot @@ -108,7 +108,9 @@ oparith: expr '+' expr | expr '/' expr | '-' expr %prec '*'; -oplogic: expr OpEquals expr; +oplogic: expr OpEquals expr + | expr '<' expr + | expr '>' expr; opbool: expr OpAnd expr | expr OpOr expr From bd9d28d06932badcc8df3c9383b95cf69cfffb09 Mon Sep 17 00:00:00 2001 From: servostar Date: Sun, 5 May 2024 21:13:38 +0200 Subject: [PATCH 3/3] removed unnecessary file prog.gem --- prog.gem | 1 - 1 file changed, 1 deletion(-) delete mode 100644 prog.gem diff --git a/prog.gem b/prog.gem deleted file mode 100644 index d4504b9..0000000 --- a/prog.gem +++ /dev/null @@ -1 +0,0 @@ -foo(1,2,bar) \ No newline at end of file