summary refs log tree commit diff
path: root/source/mod_student/parser.mly
diff options
context:
space:
mode:
authorPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-10-30 15:32:56 +0100
committerPaweł Dybiec <pdybiec@stud.cs.uni.wroc.pl>2018-10-30 15:32:56 +0100
commitb798ac29c37299b2f761243ae92ab8f7c4c4d7f1 (patch)
treeeb9b9cc9be294fe5bd3acf9a342098ffc0ea06e5 /source/mod_student/parser.mly
Initial commit
Diffstat (limited to 'source/mod_student/parser.mly')
-rw-r--r--source/mod_student/parser.mly70
1 files changed, 70 insertions, 0 deletions
diff --git a/source/mod_student/parser.mly b/source/mod_student/parser.mly
new file mode 100644
index 0000000..3eacf51
--- /dev/null
+++ b/source/mod_student/parser.mly
@@ -0,0 +1,70 @@
+(*
+ * Menhir wygeneruje funkcję o nazwie file 
+ *)
+%start <Xi_lib.Ast.module_definition> file
+
+%{
+open Xi_lib
+open Ast
+open Parser_utils
+
+(* Generator znaczników *)
+let mkTag =
+    let i = ref 0 in
+    fun () ->
+        let tag = !i in
+        incr i;
+        NodeTag tag
+
+(* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+ * Miejsce na twój kod w Ocamlu
+ *)
+
+(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   ----------------------------------------------------------------------------- *)
+
+%}
+
+(* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+ * Miejsce na dyrektywy
+ *)
+
+%token EOF
+%token <string>IDENTIFIER
+
+(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   ----------------------------------------------------------------------------- *)
+
+%%
+
+(* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+ * Miejsce na gramatykę
+ *)
+
+
+(* Obecnie potrafimy sparsować tylko pusty plik (wymagamy od razu tokena EOF) *)
+file:
+    |  EOF
+    { ModuleDefinition {global_declarations=[] } }
+
+
+identifier:
+    | IDENTIFIER
+    { Identifier $1 }
+
+(* 
+   ** przykład użycia mkLocation 
+
+    use_declaration:
+        | USE suffix(identifier, opt(SEMICOLON))
+        { GDECL_Use {loc=mkLocation $startpos; id=$2} }
+
+   ** przykład użycia mkTag
+
+    atomic_expression:
+        | identifier
+        { EXPR_Id {loc=mkLocation $startpos; id=$1; tag=mkTag ()} }
+*)
+
+(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   ----------------------------------------------------------------------------- *)