Merge branch 'parser-devel' into 40-add-parser-rule-for-calling-functions

This commit is contained in:
servostar 2024-05-06 08:51:21 +00:00 committed by GitHub
commit 96a50f4289
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 3 deletions

View File

@ -15,6 +15,8 @@
%%
"\n" yyLineNumber++;
#.* ;
":" {DEBUG("\"%s\" tokenized with \':\'", yytext); return(':');};
"=" {DEBUG("\"%s\" tokenized with \'=\'", yytext); return('=');};
"+" {DEBUG("\"%s\" tokenized with \'+\'", yytext); return('+');};
@ -24,7 +26,6 @@
"," {DEBUG("\"%s\" tokenized with \',\'", yytext); return(',');};
";" {DEBUG("\"%s\" tokenized with \';\'", yytext); return(';');};
"." {DEBUG("\"%s\" tokenized with \'.\'", yytext); return('.');};
"#" {DEBUG("\"%s\" tokenized with \'#\'", yytext); return('#');};
"(" {DEBUG("\"%s\" tokenized with \'(\'", yytext); return('(');};
")" {DEBUG("\"%s\" tokenized with \')\'", yytext); return(')');};

View File

@ -55,14 +55,22 @@
%token FunLineno
%token FunExtsupport
/* Operator associativity */
%right '='
%left '+' '-' '*' '/'
%left OpEquals OpNot '<' '>'
%left OpAnd OpOr OpXor
%left OpBitand OpBitor OpBitxor OpBitnot
%%
program: funcall;
program: statementlist;
expr: ValFloat
| ValInt
| ValMultistr
| ValStr
| Ident;
| Ident
| operation;
exprlist: expr ',' exprlist
| expr
@ -75,6 +83,24 @@ funcall: Ident paramlist { DEBUG("Function call"); };
assign: Ident '=' expr { DEBUG("Assignment"); };
statementlist: statementlist statement
| ;
statement: assign
| decl
| definition
| branch;
branchif: KeyIf expr '{' statementlist '}' { DEBUG("if"); };
branchelse: KeyElse '{' statementlist '}' { DEBUG("if-else"); };
branchelseif: KeyElse KeyIf expr '{' statementlist '}' { DEBUG("else-if"); };
branchelseifs: branchelseifs branchelseif
| ;
branch: branchif branchelseifs
| branchif branchelseifs branchelse;
identlist: Ident ',' identlist
| Ident
| ;
@ -83,6 +109,8 @@ decl: type ':' identlist { DEBUG("Declaration"); };
definition: decl '=' expr { DEBUG("Definition"); };
assign: Ident '=' expr { DEBUG("Assignment"); };
sign: KeySigned
| KeyUnsigned
| ;
@ -97,8 +125,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) {