summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-04 00:35:34 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-11-04 00:35:34 +0100
commit94595193b52e2b4913cda4bb8de4c9a733b2c440 (patch)
treedf38c4192e84f3b17a6c5f18ac9721c5202cb82d /source
parentAdd first tokens (diff)
Add basic tokens + parse function name
Diffstat (limited to 'source')
-rw-r--r--source/mod_student/lexer.mll44
-rw-r--r--source/mod_student/parser.mly27
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 }