diff --git a/.gitignore b/.gitignore index b0a833a..a1de90b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ src/parser.ml *.mli src/**/*.cmi comp +*/**/*.output # Tests out tests/out/ diff --git a/src/Makefile b/src/Makefile index 97ef93f..43621e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ -# Import lib + compile -all: lib comp +# Compile +all: comp # Compilation of Ocaml files # Attention: order of object files important @@ -30,12 +30,12 @@ comp.cmo: comp.ml gen.cmo typing.cmo parser.cmo interf.cmo # ocaml lexer and parser # Comment in for your own lexer -# lexer.ml: lexer.mll lang.cmo -# ocamllex $< +lexer.ml: lexer.mll lang.cmo + ocamllex $< # Comment in for your own parser -# parser.ml parser.mli: parser.mly lang.cmo -# ocamlyacc $< +parser.ml parser.mli: parser.mly lang.cmo + ocamlyacc $< lexer.cmo: lexer.ml parser.cmo ocamlc -c $< @@ -52,8 +52,8 @@ parser.cmo: parser.ml parser.cmi lang.cmo .PHONY: clean ### Import files from /lib (temporarly) -lib: - cp ../lib/* ./ +# lib: +# cp ../lib/* ./ ## Remove compiled modules and lib clean: diff --git a/src/parser_laurian/lexer.mll b/src/lexer.mll similarity index 100% rename from src/parser_laurian/lexer.mll rename to src/lexer.mll diff --git a/src/parser_laurian/parser.mly b/src/parser.mly similarity index 100% rename from src/parser_laurian/parser.mly rename to src/parser.mly diff --git a/src/parser_laurian/.gitignore b/src/parser_laurian/.gitignore deleted file mode 100644 index 0f274e7..0000000 --- a/src/parser_laurian/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.output \ No newline at end of file diff --git a/src/parser_laurian/Makefile b/src/parser_laurian/Makefile deleted file mode 100644 index 0ec793e..0000000 --- a/src/parser_laurian/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -all: lang.cmo parser.cmo lexer.cmo interf.cmo - -# Compilation of .ml files -lang.cmo: lang.ml - ocamlc -c $< - -# typing.cmo: typing.ml lang.cmo -# ocamlc -c $< - -# instrs.cmo: instrs.ml lang.cmo -# ocamlc -c $< - -# gen.cmo: gen.ml lang.cmo instrs.cmo typing.cmo -# ocamlc -c $< - -#interf.cmo: interf.ml lexer.cmo parser.cmo gen.cmo typing.cmo -interf.cmo: interf.ml lexer.cmo parser.cmo - ocamlc -c $< - -# comp.cmo: comp.ml gen.cmo typing.cmo parser.cmo interf.cmo -# ocamlc -c $< - -# ocaml lexer and parser - -lexer.ml: lexer.mll lang.cmo - ocamllex $< - -parser.ml parser.mli: parser.mly lang.cmo - ocamlyacc -v $< - -lexer.cmo: lexer.ml parser.cmo - ocamlc -c $< -parser.cmo: parser.ml parser.cmi lang.cmo - ocamlc -c $< - - -#### Generic rules - -%.cmi: %.mli - ocamlc -c $< - - -.PHONY: clean - -clean: - rm -f lexer.ml parser.ml *.mli *.cmi *.cmo diff --git a/src/parser_laurian/interf.ml b/src/parser_laurian/interf.ml deleted file mode 100644 index 17ca594..0000000 --- a/src/parser_laurian/interf.ml +++ /dev/null @@ -1,33 +0,0 @@ -(* Interface with parser *) - -exception ParseLexError of exn * (string * int * int * string * string) - -let parse_file infile = - let lexbuf = Lexing.from_channel (open_in infile) in - try - Parser.start Lexer.token lexbuf - with exn -> - begin - let curr = lexbuf.Lexing.lex_curr_p in - let line = curr.Lexing.pos_lnum in - let cnum = curr.Lexing.pos_cnum - curr.Lexing.pos_bol in - let tok = Lexing.lexeme lexbuf in - let tail = Lexer.ruleTail "" lexbuf in - raise (ParseLexError (exn,(infile, line,cnum,tok,tail))) - end -;; - -let print_parse_error (filename, line,cnum,tok,tail) = - print_string ("Parsing error in file: " ^ filename ^ - " on line: " ^ (string_of_int line) ^ - " column: " ^ (string_of_int cnum) ^ - " token: " ^ tok ^ - "\nrest: " ^ tail ^ "\n") -;; - -let parse infile = - try parse_file infile - with ParseLexError (e, r) -> - print_parse_error r; - failwith "Stopped execution." -;; diff --git a/src/parser_laurian/lang.ml b/src/parser_laurian/lang.ml deleted file mode 100644 index c3791aa..0000000 --- a/src/parser_laurian/lang.ml +++ /dev/null @@ -1,64 +0,0 @@ -(* Definition of source language data structures *) - -(* variable names *) -type vname = string - -(* function names *) -type fname = string - -(* binary arithmetic operators *) -type barith = BAadd | BAsub | BAmul | BAdiv | BAmod (* integer *) - | BAfadd | BAfsub | BAfmul | BAfdiv (* float *) - -(* binary boolean operators: and, or *) -type bbool = BBand | BBor - -(* binary comparison operators: =, >=, >, <=, <, != *) -type bcompar = BCeq | BCge | BCgt | BCle | BClt | BCne - -(* binary operators, combining all of the above *) -type binop = - BArith of barith -| BBool of bbool -| BCompar of bcompar - -type value = - BoolV of bool -| FloatV of float -| IntV of int -| LitV of string -| StringV of string - -(* Expresssions *) -type expr = - Const of value (* constant *) - | VarE of vname (* variable *) - | BinOp of binop * expr * expr (* binary operation *) - | CondE of expr * expr * expr (* conditional expr *) - | CallE of fname * (expr list) (* call expression *) - -(* Commands *) -type com = - Skip (* no operation *) - | Exit (* exit from loop *) - | Assign of vname * expr (* assign expression to var *) - | Seq of com * com (* sequence of statements *) - | CondC of expr * com * com (* conditional com *) - | Loop of com (* loop until exit *) - | CallC of fname * (expr list) (* call statement *) - | Return of expr (* return from call *) - -(* Types *) -type tp = BoolT | FloatT | IntT | LitT | StringT | VoidT - -(* variable / parameter declaration *) -type vardecl = Vardecl of tp * vname - -(* function declaration: return type; parameter declarations *) -type fundecl = Fundecl of tp * fname * (vardecl list) - -(* function definition: function declaration; function body *) -type fundefn = Fundefn of fundecl * com - -type prog = Prog of (fundecl list) * (fundefn list) - diff --git a/src/parser_laurian/use.ml b/src/parser_laurian/use.ml deleted file mode 100644 index 63e5293..0000000 --- a/src/parser_laurian/use.ml +++ /dev/null @@ -1,16 +0,0 @@ - -#load "lang.cmo";; -#load "parser.cmo" ;; -#load "lexer.cmo" ;; -#load "interf.cmo";; - -open Interf;; -open Lang;; - -(* For using the parser: - -- Evaluate this file (use.ml) -- parse "Tests/progsimple.c" ;; - -*) - diff --git a/src/parser_laurian/Tests/progsimple.c b/tests/progsimple.c similarity index 100% rename from src/parser_laurian/Tests/progsimple.c rename to tests/progsimple.c