summary refs log tree commit diff
path: root/source/mod_student/parser.mly
diff options
context:
space:
mode:
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 ()} }
+*)
+
+(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   ----------------------------------------------------------------------------- *)