summary refs log tree commit diff
path: root/source/mod_student
diff options
context:
space:
mode:
Diffstat (limited to 'source/mod_student')
-rw-r--r--source/mod_student/.merlin7
-rw-r--r--source/mod_student/dune21
-rw-r--r--source/mod_student/lexer.mll79
-rw-r--r--source/mod_student/parser.mly70
-rw-r--r--source/mod_student/plugin.ml61
5 files changed, 238 insertions, 0 deletions
diff --git a/source/mod_student/.merlin b/source/mod_student/.merlin
new file mode 100644
index 0000000..e07c2b1
--- /dev/null
+++ b/source/mod_student/.merlin
@@ -0,0 +1,7 @@
+B /home/wieczyk/.opam/4.07.0/lib/ocamlgraph
+B ../../_build/default/source/mod_student/.mod_student.objs
+B ../../_build/default/source/xi_lib/.xi_lib.objs
+S /home/wieczyk/.opam/4.07.0/lib/ocamlgraph
+S .
+S ../xi_lib
+FLG -open Mod_student -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -w -39-33-26-27-32
diff --git a/source/mod_student/dune b/source/mod_student/dune
new file mode 100644
index 0000000..c590740
--- /dev/null
+++ b/source/mod_student/dune
@@ -0,0 +1,21 @@
+(library
+    (name mod_student)
+    (public_name mod_student)
+    (libraries ocamlgraph xi_lib)
+    (modes byte)
+)
+(menhir 
+    (flags (--explain --dump))
+    (modules parser)
+)
+(ocamllex
+    lexer
+)
+(env
+    (dev
+        (flags (:standard -g -w -39-33-26-27-32))
+    )
+    (release
+        (flags (:standard -w -39-33-26-27))
+    )
+)
diff --git a/source/mod_student/lexer.mll b/source/mod_student/lexer.mll
new file mode 100644
index 0000000..4cd656c
--- /dev/null
+++ b/source/mod_student/lexer.mll
@@ -0,0 +1,79 @@
+{
+  open Xi_lib
+  open Parser
+  open Parser_utils
+
+  (* Lexing z biblioteki standardowej ocamla *)
+  open Lexing
+
+  (* Standardowo w YACC-podobnych narzędziach  to lekser jest uzależniony od parsera. To znaczy, że typ 
+   * danych z tokenami definiuje moduł wygenerowany na bazie grammar.mly. Definiujemy alias na typ
+   * tokenu na potrzeby interfejsów Xi_lib.Iface *)
+  type token = Parser.token
+
+  (* Obsługa błędu *)
+  let handleError pos token =
+      let exc = InvalidToken (mkLocation pos, token) in
+      raise exc
+      
+  (* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+   * Miejsce na twój kod w Ocamlu
+   *)
+
+
+  (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     ----------------------------------------------------------------------------- *)
+
+  }
+  
+  (* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+   * Miejsce na nazwane wyrażenia regularne
+   *)
+
+  let identifier    = ['a'-'z' '_' 'A' - 'Z']['_' 'A' - 'Z' 'a'-'z' '0'-'9']*
+  
+  (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+     ----------------------------------------------------------------------------- *)
+
+
+  rule token = parse
+      (* Trzeba pamiętać aby uaktualnić pozycje w lexbuf, gdy widzimy znak końca wiersza.
+       * To się samo nie robi. Moduł Lexing z standardowej biblioteki daje do tego wygodną
+       * funkcję new_line.
+       *)
+      | ['\n']
+      { new_line lexbuf; token lexbuf }
+
+      (* widzimy początek komentarza i przechodzimy do pomocniczego stanu *)
+      | "//"
+      { line_comment lexbuf }
+
+      | eof
+      { EOF }
+
+      (* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 
+       * Miejsce na twoje reguły
+       *)
+
+      | identifier as id
+      { failwith id }
+
+      (* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+         ----------------------------------------------------------------------------- *)
+  
+      | _
+      { handleError (Lexing.lexeme_start_p lexbuf) (Lexing.lexeme lexbuf) }
+
+  (* Pomocniczy stan aby wygodnie i prawidłowo obsłużyć komentarze *)
+  and line_comment = parse
+      | '\n' 
+      { new_line lexbuf; token lexbuf }
+
+      (* Niektóre edytory nie wstawiają znaku końca wiersza w ostatniej linijce, jesteśmy
+       * przygotowani na obsługę takiego komentarza.
+       *)
+      | eof
+      { EOF }
+
+      | _ 
+      { line_comment lexbuf }
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 ()} }
+*)
+
+(* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   ----------------------------------------------------------------------------- *)
diff --git a/source/mod_student/plugin.ml b/source/mod_student/plugin.ml
new file mode 100644
index 0000000..26d15d0
--- /dev/null
+++ b/source/mod_student/plugin.ml
@@ -0,0 +1,61 @@
+open Xi_lib.Iface
+open Xi_lib.Plugin
+open Xi_lib.Plugin_register
+
+
+module LexerAndParser = struct
+
+  type token = Parser.token
+
+  module Lexer = Lexer
+
+  module Parser = Parser
+
+end
+
+module Plugin : PLUGIN = struct
+
+  let version = "na"
+
+  let make_live_variables_analysis = None
+
+  let make_dominators_analysis = None
+
+  let make_scheduler = None
+
+  let make_natural_loops_analysis = None
+
+  let make_spill_costs_analysis = None
+
+  let lexer_and_parser = Some (module LexerAndParser : LEXER_AND_PARSER)
+
+  let make_typechecker = None
+
+  let make_translator = None
+
+  let make_jump_threading = None
+
+  let make_constant_folding = None
+
+  let make_hilower = None
+
+  let make_callconv = None
+
+  let make_mipslower = None
+
+  let make_register_allocator = None
+
+  let make_constant_folding_analysis = None
+
+  let make_codegen = None
+
+  let make_dead_code_elimination = None
+
+  let make_interference_graph_analysis = None
+
+  let make_spilling = None
+
+  let make_reachability_analysis = None
+end
+
+module RegisterMyPlugin = RegisterPlugin(Plugin)
\ No newline at end of file