Merge pull request #45 from Servostar/43-add-parser-rule-for-operators

added rules for operators
This commit is contained in:
servostar 2024-05-06 08:48:12 +00:00 committed by GitHub
commit 55caa37ba7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 33 additions and 1 deletions

View File

@ -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: statement;
@ -63,7 +70,8 @@ expr: ValFloat
| ValInt
| ValMultistr
| ValStr
| Ident;
| Ident
| operation;
statement: assign
| decl
@ -93,6 +101,30 @@ 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
| expr '<' expr
| expr '>' 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;
%%
int yyerror(char *s) {