Commit f53d4e29 authored by arthur.furet@insa-rennes.fr's avatar arthur.furet@insa-rennes.fr
Browse files

trying to get the ++ ...

parent 2f491ca3
......@@ -14,6 +14,8 @@ and raw_expression =
| EConst of constant (** A integer or boolean constant. *)
| EGetVar of identifier (** Get the value of a variable. *)
| EUnOp of unop * expression (** An unary operator. *)
| EUnOp2 of unop2 * identifier (** An unary operator. *)
| EBinOp of binop * expression * expression (** [EBinOp (op, e1, e2)] represents the expression [e1 op e2]. *)
| EMethodCall of expression * identifier * expression list (** [EMethodCall (o, id, [p1, ..., pn])] represents the call [o.id(p1, ..., pn)]. *)
| EArrayGet of expression * expression (** [EArrayGet (e1, e2)] represents the expression [e1[e2]]. *)
......@@ -31,7 +33,7 @@ and binop =
| OpSub (** Binary operator [-]. *)
| OpMul (** Binary operator [*]. *)
| OpLt (** Binary operator [<]. *)
| OpGt (** Binary operator [>]. *)
| OpGt (** Binary operatUOpNotor [>]. *)
| OpEq (**Binarty opeartor [==]. *)
| OpAnd (** Binary operator [&&]. *)
......@@ -42,6 +44,8 @@ and unop =
| UOpSubPre (** Add prefix sub operator [--i]*)
| UOpAddPost (** Add post add operator [i++]*)
| UOpSubPost (** Add post sub operator [i--]*)
and unop2 = UOpNot2
and instruction = (** use unop in the IIf area)**)
| IExpr of expression
......
......@@ -8,6 +8,7 @@ type expression =
| EConst of constant
| EGetVar of identifier
| EUnOp of unop * expression
| EUnOp2 of unop * identifier
| EBinOp of binop * expression * expression
| EMethodCall of expression * identifier * expression list
| EArrayGet of expression * expression
......@@ -35,6 +36,10 @@ and unop = LMJ.unop =
| UOpSubPre
| UOpAddPost
| UOpSubPost
and unop2 = LMJ.unop2 =
| UOpNot2
and instruction =
......
"Rule: ocaml dependencies ml (%=lexer )": "\229\156@~\219\229h\183\187\244\225\174\"\024\002s"
"Rule: ocaml dependencies ml (%=lexer )": "b7\007\237\nZ\028\167\131\241\r\020H\163X\151"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/LMJ.mli": "\031\192.{,W\200\001>\235\177\149Qf\006\200"
"Rule: ocaml: menhir dependencies (%=parser )": "k\151w\174\149/n<\1682\155%\025\246\004\132"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/typechecking.mli": "\n\139u\146:\173h=\001\189U\024\\7\218 "
"Rule: ocaml dependencies mli (%=MJ )": "j\139\179\245\236}\127\142\027/\182\224\249\239(t"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/parser.mly": "\015\198\174a\178s\004\148;\235J0\129yIh"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/main.ml": "qL_1W\002#DY\014c\224\221\148k\213"
"Rule: ocaml dependencies mli (%=print_ast )": "\028`h\240 }\148\184\253z\185\144'\153\1735"
"Rule: ocamllex (%=lexer )": "\243v\011@\002\132\218\218\028\207B\174X\189\255\164"
"Rule: ocamllex (%=lexer )": "cA\198\208\204\171?M\016U]4\215\136%/"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/LMJ.mli": "\031\192.{,W\200\001>\235\177\149Qf\006\200"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/print_ast.mli": "\232OzMTO\155\136\199\230+\179\185vqy"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/print_tokens.mli": "EWo\017\004\167\246b\195\165\233$\139\150P\131"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/parser.mly": "\015\198\174a\178s\004\148;\235J0\129yIh"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/main.ml": "qL_1W\002#DY\014c\224\221\148k\213"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/print_ast.mli": "\232OzMTO\155\136\199\230+\179\185vqy"
"Rule: ocaml dependencies mli (%=LMJ )": "-'B\175\159\191f\136\011?\208mw%\222\226"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/mj2c.mli": "\248\168\002\242\251\186k+\246\031\243\248\019\011U]"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/printMJ.mli": "M\000\t\218p\195\237\168\218\242\190\248\140\015\247\192"
"Rule: ocaml: mli -> cmi (%=MJ )": "\228\167\225\247\241\151EOS\160\249\163\154\232\217\002"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/lexer.mll": "\255@:W\127QG\210\176J\022\1451b|\196"
"Rule: ocaml dependencies mli (%=LMJ )": "-'B\175\159\191f\136\011?\208mw%\222\226"
"Rule: ocaml dependencies mli (%=print_tokens )": "\160\190G\n0\129\252\r\188\134 \229Q\174D\168"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/lexer.mll": "\255@:W\127QG\210\176J\022\1451b|\196"
"Rule: ocaml dependencies mli (%=error )": "\028^\151\178\231Z\235F\146sKm\201\234oj"
"Rule: ocaml dependencies mli (%=printMJ )": "~(y\001\1866\149\245f\195m\240:\183t\161"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/lmj2mj.mli": "\199\236I\241\193U\007E\165\216k\159\t\203R\142"
"Rule: ocaml: mli -> cmi (%=location )": "\163\192(\147\226C+\223\133\141\193\1665g\199\189"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/lmj2mj.mli": "\199\236I\241\193U\007E\165\216k\159\t\203R\142"
"Rule: ocaml dependencies mli (%=parser )": "\201\166\132N\249\239\140\015e\227m5\145\250\172\192"
"Rule: ocaml dependencies mli (%=lmj2mj )": "\152WC\021E\168\b\140\223gV\150\172UP\231"
"Rule: ocaml dependencies mli (%=mj2c )": "\190'o\223%\011\170\t\127\130X\213\230\165\221\191"
"Rule: ocaml dependencies ml (%=main )": "\213\253d\006\194\218nL!\028\160\209qJ\164\236"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/error.mli": "g\143(]\222\176H\148\244<\149.}\028\143\246"
"Rule: ocaml: mli -> cmi (%=LMJ )": "\190\151_j|\212\192O\143\018\221o\222O\152d"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/MJ.mli": "1\196\002\190\192I\191\196\182\154\136\134s\150\159<"
"Rule: ocaml dependencies mli (%=typechecking )": "S\214l\158z\217\130;ejk\029\1326\222\b"
"Rule: ocaml dependencies mli (%=location )": "\b\000>Pd\149\169\213K\241\011q\207Z\142\201"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/MJ.mli": "1\196\002\190\192I\191\196\182\154\136\134s\150\159<"
"Rule: ocaml: menhir (%=parser )": "\150\247\207\249a\155\021\248_\221\239\n\248\015\147v"
"Rule: ocaml: mli -> cmi (%=error )": "\138\158\244\027\177,\232\2544\129h\201\250i\001I"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/lexer.mll": "\218\177U\164\030\208\\\198d\005\133\030\215)$\026"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/error.mli": "g\143(]\222\176H\148\244<\149.}\028\143\246"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/mj2c.mli": "\248\168\002\242\251\186k+\246\031\243\248\019\011U]"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/location.mli": "\196\247B\243\247\t\250\217\016w\021\021\238=\201\236"
"Rule: ocaml: mli -> cmi (%=parser )": "\181\151:\250z\167\179\237\232\240\170\193\017\225\030\226"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/printMJ.mli": "M\000\t\218p\195\237\168\218\242\190\248\140\015\247\192"
"Resource: /home/samuel/Bureau/ProjetCompil/MiniJava2/typechecking.mli": "\n\139u\146:\173h=\001\189U\024\\7\218 "
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/print_tokens.mli": "EWo\017\004\167\246b\195\165\233$\139\150P\131"
"Resource: /home/tars/Documents/4AInfo/Compilation/compilation/location.mli": "\196\247B\243\247\t\250\217\016w\021\021\238=\201\236"
### Starting build.
# Target: main.ml.depends, tags: { extension:ml, file:main.ml, ocaml, ocamldep, quiet }
/usr/bin/ocamldep.opt -modules main.ml > main.ml.depends # cached
ocamldep.opt -modules main.ml > main.ml.depends
# Target: error.mli.depends, tags: { extension:mli, file:error.mli, ocaml, ocamldep, quiet }
/usr/bin/ocamldep.opt -modules error.mli > error.mli.depends # cached
# Target: error.cmi, tags: { byte, compile, extension:mli, file:error.mli, interf, ocaml, quiet }
/usr/bin/ocamlc.opt -c -I /usr/lib/ocaml -o error.cmi error.mli # cached
ocamldep.opt -modules error.mli > error.mli.depends
# Target: lexer.mll, tags: { extension:mll, file:lexer.mll, lexer, ocaml, ocamllex, quiet }
/usr/bin/ocamllex.opt -q lexer.mll
ocamllex.opt -q lexer.mll
# Target: lexer.ml.depends, tags: { extension:ml, file:lexer.ml, ocaml, ocamldep, quiet }
/usr/bin/ocamldep.opt -modules lexer.ml > lexer.ml.depends
+ /usr/bin/ocamldep.opt -modules lexer.ml > lexer.ml.depends
File "lexer.mll", line 11, characters 14-15:
Error: Syntax error
ocamldep.opt -modules lexer.ml > lexer.ml.depends
# Target: location.mli.depends, tags: { extension:mli, file:location.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules location.mli > location.mli.depends
# Target: parser.mly.depends, tags: { extension:mly, file:parser.mly, infer, menhir_ocamldep, ocaml, ocamldep, quiet }
menhir --explain --dump --raw-depend --ocamldep 'ocamldep.opt -modules' parser.mly > parser.mly.depends
+ menhir --explain --dump --raw-depend --ocamldep 'ocamldep.opt -modules' parser.mly > parser.mly.depends
File "parser.mly", line 18, characters 25-28:
Warning: the token ADD is unused.
# Target: LMJ.mli.depends, tags: { extension:mli, file:LMJ.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules LMJ.mli > LMJ.mli.depends
# Target: location.cmi, tags: { byte, compile, extension:mli, file:location.mli, interf, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o location.cmi location.mli
# Target: LMJ.cmi, tags: { byte, compile, extension:mli, file:LMJ.mli, interf, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o LMJ.cmi LMJ.mli
# Target: parser.mly, tags: { byte, compile, extension:ml, extension:mly, file:parser.ml, file:parser.mly, infer, menhir, ocaml, parser, quiet }
menhir --explain --dump --ocamlc 'ocamlc.opt -I /usr/lib/ocaml' --infer parser.mly
+ menhir --explain --dump --ocamlc 'ocamlc.opt -I /usr/lib/ocaml' --infer parser.mly
File "parser.mly", line 18, characters 25-28:
Warning: the token ADD is unused.
# Target: parser.mli.depends, tags: { extension:mli, file:parser.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules parser.mli > parser.mli.depends # cached
# Target: parser.cmi, tags: { byte, compile, extension:mli, file:parser.mli, interf, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o parser.cmi parser.mli # cached
# Target: lmj2mj.mli.depends, tags: { extension:mli, file:lmj2mj.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules lmj2mj.mli > lmj2mj.mli.depends
# Target: MJ.mli.depends, tags: { extension:mli, file:MJ.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules MJ.mli > MJ.mli.depends
# Target: MJ.cmi, tags: { byte, compile, extension:mli, file:MJ.mli, interf, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o MJ.cmi MJ.mli
# Target: mj2c.mli.depends, tags: { extension:mli, file:mj2c.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules mj2c.mli > mj2c.mli.depends
# Target: printMJ.mli.depends, tags: { extension:mli, file:printMJ.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules printMJ.mli > printMJ.mli.depends
# Target: print_ast.mli.depends, tags: { extension:mli, file:print_ast.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules print_ast.mli > print_ast.mli.depends
# Target: print_tokens.mli.depends, tags: { extension:mli, file:print_tokens.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules print_tokens.mli > print_tokens.mli.depends
# Target: typechecking.mli.depends, tags: { extension:mli, file:typechecking.mli, ocaml, ocamldep, quiet }
ocamldep.opt -modules typechecking.mli > typechecking.mli.depends
# Target: error.cmi, tags: { byte, compile, extension:mli, file:error.mli, interf, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o error.cmi error.mli
# Target: lexer.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:lexer.cmo, file:lexer.ml, implem, ocaml, quiet }
ocamlc.opt -c -I /usr/lib/ocaml -o lexer.cmo lexer.ml
+ ocamlc.opt -c -I /usr/lib/ocaml -o lexer.cmo lexer.ml
File "lexer.mll", line 11, characters 27-29:
Error: This expression has type unit but an expression was expected of type
int
Command exited with code 2.
# Compilation unsuccessful.
......@@ -9,7 +9,7 @@
and the number of characters from the beginning of the file to the beginning
of the current line [pos_bol].
*)
Buffer.create()
let buffer = Buffer.create()
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
......
lexer.ml:
lexer.ml: Buffer Int32 Lexing Location Parser String
......@@ -8,7 +8,7 @@
and the number of characters from the beginning of the file to the beginning
of the current line [pos_bol].
*)
Buffer.create()
let buffer = Buffer.create()
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
......
......@@ -27,6 +27,7 @@ rule get_token = parse
| space+ { get_token lexbuf }
| "/*" { comment lexbuf }
| '+' { PLUS }
| "++" { PLUS_PLUS }
| '-' { MINUS }
| '*' { TIMES }
| "&&" { AND }
......
......@@ -6,6 +6,7 @@ and translate_raw_expression = function
| LMJ.EConst c -> MJ.EConst c
| LMJ.EGetVar id -> MJ.EGetVar (Location.content id)
| LMJ.EUnOp (op, e) -> MJ.EUnOp (op, translate_expression e)
| LMJ.EUnOp2 (op, id) -> MJ.EUnOp2 (op, Location.content id
| LMJ.EBinOp (op, e1, e2) -> MJ.EBinOp (op, translate_expression e1, translate_expression e2)
| LMJ.EMethodCall (o, id, args) -> MJ.EMethodCall (translate_expression o, Location.content id, List.map translate_expression args)
| LMJ.EArrayGet (a, i) -> MJ.EArrayGet (translate_expression a, translate_expression i)
......
......@@ -395,25 +395,6 @@ let expr2c
let rec expr2c out e =
match e with
| EAdd e ->
fprintf out "%a++;"
| EUnOp (UOpAddPre, e) ->
fprintf out "%a++"
expr2c e
| EUnOp (UOpAddPost, e) ->
fprintf out "++%a"
expr2c e
| EUnOp (UOpSubPre, e) ->
fprintf out "%a--"
expr2c e
| EUnOp (UOpSubPost, e) ->
fprintf out "%a--"
expr2c e
| EConst const ->
fprintf out "%a" constant2c const
......@@ -484,6 +465,11 @@ let expr2c
fprintf out "!(%a)"
expr2c e
| EUnOp2 (UOpNot2, id) ->
fprintf out "!(%a)"
expr2c e
| EBinOp (op, e1, e2) ->
fprintf out "(%a %a %a)"
expr2c e1
......
......@@ -12,6 +12,7 @@
%token PLUS MINUS TIMES NOT LT AND GT EQ
%token COMMA SEMICOLON
%token ASSIGN
%token PLUS_PLUS
%token LPAREN RPAREN LBRACKET RBRACKET LBRACE RBRACE
%token THIS NEW DOT LENGTH
%token SYSO
......@@ -127,8 +128,8 @@ raw_expression:
| e1 = expression op = binop e2 = expression
{ EBinOp (op, e1, e2) }
| e1 = expression PLUS PLUS
{ EUnOp (UOpAddPost, e1) }
| i1 = IDENT PLUS_PLUS
{ EUnOp2 i1 }
| o = expression DOT c = IDENT LPAREN actuals = separated_list(COMMA, expression) RPAREN
{ EMethodCall (o, c, actuals) }
......
......@@ -55,7 +55,7 @@ let print_token show_loc out = function
| GT ->
fprintf out "GT"
| EQ ->
fprintf out "EQ"
fprintf out "EQ"
| AND ->
fprintf out "AND"
| COMMA ->
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment