diff --git a/CMakeLists.txt b/CMakeLists.txt index 079fc47..824b3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,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) diff --git a/src/lex/lexer.l b/src/lex/lexer.l index 8823195..c9bf739 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(')');}; @@ -35,9 +36,10 @@ ">" {DEBUG("\"%s\" tokenized with \'>\'", yytext); return('>');}; "<" {DEBUG("\"%s\" tokenized with \'<\'", yytext); return('<');}; -"int" {DEBUG("\"%s\" tokenized with \' ValInt %token Ident @@ -55,8 +56,170 @@ %token FunLineno %token FunExtsupport +/* Operator associativity */ +%right '=' +%left '+' '-' '*' '/' +%left OpEquals OpNot '<' '>' +%left OpAnd OpOr OpXor +%left OpBitand OpBitor OpBitxor OpBitnot + %% -program: ; +program: program programbody + | programbody; + +programbody: moduleimport + | fundef + | box + | definition + | decl + | typedef; + + + +expr: ValFloat + | ValInt + | ValMultistr + | ValStr + | Ident + | operation + | boxaccess + | boxselfaccess; + +exprlist: expr ',' exprlist + | expr; + +argumentlist: argumentlist '(' exprlist ')' + | ; + + +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"); }; + +box: KeyType KeyBox ':' Ident '{' boxbody '}' { DEBUG("Box"); } + | KeyType KeyBox ':' Ident '{' '}'; + +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"); }; + +statementlist: statement statementlist + | statement; + +statement: assign + | decl + | definition + | while + | branch + | funcall + | boxcall; + +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; + +while: KeyWhile expr '{' statementlist '}' { DEBUG("while"); }; + +identlist: Ident ',' identlist + | Ident; + +decl: type ':' identlist + | storagequalifier type ':' identlist + + +definition: decl '=' expr { DEBUG("Definition"); }; + +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 + | scale KeyDouble + | KeyShort + | KeyHalf + | KeyLong + | KeyDouble; + +typekind: Ident + | KeyInt + | KeyFloat; + +type: typekind + | scale typekind + | sign typekind + | sign scale typekind; + +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) {