From 94595193b52e2b4913cda4bb8de4c9a733b2c440 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 4 Nov 2018 00:35:34 +0100 Subject: Add basic tokens + parse function name --- source/mod_student/lexer.mll | 44 +++++++++++++++++++++++++++++++++++++++++++ source/mod_student/parser.mly | 27 +++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) 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 %token IDENTIFIER %token 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 } -- cgit 1.4.1