From f05ebf6ac299f3017058bff7c0d12cd6f0d85787 Mon Sep 17 00:00:00 2001 From: Filleo Date: Wed, 8 May 2024 15:51:30 +0200 Subject: [PATCH] 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