diff options
Diffstat (limited to 'source/mod_student')
-rw-r--r-- | source/mod_student/lexer.mll | 44 | ||||
-rw-r--r-- | source/mod_student/parser.mly | 27 |
2 files changed, 70 insertions, 1 deletions
diff --git a/source/mod_student/lexer.mll b/source/mod_student/lexer.mll index f785e52..a62b8ad 100644 --- a/source/mod_student/lexer.mll +++ b/source/mod_student/lexer.mll @@ -58,6 +58,50 @@ { LPAREN } | ")" { RPAREN } + | "{" + { LBRACKET } + | "{" + { RBRACKET } + | ":" + { COLON } + | "+" + { OP_PLUS } + | "-" + { OP_MINUS } + | "*" + { OP_MULT } + | "/" + { OP_DIV } + | "%" + { OP_REM } + | "&" + { OP_AND } + | "|" + { OP_OR } + | "==" + { OP_EQ } + | "!=" + { OP_NEQ } + | "<=" + { OP_LE } + | ">=" + { OP_GE } + | "<" + { OP_LT } + | ">" + { OP_GT } + | "=" + { ASSIGN } + | "if" + { IF } + | "else" + { ELSE } + | "while" + { WHILE } + | "return" + { RETURN } + | "length" + { LENGTH } | identifier as id { IDENTIFIER id } diff --git a/source/mod_student/parser.mly b/source/mod_student/parser.mly index d2216a6..4889d11 100644 --- a/source/mod_student/parser.mly +++ b/source/mod_student/parser.mly @@ -34,6 +34,26 @@ let mkTag = %token RPAREN %token LBRACKET %token RBRACKET +%token COLON +%token OP_PLUS +%token OP_MINUS +%token OP_MULT +%token OP_DIV +%token OP_REM +%token OP_AND +%token OP_OR +%token OP_EQ +%token OP_NEQ +%token OP_LE +%token OP_GE +%token OP_LT +%token OP_GT +%token ASSIGN +%token IF +%token ELSE +%token WHILE +%token RETURN +%token LENGTH %token <int>INT %token <string>IDENTIFIER %token <char>CHAR @@ -51,10 +71,15 @@ let mkTag = (* Obecnie potrafimy sparsować tylko pusty plik (wymagamy od razu tokena EOF) *) file: + | declarations= list(func) EOF + { ModuleDefinition {global_declarations=declarations } } | EOF { ModuleDefinition {global_declarations=[] } } - +func: + | id=identifier LPAREN RPAREN + { GDECL_Function { loc=Location( {line=0;column=0;file=""}); + id=id;formal_parameters=[]; return_types=[];body=None} } identifier: | IDENTIFIER { Identifier $1 } |