From f6df1926860fe795ad4b3e68cd1c63e4a65c3fcc Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 26 Apr 2024 16:53:04 +0200 Subject: [PATCH 01/22] added counter examples to yacc --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cfeefc..56da828 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ set(YACC_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c) add_custom_command(OUTPUT ${YACC_GENERATED_SOURCE_FILE} COMMAND yacc - ARGS -d -o ${YACC_GENERATED_SOURCE_FILE} ${YACC_SOURCE_FILE} + ARGS -Wcounterexamples -d -o ${YACC_GENERATED_SOURCE_FILE} ${YACC_SOURCE_FILE} COMMENT "generate C source file for parser" VERBATIM) From 3c0a885186b29dcfc48578ce93b8cbf16892dfa7 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 26 Apr 2024 16:53:41 +0200 Subject: [PATCH 02/22] added parser rules for declaration, assignment, definition --- src/yacc/parser.y | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 8dc3d64..c158dec 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -56,7 +56,35 @@ %token FunExtsupport %% -program: ; +program: assign + | definition; + +expr: ValFloat + | ValInt + | ValMultistr + | ValStr + | Ident; + +assign: Ident '=' expr { DEBUG("Assignment"); }; + +decl: type ':' Ident { DEBUG("Declaration"); }; + +definition: decl '=' expr { DEBUG("Definition"); }; + +sign: KeySigned + | KeyUnsigned + | ; + +scale: scale KeyShort + | scale KeyHalf + | scale KeyLong + | scale KeyDouble + | ; + +type: Ident + | sign scale KeyInt + | sign scale KeyFloat; + %% int yyerror(char *s) { From dd867db271e4f8e7005c785033377bdad2dd22d5 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 26 Apr 2024 17:30:22 +0200 Subject: [PATCH 03/22] Added identifier lists --- src/yacc/parser.y | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index c158dec..2ee4e7d 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -67,7 +67,11 @@ expr: ValFloat assign: Ident '=' expr { DEBUG("Assignment"); }; -decl: type ':' Ident { DEBUG("Declaration"); }; +identlist: Ident ',' identlist + | Ident + | ; + +decl: type ':' identlist { DEBUG("Declaration"); }; definition: decl '=' expr { DEBUG("Definition"); }; @@ -81,10 +85,12 @@ scale: scale KeyShort | scale KeyDouble | ; -type: Ident +type: sign scale Ident | sign scale KeyInt | sign scale KeyFloat; + + %% int yyerror(char *s) { From d718b8f812a8d29f06c76040b255602c6e22b5d1 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 26 Apr 2024 17:35:27 +0200 Subject: [PATCH 04/22] reversed change from devkit --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ce2db20..c419f9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ LABEL version="0.2.1" LABEL description="docker image for setting up the build pipeline on SDK" LABEL website="https://github.com/Servostar/gemstone" -RUN git clone https://github.com/Servostar/gemstone.git /home/lorang +COPY --chown=lorang src /home/lorang/src +COPY --chown=lorang CMakeLists.txt /home/lorang/ RUN cmake . From 897de1b8e12352b60d02f81d32c64a2b24f9d047 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 26 Apr 2024 17:36:20 +0200 Subject: [PATCH 05/22] fixed spelling mistake --- src/lex/lexer.l | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 8823195..eb0ca18 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -35,9 +35,9 @@ ">" {DEBUG("\"%s\" tokenized with \'>\'", yytext); return('>');}; "<" {DEBUG("\"%s\" tokenized with \'<\'", yytext); return('<');}; -"int" {DEBUG("\"%s\" tokenized with \' Date: Sun, 28 Apr 2024 23:46:12 +0200 Subject: [PATCH 06/22] created lexer rule for comments deleted lexer rule for '#' added parser rule for statement sorted parser rules --- src/lex/lexer.l | 3 ++- src/yacc/parser.y | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index eb0ca18..1d5b9c2 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -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(')');}; diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 2ee4e7d..7bcd013 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -56,8 +56,8 @@ %token FunExtsupport %% -program: assign - | definition; +program: statement; + expr: ValFloat | ValInt @@ -65,16 +65,36 @@ expr: ValFloat | ValStr | Ident; -assign: Ident '=' expr { DEBUG("Assignment"); }; +statement: assign + | decl + | definition; + + + identlist: Ident ',' identlist | Ident | ; + decl: type ':' identlist { DEBUG("Declaration"); }; + + + + + definition: decl '=' expr { DEBUG("Definition"); }; +assign: Ident '=' expr { DEBUG("Assignment"); }; + + + + + + + + sign: KeySigned | KeyUnsigned | ; @@ -89,8 +109,6 @@ type: sign scale Ident | sign scale KeyInt | sign scale KeyFloat; - - %% int yyerror(char *s) { From 75473317051a58958bbee0d441d935248e76b5ef Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 29 Apr 2024 12:39:44 +0200 Subject: [PATCH 07/22] 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 3e6469e2390fee9eeb9aad55aaea0cc16e7f6e00 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 29 Apr 2024 14:12:27 +0200 Subject: [PATCH 08/22] added parser rule for function calling --- src/yacc/parser.y | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 2ee4e7d..154cff8 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -65,6 +65,12 @@ expr: ValFloat | ValStr | Ident; +exprlist: expr ',' exprlist + | expr + | ; + +funcall: Ident '(' exprlist ')' { DEBUG("Function call"); }; + assign: Ident '=' expr { DEBUG("Assignment"); }; identlist: Ident ',' identlist From 65fe3acdb861ffb82d4f50ab103e5e00256101c7 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 29 Apr 2024 17:22:35 +0200 Subject: [PATCH 09/22] removed empty lines --- src/yacc/parser.y | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 7bcd013..e4cc3fa 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -69,32 +69,16 @@ statement: assign | decl | definition; - - - identlist: Ident ',' identlist | Ident | ; - decl: type ':' identlist { DEBUG("Declaration"); }; - - - - - definition: decl '=' expr { DEBUG("Definition"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; - - - - - - - sign: KeySigned | KeyUnsigned | ; From 970b45ac3c90a3b43ec1b353dd77999a4138aff3 Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 30 Apr 2024 11:51:59 +0200 Subject: [PATCH 10/22] 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 a1c12f03db8eab88cab83cb35ae9020e381aa0d5 Mon Sep 17 00:00:00 2001 From: Filleo Date: Sun, 5 May 2024 21:05:37 +0200 Subject: [PATCH 11/22] removed some empty lines --- src/yacc/parser.y | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 7bcd013..e4cc3fa 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -69,32 +69,16 @@ statement: assign | decl | definition; - - - identlist: Ident ',' identlist | Ident | ; - decl: type ':' identlist { DEBUG("Declaration"); }; - - - - - definition: decl '=' expr { DEBUG("Definition"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; - - - - - - - sign: KeySigned | KeyUnsigned | ; From 6f6b34792f0a7953c16288cf60904a3bc496dc61 Mon Sep 17 00:00:00 2001 From: servostar Date: Sun, 5 May 2024 21:11:28 +0200 Subject: [PATCH 12/22] function calls can now have more than 1 parameter list --- src/yacc/parser.y | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 154cff8..8dc5293 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -56,8 +56,7 @@ %token FunExtsupport %% -program: assign - | definition; +program: funcall; expr: ValFloat | ValInt @@ -69,7 +68,10 @@ exprlist: expr ',' exprlist | expr | ; -funcall: Ident '(' exprlist ')' { DEBUG("Function call"); }; +paramlist: paramlist '(' exprlist ')' + | ; + +funcall: Ident paramlist { DEBUG("Function call"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; From bd9d28d06932badcc8df3c9383b95cf69cfffb09 Mon Sep 17 00:00:00 2001 From: servostar Date: Sun, 5 May 2024 21:13:38 +0200 Subject: [PATCH 13/22] 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 From 98c60aef16b89df142abf58ea6674ddc4c809d8a Mon Sep 17 00:00:00 2001 From: servostar Date: Sun, 5 May 2024 21:51:51 +0200 Subject: [PATCH 14/22] added rule for branches --- src/yacc/parser.y | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index e4cc3fa..014dce0 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -56,7 +56,7 @@ %token FunExtsupport %% -program: statement; +program: statementlist; expr: ValFloat @@ -65,9 +65,23 @@ expr: ValFloat | ValStr | Ident; +statementlist: statementlist statement + | ; + statement: assign | decl - | definition; + | 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 From 6038241a1b48b5f95c9cc764de3ff32f69292b78 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Mon, 6 May 2024 12:00:03 +0200 Subject: [PATCH 15/22] initial commit for adding Module Import --- src/yacc/parser.y | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index d6226e4..b052fbf 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -83,6 +83,8 @@ funcall: Ident paramlist { DEBUG("Function call"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; +moduleimport: KeyImport '"filename"' { DEBUG("Module-Import"); }; + statementlist: statementlist statement | ; From 4ee6be3eb85775d3ff6312ad6aadacd563eb6a9e Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Mon, 6 May 2024 12:09:58 +0200 Subject: [PATCH 16/22] Changed Key for Function name --- src/yacc/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index b052fbf..9302ec8 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -83,7 +83,7 @@ funcall: Ident paramlist { DEBUG("Function call"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; -moduleimport: KeyImport '"filename"' { DEBUG("Module-Import"); }; +moduleimport: KeyImport FunFilename { DEBUG("Module-Import"); }; statementlist: statementlist statement | ; From 5d155416b4c4fdf3dff1cd516bff1bb58b7a3f93 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 6 May 2024 14:13:43 +0200 Subject: [PATCH 17/22] added while parser rule --- src/yacc/parser.y | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index d6226e4..82e0827 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -89,6 +89,7 @@ statementlist: statementlist statement statement: assign | decl | definition + | while | branch; branchif: KeyIf expr '{' statementlist '}' { DEBUG("if"); }; @@ -101,6 +102,8 @@ branchelseifs: branchelseifs branchelseif branch: branchif branchelseifs | branchif branchelseifs branchelse; +while: KeyWhile expr '{' statementlist '}' { DEBUG("while"); }; + identlist: Ident ',' identlist | Ident | ; From 02628a56d6e9889b7797e5e94e0be587b8afa1e5 Mon Sep 17 00:00:00 2001 From: servostar Date: Mon, 6 May 2024 16:41:23 +0200 Subject: [PATCH 18/22] fixed shift reduce conflicts by removing epsilon functions --- src/yacc/parser.y | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index d6226e4..48db348 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -73,57 +73,61 @@ expr: ValFloat | operation; exprlist: expr ',' exprlist - | expr - | ; + | expr; -paramlist: paramlist '(' exprlist ')' - | ; +paramlist: '(' exprlist ')' paramlist + | '(' exprlist ')'; funcall: Ident paramlist { DEBUG("Function call"); }; -assign: Ident '=' expr { DEBUG("Assignment"); }; - -statementlist: statementlist statement - | ; +statementlist: statement statementlist + | statement; statement: assign | decl | definition - | branch; + | branch + | funcall; branchif: KeyIf expr '{' statementlist '}' { DEBUG("if"); }; branchelse: KeyElse '{' statementlist '}' { DEBUG("if-else"); }; branchelseif: KeyElse KeyIf expr '{' statementlist '}' { DEBUG("else-if"); }; branchelseifs: branchelseifs branchelseif - | ; + | branchelseif; branch: branchif branchelseifs | branchif branchelseifs branchelse; identlist: Ident ',' identlist - | Ident - | ; + | Ident; -decl: type ':' identlist { DEBUG("Declaration"); }; +decl: type ':' identlist; definition: decl '=' expr { DEBUG("Definition"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; sign: KeySigned - | KeyUnsigned - | ; + | KeyUnsigned; scale: scale KeyShort | scale KeyHalf | scale KeyLong | scale KeyDouble - | ; + | KeyShort + | KeyHalf + | KeyLong + | KeyDouble; -type: sign scale Ident - | sign scale KeyInt - | sign scale KeyFloat; +typekind: Ident + | KeyInt + | KeyFloat; + +type: typekind + | scale typekind + | sign typekind + | sign scale typekind; operation: oparith | oplogic From 08943e3e6eacdbc8a843edf6eef6a58eae172066 Mon Sep 17 00:00:00 2001 From: Filleo Date: Mon, 6 May 2024 22:14:42 +0200 Subject: [PATCH 19/22] added function parser rules --- src/yacc/parser.y | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index d6226e4..34d9ba2 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -63,7 +63,8 @@ %left OpBitand OpBitor OpBitxor OpBitnot %% -program: statementlist; +program: statementlist + | fundef; expr: ValFloat | ValInt @@ -76,10 +77,35 @@ exprlist: expr ',' exprlist | expr | ; -paramlist: paramlist '(' exprlist ')' +argumentlist: argumentlist '(' exprlist ')' | ; -funcall: Ident paramlist { DEBUG("Function call"); }; +fundef: KeyFun Ident paramlist '{' statementlist'}' { DEBUG("Function");}; + +paramlist: paramlist '(' params ')' + | paramlist '(' ')' + | '(' params ')' + | '(' ')'; + +params: IOqualifyier paramdecl ',' params + | IOqualifyier paramdecl; + +IOqualifyier: KeyIn + | KeyOut + | KeyIn KeyOut + | KeyOut KeyIn + | ; + +paramdecl: type ':' Ident { DEBUG("Param-Declaration"); }; + + + + + + + + +funcall: Ident argumentlist { DEBUG("Function call"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; @@ -102,8 +128,7 @@ branch: branchif branchelseifs | branchif branchelseifs branchelse; identlist: Ident ',' identlist - | Ident - | ; + | Ident; decl: type ':' identlist { DEBUG("Declaration"); }; From 198c27f67672d698acc7cd1af72c28027dde5b97 Mon Sep 17 00:00:00 2001 From: Ur Mom Date: Tue, 7 May 2024 10:07:00 +0200 Subject: [PATCH 20/22] changed moduleimport in parser --- src/yacc/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index 9302ec8..d33f562 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -83,7 +83,7 @@ funcall: Ident paramlist { DEBUG("Function call"); }; assign: Ident '=' expr { DEBUG("Assignment"); }; -moduleimport: KeyImport FunFilename { DEBUG("Module-Import"); }; +moduleimport: KeyImport ValStr { DEBUG("Module-Import"); }; statementlist: statementlist statement | ; From b8723bf83ce7ecec32c4771417ab41b21672c81c Mon Sep 17 00:00:00 2001 From: Filleo Date: Wed, 8 May 2024 13:18:34 +0200 Subject: [PATCH 21/22] removed empty lines --- src/yacc/parser.y | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/yacc/parser.y b/src/yacc/parser.y index cd40dc2..21e97b8 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -98,13 +98,6 @@ IOqualifyier: KeyIn paramdecl: type ':' Ident { DEBUG("Param-Declaration"); }; - - - - - - - funcall: Ident argumentlist { DEBUG("Function call"); }; statementlist: statement statementlist From f05ebf6ac299f3017058bff7c0d12cd6f0d85787 Mon Sep 17 00:00:00 2001 From: Filleo Date: Wed, 8 May 2024 15:51:30 +0200 Subject: [PATCH 22/22] added Self token changed program rule added rules for box removed second assign added storagequalifier added typedefine --- src/lex/lexer.l | 1 + src/yacc/parser.y | 56 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 1d5b9c2..c9bf739 100644 --- a/src/lex/lexer.l +++ b/src/lex/lexer.l @@ -38,6 +38,7 @@ "int" {DEBUG("\"%s\" tokenized with \'KeyInt'", yytext); return(KeyInt);}; "float" {DEBUG("\"%s\" tokenized with \'KeyFloat\'", yytext); return(KeyFloat);}; +"self" {DEBUG("\"%s\" tokenized with \'KeySelf\'", yytext); return(KeySelf);}; "as" {DEBUG("\"%s\" tokenized with \'KeyAs'", yytext); return (KeyAs);}; "short" {DEBUG("\"%s\" tokenized with \'KeyShort\'", yytext); return(KeyShort);}; "long" {DEBUG("\"%s\" tokenized with \'KeyLong\'", yytext); return(KeyLong);}; diff --git a/src/yacc/parser.y b/src/yacc/parser.y index ddcae10..36c5931 100644 --- a/src/yacc/parser.y +++ b/src/yacc/parser.y @@ -13,6 +13,7 @@ %token KeyInt %token KeyFloat +%token KeySelf %token KeyAs %token ValInt %token Ident @@ -63,15 +64,26 @@ %left OpBitand OpBitor OpBitxor OpBitnot %% -program: statementlist - | fundef; +program: program programbody + | programbody; + +programbody: moduleimport + | fundef + | box + | definition + | decl + | typedef; + + expr: ValFloat | ValInt | ValMultistr | ValStr | Ident - | operation; + | operation + | boxaccess + | boxselfaccess; exprlist: expr ',' exprlist | expr; @@ -98,9 +110,26 @@ IOqualifyier: KeyIn paramdecl: type ':' Ident { DEBUG("Param-Declaration"); }; -funcall: Ident argumentlist { DEBUG("Function call"); }; +box: KeyType KeyBox ':' Ident '{' boxbody '}' { DEBUG("Box"); } + | KeyType KeyBox ':' Ident '{' '}'; -assign: Ident '=' expr { DEBUG("Assignment"); }; +boxbody: boxbody boxcontent + | boxcontent; + +boxcontent: decl { DEBUG("Box decl Content"); } + | definition { DEBUG("Box def Content"); } + | fundef { DEBUG("Box fun Content"); }; + +boxselfaccess: KeySelf '.' Ident + | KeySelf '.' boxaccess; + +boxaccess: Ident '.' Ident + | Ident '.' boxaccess; + +boxcall: boxaccess argumentlist + | boxselfaccess argumentlist; + +funcall: Ident argumentlist { DEBUG("Function call"); }; moduleimport: KeyImport ValStr { DEBUG("Module-Import"); }; @@ -112,7 +141,8 @@ statement: assign | definition | while | branch - | funcall; + | funcall + | boxcall; branchif: KeyIf expr '{' statementlist '}' { DEBUG("if"); }; branchelse: KeyElse '{' statementlist '}' { DEBUG("if-else"); }; @@ -129,15 +159,25 @@ while: KeyWhile expr '{' statementlist '}' { DEBUG("while"); }; identlist: Ident ',' identlist | Ident; -decl: type ':' identlist; +decl: type ':' identlist + | storagequalifier type ':' identlist + definition: decl '=' expr { DEBUG("Definition"); }; -assign: Ident '=' expr { DEBUG("Assignment"); }; +storagequalifier: KeyGlobal + | KeyStatic + | KeyLocal; + +assign: Ident '=' expr { DEBUG("Assignment"); } + | boxaccess '=' expr + | boxselfaccess '=' expr ; sign: KeySigned | KeyUnsigned; +typedef: KeyType type':' Ident; + scale: scale KeyShort | scale KeyHalf | scale KeyLong