From 0ff17560ee3b8083f7b1750beb0f97a3db701ce2 Mon Sep 17 00:00:00 2001 From: elvis Date: Wed, 13 Nov 2024 21:50:44 +0100 Subject: [PATCH] separated into modules, added parser and lexer for miniImp --- .gitignore | 1 + bin/dune | 9 +- dune-project | 16 +- lang.opam | 21 - lib/dune | 5 - lib/exercises/dune | 5 + lib/{ => exercises}/exercises.ml | 10 +- lib/{ => exercises}/exercises.mli | 0 lib/miniFun/dune | 6 + lib/miniImp/Lexer.mll | 88 +++ lib/miniImp/Parser.messages | 1016 +++++++++++++++++++++++++++++ lib/miniImp/Parser.mly | 85 +++ lib/miniImp/Types.ml | 8 +- lib/miniImp/Types.mli | 8 +- lib/miniImp/dune | 16 + lib/utility/dune | 5 + lib/{ => utility}/utility.ml | 0 lib/{ => utility}/utility.mli | 0 test/dune | 10 +- test/testingFun.ml | 4 +- test/testingImp.ml | 4 +- test/testingImpParser.expected | 9 + test/testingImpParser.ml | 129 ++++ test/testingTypeFun.ml | 4 +- 24 files changed, 1408 insertions(+), 51 deletions(-) delete mode 100644 lang.opam delete mode 100644 lib/dune create mode 100644 lib/exercises/dune rename lib/{ => exercises}/exercises.ml (93%) rename lib/{ => exercises}/exercises.mli (100%) create mode 100644 lib/miniFun/dune create mode 100644 lib/miniImp/Lexer.mll create mode 100644 lib/miniImp/Parser.messages create mode 100644 lib/miniImp/Parser.mly create mode 100644 lib/miniImp/dune create mode 100644 lib/utility/dune rename lib/{ => utility}/utility.ml (100%) rename lib/{ => utility}/utility.mli (100%) create mode 100644 test/testingImpParser.expected create mode 100644 test/testingImpParser.ml diff --git a/.gitignore b/.gitignore index 1e2dbd8..bdbf52d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ setup.log # Dune generated files *.install +*.opam # Local OPAM switch _opam/ diff --git a/bin/dune b/bin/dune index a4ef753..d9d9a4a 100644 --- a/bin/dune +++ b/bin/dune @@ -1,4 +1,9 @@ (executable - (public_name main) (name main) - (libraries lang)) + (public_name main) + (libraries exercises + miniImp + miniFun + utility) + (package miniFun) + ) diff --git a/dune-project b/dune-project index c16cb8e..900aba8 100644 --- a/dune-project +++ b/dune-project @@ -4,6 +4,20 @@ (generate_opam_files true) +(using menhir 3.0) + (package - (name lang) + (name utility) + (depends ocaml dune)) + +(package + (name miniImp) + (depends ocaml dune utility)) + +(package + (name miniFun) + (depends ocaml dune utility)) + +(package + (name exercises) (depends ocaml dune)) diff --git a/lang.opam b/lang.opam deleted file mode 100644 index 75de6b8..0000000 --- a/lang.opam +++ /dev/null @@ -1,21 +0,0 @@ -# This file is generated by dune, edit dune-project instead -opam-version: "2.0" -depends: [ - "ocaml" - "dune" {>= "3.16"} - "odoc" {with-doc} -] -build: [ - ["dune" "subst"] {dev} - [ - "dune" - "build" - "-p" - name - "-j" - jobs - "@install" - "@runtest" {with-test} - "@doc" {with-doc} - ] -] diff --git a/lib/dune b/lib/dune deleted file mode 100644 index 7690322..0000000 --- a/lib/dune +++ /dev/null @@ -1,5 +0,0 @@ -(library - (name lang) - (public_name lang)) - -(include_subdirs qualified) \ No newline at end of file diff --git a/lib/exercises/dune b/lib/exercises/dune new file mode 100644 index 0000000..280c335 --- /dev/null +++ b/lib/exercises/dune @@ -0,0 +1,5 @@ +(library + (name exercises) + (public_name exercises)) + +(include_subdirs qualified) \ No newline at end of file diff --git a/lib/exercises.ml b/lib/exercises/exercises.ml similarity index 93% rename from lib/exercises.ml rename to lib/exercises/exercises.ml index efc8adc..895bde5 100644 --- a/lib/exercises.ml +++ b/lib/exercises/exercises.ml @@ -34,10 +34,10 @@ type 'a my_tree = let mod_list y = (List.fold_left (fun acc x -> - match acc with - | [a] when ((List.hd a) = x) -> [x :: a] - | a :: tl when ((List.hd a) = x) -> (x :: a) :: tl - | _ -> [x] :: acc) + match acc with + | [a] when ((List.hd a) = x) -> [x :: a] + | a :: tl when ((List.hd a) = x) -> (x :: a) :: tl + | _ -> [x] :: acc) [] y) |> List.rev @@ -46,7 +46,7 @@ let mod_list y = let to_tup f g = fun x -> match x with - (a, b) -> (f a, g b) + (a, b) -> (f a, g b) let partialsum l = snd (List.fold_left_map (fun acc x -> (acc+x, acc+x)) 0 l) diff --git a/lib/exercises.mli b/lib/exercises/exercises.mli similarity index 100% rename from lib/exercises.mli rename to lib/exercises/exercises.mli diff --git a/lib/miniFun/dune b/lib/miniFun/dune new file mode 100644 index 0000000..92a977f --- /dev/null +++ b/lib/miniFun/dune @@ -0,0 +1,6 @@ +(library + (name miniFun) + (public_name miniFun) + (libraries utility)) + +(include_subdirs qualified) \ No newline at end of file diff --git a/lib/miniImp/Lexer.mll b/lib/miniImp/Lexer.mll new file mode 100644 index 0000000..bf4e94e --- /dev/null +++ b/lib/miniImp/Lexer.mll @@ -0,0 +1,88 @@ +{ + open Parser + exception LexingError of string + + let create_hashtable size init = + let tbl = Hashtbl.create size in + List.iter (fun (key, data) -> Hashtbl.add tbl key data) init; + tbl + + let keyword_table = + let mapping = [ + ("main", MAIN); + ("skip", SKIP); + ("if", IF); + ("else", ELSE); + ("while", WHILE); + ("for", FOR); + ("do", DO); + ("true", BOOL(true)); + ("false", BOOL(false)); + ("not", BNOT); + ("rand", RAND); + ("powmod", POWERMOD); + ] + in create_hashtable (List.length mapping) mapping +} + +let digit = ['0'-'9'] +let alpha = ['a'-'z' 'A'-'Z'] +let white = [' ' '\t']+ | '\r' | '\n' | "\r\n" + +let integer = (digit)(digit*) +let var = (alpha|'_') (alpha|digit|'_')* + +let symbols = ['!'-'/' ':'-'?' '[' ']' '^' '{'-'}' '~'] + +(* lexing rules *) +rule read = parse + | white {read lexbuf} + | var as v { + match Hashtbl.find_opt keyword_table v with + | Some keyword -> keyword + | None -> VARIABLE(v) + } + | ";" {SEQUENCE} + | "," {COMMA} + | "{" {LEFTGPAR} + | "}" {RIGHTGPAR} + | "(" {LEFTPAR} + | ")" {RIGHTPAR} + | "<" {BCMPLESS} + | ">" {BCMPGREATER} + | "+" {PLUS} + | "-" {MINUS} + | "*" {TIMES} + | "/" {DIVISION} + | "%" {MODULO} + | "^" {POWER} + | ":=" {ASSIGNMENT} + | "&&" {BAND} + | "||" {BOR} + | "==" {BCMP} + | "<=" {BCMPLESSEQ} + | ">=" {BCMPGREATEREQ} + | integer as i {INT(int_of_string i)} + | "(*" {comments 0 lexbuf} + | eof {EOF} + | _ { + raise + (LexingError + (Printf.sprintf + "Error scanning %s on line %d at char %d" + (Lexing.lexeme lexbuf) + (lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum) + (lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum) + ))} +and comments level = parse + | "*)" {if level = 0 + then read lexbuf + else comments (level-1) lexbuf} + | "(*" {comments (level+1) lexbuf} + | _ {comments level lexbuf} + | eof {raise (LexingError ("Comment is not closed"))} + + +{ + let lex = read +} diff --git a/lib/miniImp/Parser.messages b/lib/miniImp/Parser.messages new file mode 100644 index 0000000..7eba78f --- /dev/null +++ b/lib/miniImp/Parser.messages @@ -0,0 +1,1016 @@ +prg: WHILE +## +## Ends in an error in state: 0. +## +## prg' -> . prg [ # ] +## +## The known suffix of the stack is as follows: +## +## + +Program must begin with "main var var {...}". + +prg: MAIN WHILE +## +## Ends in an error in state: 1. +## +## prg -> MAIN . VARIABLE VARIABLE LEFTGPAR cexpp RIGHTGPAR EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN +## + +Program must begin with "main var var {...}". + +prg: MAIN VARIABLE WHILE +## +## Ends in an error in state: 2. +## +## prg -> MAIN VARIABLE . VARIABLE LEFTGPAR cexpp RIGHTGPAR EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN VARIABLE +## + +Program must begin with "main var var {...}". + +prg: MAIN VARIABLE VARIABLE WHILE +## +## Ends in an error in state: 3. +## +## prg -> MAIN VARIABLE VARIABLE . LEFTGPAR cexpp RIGHTGPAR EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN VARIABLE VARIABLE +## + +Program must begin with "main var var {...}". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR TIMES +## +## Ends in an error in state: 4. +## +## prg -> MAIN VARIABLE VARIABLE LEFTGPAR . cexpp RIGHTGPAR EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN VARIABLE VARIABLE LEFTGPAR +## + +No left value for "*". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE WHILE +## +## Ends in an error in state: 5. +## +## cexpp -> WHILE . bexpp DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## WHILE +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE RAND WHILE +## +## Ends in an error in state: 7. +## +## aexpp -> RAND . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## RAND +## + +Error while parsing "rand" + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD WHILE +## +## Ends in an error in state: 8. +## +## aexpp -> POWERMOD . LEFTPAR aexpp COMMA aexpp COMMA aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR WHILE +## +## Ends in an error in state: 9. +## +## aexpp -> POWERMOD LEFTPAR . aexpp COMMA aexpp COMMA aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR +## + +Error while parsing "powmod", first element is not an arithmetic expression. + +prg: MAIN VARIABLE VARIABLE LEFTGPAR VARIABLE ASSIGNMENT LEFTPAR WHILE +## +## Ends in an error in state: 10. +## +## aexpp -> LEFTPAR . aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## LEFTPAR +## + +Assignment of a value that is not arithmetic. + +prg: MAIN VARIABLE VARIABLE LEFTGPAR VARIABLE ASSIGNMENT LEFTPAR INT SEQUENCE +## +## Ends in an error in state: 12. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> LEFTPAR aexpp . RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## LEFTPAR aexpp +## + +Error while parsing ";". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT TIMES WHILE +## +## Ends in an error in state: 13. +## +## aexpp -> aexpp TIMES . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp TIMES +## + +Error while parsing "*", second argument is not arithmetic. + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT TIMES INT WHILE +## +## Ends in an error in state: 14. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp TIMES aexpp . [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp TIMES aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT POWER WHILE +## +## Ends in an error in state: 15. +## +## aexpp -> aexpp POWER . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp POWER +## + +Error while parsing "^". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT PLUS WHILE +## +## Ends in an error in state: 18. +## +## aexpp -> aexpp PLUS . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp PLUS +## + +Error while parsing "+". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT PLUS INT WHILE +## +## Ends in an error in state: 19. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp PLUS aexpp . [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp PLUS aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT MODULO WHILE +## +## Ends in an error in state: 20. +## +## aexpp -> aexpp MODULO . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp MODULO +## + +Error while parsing "%". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT MODULO INT WHILE +## +## Ends in an error in state: 21. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp MODULO aexpp . [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp MODULO aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT DIVISION WHILE +## +## Ends in an error in state: 22. +## +## aexpp -> aexpp DIVISION . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp DIVISION +## + +Error while parsing "/". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT DIVISION INT WHILE +## +## Ends in an error in state: 23. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp DIVISION aexpp . [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp DIVISION aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT MINUS WHILE +## +## Ends in an error in state: 24. +## +## aexpp -> aexpp MINUS . aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp MINUS +## + +Error while parsing "-". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT MINUS INT WHILE +## +## Ends in an error in state: 25. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp MINUS aexpp . [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## aexpp MINUS aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR INT SEQUENCE +## +## Ends in an error in state: 26. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . MINUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . TIMES aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . MODULO aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . POWER aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> POWERMOD LEFTPAR aexpp . COMMA aexpp COMMA aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR aexpp +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR INT COMMA WHILE +## +## Ends in an error in state: 27. +## +## aexpp -> POWERMOD LEFTPAR aexpp COMMA . aexpp COMMA aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR aexpp COMMA +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR INT COMMA INT SEQUENCE +## +## Ends in an error in state: 28. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . MINUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . TIMES aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . MODULO aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> aexpp . POWER aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION COMMA ] +## aexpp -> POWERMOD LEFTPAR aexpp COMMA aexpp . COMMA aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR aexpp COMMA aexpp +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR INT COMMA INT COMMA WHILE +## +## Ends in an error in state: 29. +## +## aexpp -> POWERMOD LEFTPAR aexpp COMMA aexpp COMMA . aexpp RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR aexpp COMMA aexpp COMMA +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE POWERMOD LEFTPAR INT COMMA INT COMMA INT SEQUENCE +## +## Ends in an error in state: 30. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION ] +## aexpp -> POWERMOD LEFTPAR aexpp COMMA aexpp COMMA aexpp . RIGHTPAR [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DO DIVISION COMMA BOR BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP BAND ] +## +## The known suffix of the stack is as follows: +## POWERMOD LEFTPAR aexpp COMMA aexpp COMMA aexpp +## + +Error while parsing "powmod". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE LEFTPAR WHILE +## +## Ends in an error in state: 33. +## +## aexpp -> LEFTPAR . aexpp RIGHTPAR [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## bexpp -> LEFTPAR . bexpp RIGHTPAR [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## LEFTPAR +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BNOT WHILE +## +## Ends in an error in state: 35. +## +## bexpp -> BNOT . bexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## BNOT +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT SEQUENCE +## +## Ends in an error in state: 37. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . MINUS aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . TIMES aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . MODULO aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . POWER aexpp [ TIMES POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## bexpp -> aexpp . BCMP aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## bexpp -> aexpp . BCMPLESS aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## bexpp -> aexpp . BCMPLESSEQ aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## bexpp -> aexpp . BCMPGREATER aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## bexpp -> aexpp . BCMPGREATEREQ aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPLESSEQ WHILE +## +## Ends in an error in state: 38. +## +## bexpp -> aexpp BCMPLESSEQ . aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPLESSEQ +## + +Error while parsing "<=" + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPLESSEQ INT SEQUENCE +## +## Ends in an error in state: 39. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## bexpp -> aexpp BCMPLESSEQ aexpp . [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPLESSEQ aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPLESS WHILE +## +## Ends in an error in state: 40. +## +## bexpp -> aexpp BCMPLESS . aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPLESS +## + +Error while parsing "<". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPLESS INT SEQUENCE +## +## Ends in an error in state: 41. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## bexpp -> aexpp BCMPLESS aexpp . [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPLESS aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPGREATEREQ WHILE +## +## Ends in an error in state: 42. +## +## bexpp -> aexpp BCMPGREATEREQ . aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPGREATEREQ +## + +Error while parsing ">=". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPGREATEREQ INT SEQUENCE +## +## Ends in an error in state: 43. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## bexpp -> aexpp BCMPGREATEREQ aexpp . [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPGREATEREQ aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPGREATER WHILE +## +## Ends in an error in state: 44. +## +## bexpp -> aexpp BCMPGREATER . aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPGREATER +## + +Error while parsing ">". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMPGREATER INT SEQUENCE +## +## Ends in an error in state: 45. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## bexpp -> aexpp BCMPGREATER aexpp . [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMPGREATER aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMP WHILE +## +## Ends in an error in state: 46. +## +## bexpp -> aexpp BCMP . aexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMP +## + +Error while parsing "==". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE INT BCMP INT SEQUENCE +## +## Ends in an error in state: 47. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DO DIVISION COMMA BOR BAND ] +## bexpp -> aexpp BCMP aexpp . [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## aexpp BCMP aexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE LEFTPAR BOOL WHILE +## +## Ends in an error in state: 48. +## +## bexpp -> bexpp . BAND bexpp [ RIGHTPAR BOR BAND ] +## bexpp -> bexpp . BOR bexpp [ RIGHTPAR BOR BAND ] +## bexpp -> LEFTPAR bexpp . RIGHTPAR [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## LEFTPAR bexpp +## + +Error while parsing "while". + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL BOR WHILE +## +## Ends in an error in state: 50. +## +## bexpp -> bexpp BOR . bexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## bexpp BOR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL BAND WHILE +## +## Ends in an error in state: 52. +## +## bexpp -> bexpp BAND . bexpp [ RIGHTPAR DO COMMA BOR BAND ] +## +## The known suffix of the stack is as follows: +## bexpp BAND +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE LEFTPAR INT SEQUENCE +## +## Ends in an error in state: 54. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . MINUS aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . TIMES aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . MODULO aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> aexpp . POWER aexpp [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## aexpp -> LEFTPAR aexpp . RIGHTPAR [ TIMES RIGHTPAR POWER PLUS MODULO MINUS DIVISION BCMPLESSEQ BCMPLESS BCMPGREATEREQ BCMPGREATER BCMP ] +## bexpp -> aexpp . BCMP aexpp [ RIGHTPAR BOR BAND ] +## bexpp -> aexpp . BCMPLESS aexpp [ RIGHTPAR BOR BAND ] +## bexpp -> aexpp . BCMPLESSEQ aexpp [ RIGHTPAR BOR BAND ] +## bexpp -> aexpp . BCMPGREATER aexpp [ RIGHTPAR BOR BAND ] +## bexpp -> aexpp . BCMPGREATEREQ aexpp [ RIGHTPAR BOR BAND ] +## +## The known suffix of the stack is as follows: +## LEFTPAR aexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL WHILE +## +## Ends in an error in state: 55. +## +## bexpp -> bexpp . BAND bexpp [ DO BOR BAND ] +## bexpp -> bexpp . BOR bexpp [ DO BOR BAND ] +## cexpp -> WHILE bexpp . DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## WHILE bexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL DO WHILE +## +## Ends in an error in state: 56. +## +## cexpp -> WHILE bexpp DO . LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## WHILE bexpp DO +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL DO LEFTGPAR TIMES +## +## Ends in an error in state: 57. +## +## cexpp -> WHILE bexpp DO LEFTGPAR . cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## WHILE bexpp DO LEFTGPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR VARIABLE WHILE +## +## Ends in an error in state: 58. +## +## cexpp -> VARIABLE . ASSIGNMENT aexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## VARIABLE +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR VARIABLE ASSIGNMENT WHILE +## +## Ends in an error in state: 59. +## +## cexpp -> VARIABLE ASSIGNMENT . aexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## VARIABLE ASSIGNMENT +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR VARIABLE ASSIGNMENT INT DO +## +## Ends in an error in state: 60. +## +## aexpp -> aexpp . PLUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## aexpp -> aexpp . MINUS aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## aexpp -> aexpp . TIMES aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## aexpp -> aexpp . DIVISION aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## aexpp -> aexpp . MODULO aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## aexpp -> aexpp . POWER aexpp [ TIMES SEQUENCE RIGHTPAR RIGHTGPAR POWER PLUS MODULO MINUS ELSE DIVISION COMMA ] +## cexpp -> VARIABLE ASSIGNMENT aexpp . [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## VARIABLE ASSIGNMENT aexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR LEFTGPAR TIMES +## +## Ends in an error in state: 62. +## +## cexpp -> LEFTGPAR . cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## LEFTGPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF WHILE +## +## Ends in an error in state: 63. +## +## cexpp -> IF . LEFTPAR bexpp RIGHTPAR cexpp ELSE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF LEFTPAR WHILE +## +## Ends in an error in state: 64. +## +## cexpp -> IF LEFTPAR . bexpp RIGHTPAR cexpp ELSE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF LEFTPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF LEFTPAR BOOL WHILE +## +## Ends in an error in state: 65. +## +## bexpp -> bexpp . BAND bexpp [ RIGHTPAR BOR BAND ] +## bexpp -> bexpp . BOR bexpp [ RIGHTPAR BOR BAND ] +## cexpp -> IF LEFTPAR bexpp . RIGHTPAR cexpp ELSE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF LEFTPAR bexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF LEFTPAR BOOL RIGHTPAR TIMES +## +## Ends in an error in state: 66. +## +## cexpp -> IF LEFTPAR bexpp RIGHTPAR . cexpp ELSE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF LEFTPAR bexpp RIGHTPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR WHILE +## +## Ends in an error in state: 67. +## +## cexpp -> FOR . LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR TIMES +## +## Ends in an error in state: 68. +## +## cexpp -> FOR LEFTPAR . cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP WHILE +## +## Ends in an error in state: 69. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE COMMA ] +## cexpp -> FOR LEFTPAR cexpp . COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR SKIP SEQUENCE TIMES +## +## Ends in an error in state: 70. +## +## cexpp -> cexpp SEQUENCE . cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## cexpp SEQUENCE +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR SKIP SEQUENCE SKIP WHILE +## +## Ends in an error in state: 71. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## cexpp -> cexpp SEQUENCE cexpp . [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## cexpp SEQUENCE cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA WHILE +## +## Ends in an error in state: 72. +## +## cexpp -> FOR LEFTPAR cexpp COMMA . bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL WHILE +## +## Ends in an error in state: 73. +## +## bexpp -> bexpp . BAND bexpp [ COMMA BOR BAND ] +## bexpp -> bexpp . BOR bexpp [ COMMA BOR BAND ] +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp . COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA TIMES +## +## Ends in an error in state: 74. +## +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA . cexpp RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA SKIP WHILE +## +## Ends in an error in state: 75. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTPAR ] +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp . RIGHTPAR DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA SKIP RIGHTPAR WHILE +## +## Ends in an error in state: 76. +## +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR . DO LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA SKIP RIGHTPAR DO WHILE +## +## Ends in an error in state: 77. +## +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO . LEFTGPAR cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA SKIP RIGHTPAR DO LEFTGPAR TIMES +## +## Ends in an error in state: 78. +## +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR . cexpp RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR FOR LEFTPAR SKIP COMMA BOOL COMMA SKIP RIGHTPAR DO LEFTGPAR SKIP WHILE +## +## Ends in an error in state: 79. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTGPAR ] +## cexpp -> FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp . RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## FOR LEFTPAR cexpp COMMA bexpp COMMA cexpp RIGHTPAR DO LEFTGPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF LEFTPAR BOOL RIGHTPAR SKIP WHILE +## +## Ends in an error in state: 81. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE ELSE ] +## cexpp -> IF LEFTPAR bexpp RIGHTPAR cexpp . ELSE cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF LEFTPAR bexpp RIGHTPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR IF LEFTPAR BOOL RIGHTPAR SKIP ELSE TIMES +## +## Ends in an error in state: 82. +## +## cexpp -> IF LEFTPAR bexpp RIGHTPAR cexpp ELSE . cexpp [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## IF LEFTPAR bexpp RIGHTPAR cexpp ELSE +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR LEFTGPAR SKIP WHILE +## +## Ends in an error in state: 84. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTGPAR ] +## cexpp -> LEFTGPAR cexpp . RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## LEFTGPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR WHILE BOOL DO LEFTGPAR SKIP WHILE +## +## Ends in an error in state: 86. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTGPAR ] +## cexpp -> WHILE bexpp DO LEFTGPAR cexpp . RIGHTGPAR [ SEQUENCE RIGHTPAR RIGHTGPAR ELSE COMMA ] +## +## The known suffix of the stack is as follows: +## WHILE bexpp DO LEFTGPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR SKIP WHILE +## +## Ends in an error in state: 88. +## +## cexpp -> cexpp . SEQUENCE cexpp [ SEQUENCE RIGHTGPAR ] +## prg -> MAIN VARIABLE VARIABLE LEFTGPAR cexpp . RIGHTGPAR EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN VARIABLE VARIABLE LEFTGPAR cexpp +## + + + +prg: MAIN VARIABLE VARIABLE LEFTGPAR SKIP RIGHTGPAR WHILE +## +## Ends in an error in state: 89. +## +## prg -> MAIN VARIABLE VARIABLE LEFTGPAR cexpp RIGHTGPAR . EOF [ # ] +## +## The known suffix of the stack is as follows: +## MAIN VARIABLE VARIABLE LEFTGPAR cexpp RIGHTGPAR +## + + + diff --git a/lib/miniImp/Parser.mly b/lib/miniImp/Parser.mly new file mode 100644 index 0000000..3962274 --- /dev/null +++ b/lib/miniImp/Parser.mly @@ -0,0 +1,85 @@ +(* code to be copied in the scanner module *) +(* +*) +%{ + open Types +%} + +(* tokens *) +%token MAIN SKIP ASSIGNMENT SEQUENCE IF ELSE WHILE FOR DO COMMA +%token LEFTGPAR RIGHTGPAR +%token BOOL +%token BAND BOR BNOT BCMP BCMPLESS BCMPLESSEQ BCMPGREATER BCMPGREATEREQ +%token VARIABLE +%token INT +%token LEFTPAR RIGHTPAR +%token PLUS MINUS TIMES DIVISION MODULO POWER POWERMOD RAND +%token EOF + +%type cexpp +%type bexpp +%type aexpp +%type prg + +(* start nonterminal *) +%start prg + +(* associativity in order of precedence *) +%left twoseq +%left SEQUENCE +%left ELSE +%left PLUS MINUS BOR BAND +%left BNOT +%left DIVISION +%left MODULO +%left TIMES +%left POWER + +%% + +(* grammar *) +prg: + | MAIN; a = VARIABLE; b = VARIABLE; LEFTGPAR; t = cexpp; RIGHTGPAR; EOF + {Main (a, b, t)} // main a b {...} +cexpp: + | SKIP {Skip} // skip + | a = VARIABLE; ASSIGNMENT; body = aexpp + {Assignment (a, body)} // a := ... + | t1 = cexpp; SEQUENCE; t2 = cexpp %prec twoseq + {Sequence (t1, t2)} // ...; ... + | t = cexpp; SEQUENCE {t} // ...; + | IF; LEFTPAR; guard = bexpp; RIGHTPAR; body1 = cexpp; ELSE; body2 = cexpp + {If (guard, body1, body2)} // if (...) ... else ... + | WHILE; guard = bexpp; DO; LEFTGPAR; body = cexpp; RIGHTGPAR + {While (guard, body)} // while ... do {...} + | FOR; LEFTPAR; ass = cexpp; COMMA; guard = bexpp; COMMA; iter = cexpp; RIGHTPAR; + DO; LEFTGPAR; body = cexpp; RIGHTGPAR + {For (ass, guard, iter, body)} // for (..., ..., ...) do {...} + | LEFTGPAR; t = cexpp; RIGHTGPAR {t} // {...} +bexpp: + | b = BOOL {Boolean (b)} + | b1 = bexpp; BAND; b2 = bexpp {BAnd (b1, b2)} + | b1 = bexpp; BOR; b2 = bexpp {BOr (b1, b2)} + | BNOT; b = bexpp {BNot (b)} + | a1 = aexpp; BCMP; a2 = aexpp {BCmp (a1, a2)} + | a1 = aexpp; BCMPLESS; a2 = aexpp {BCmpLess (a1, a2)} + | a1 = aexpp; BCMPLESSEQ; a2 = aexpp {BCmpLessEq (a1, a2)} + | a1 = aexpp; BCMPGREATER; a2 = aexpp {BCmpGreater (a1, a2)} + | a1 = aexpp; BCMPGREATEREQ; a2 = aexpp {BCmpGreaterEq (a1, a2)} + | LEFTPAR; b = bexpp; RIGHTPAR {b} +aexpp: + | a = VARIABLE {Variable (a)} + | i = INT {Integer (i)} + | t1 = aexpp; PLUS; t2 = aexpp {Plus (t1, t2)} + | t1 = aexpp; MINUS; t2 = aexpp {Minus (t1, t2)} + | MINUS; i = INT {Integer (-i)} + | t1 = aexpp; TIMES; t2 = aexpp {Times (t1, t2)} + | t1 = aexpp; DIVISION; t2 = aexpp {Division (t1, t2)} + | t1 = aexpp; MODULO; t2 = aexpp {Modulo (t1, t2)} + | t1 = aexpp; POWER; t2 = aexpp {Power (t1, t2)} + | POWERMOD; LEFTPAR; t1 = aexpp; COMMA; + t2 = aexpp; COMMA; + t3 = aexpp; RIGHTPAR + {PowerMod (t1, t2, t3)} // powmod (..., ..., ...) + | RAND; LEFTPAR; t = aexpp; RIGHTPAR {Rand (t)} + | LEFTPAR; a = aexpp; RIGHTPAR {a} diff --git a/lib/miniImp/Types.ml b/lib/miniImp/Types.ml index 8bd81cf..69a41da 100644 --- a/lib/miniImp/Types.ml +++ b/lib/miniImp/Types.ml @@ -8,13 +8,13 @@ and c_exp = | Sequence of c_exp * c_exp (* c; c *) | If of b_exp * c_exp * c_exp (* if b then c else c *) | While of b_exp * c_exp (* while b do c *) - | For of c_exp * b_exp * c_exp * c_exp (* for c; b; c do c *) + | For of c_exp * b_exp * c_exp * c_exp (* for (c; b; c) do c *) and b_exp = Boolean of bool (* v *) - | BAnd of b_exp * b_exp (* b and b *) - | BOr of b_exp * b_exp (* b or b *) + | BAnd of b_exp * b_exp (* b && b *) + | BOr of b_exp * b_exp (* b || b *) | BNot of b_exp (* not b *) - | BCmp of a_exp * a_exp (* a = a *) + | BCmp of a_exp * a_exp (* a == a *) | BCmpLess of a_exp * a_exp (* a < a *) | BCmpLessEq of a_exp * a_exp (* a <= a *) | BCmpGreater of a_exp * a_exp (* a > a *) diff --git a/lib/miniImp/Types.mli b/lib/miniImp/Types.mli index fe60c81..cbcd563 100644 --- a/lib/miniImp/Types.mli +++ b/lib/miniImp/Types.mli @@ -8,13 +8,13 @@ and c_exp = | Sequence of c_exp * c_exp (* c; c *) | If of b_exp * c_exp * c_exp (* if b then c else c *) | While of b_exp * c_exp (* while b do c *) - | For of c_exp * b_exp * c_exp * c_exp (* for c; b; c do c *) + | For of c_exp * b_exp * c_exp * c_exp (* for (c; b; c) do c *) and b_exp = Boolean of bool (* v *) - | BAnd of b_exp * b_exp (* b and b *) - | BOr of b_exp * b_exp (* b or b *) + | BAnd of b_exp * b_exp (* b && b *) + | BOr of b_exp * b_exp (* b || b *) | BNot of b_exp (* not b *) - | BCmp of a_exp * a_exp (* a = a *) + | BCmp of a_exp * a_exp (* a == a *) | BCmpLess of a_exp * a_exp (* a < a *) | BCmpLessEq of a_exp * a_exp (* a <= a *) | BCmpGreater of a_exp * a_exp (* a > a *) diff --git a/lib/miniImp/dune b/lib/miniImp/dune new file mode 100644 index 0000000..9977930 --- /dev/null +++ b/lib/miniImp/dune @@ -0,0 +1,16 @@ +(ocamllex Lexer) + +(menhir + (modules Parser) + (explain true) + (infer true) + (flags --dump --table) + ) + +(library + (name miniImp) + (public_name miniImp) + (modules Lexer Parser Types Semantics) + (libraries utility menhirLib)) + +(include_subdirs qualified) diff --git a/lib/utility/dune b/lib/utility/dune new file mode 100644 index 0000000..5b02a35 --- /dev/null +++ b/lib/utility/dune @@ -0,0 +1,5 @@ +(library + (name utility) + (public_name utility)) + +(include_subdirs qualified) \ No newline at end of file diff --git a/lib/utility.ml b/lib/utility/utility.ml similarity index 100% rename from lib/utility.ml rename to lib/utility/utility.ml diff --git a/lib/utility.mli b/lib/utility/utility.mli similarity index 100% rename from lib/utility.mli rename to lib/utility/utility.mli diff --git a/test/dune b/test/dune index 6fa18f7..01caa84 100644 --- a/test/dune +++ b/test/dune @@ -1,11 +1,15 @@ (test (name testingImp) - (libraries lang)) + (libraries miniImp)) + +(test + (name testingImpParser) + (libraries miniImp)) (test (name testingFun) - (libraries lang)) + (libraries miniFun)) (test (name testingTypeFun) - (libraries lang)) \ No newline at end of file + (libraries miniFun)) diff --git a/test/testingFun.ml b/test/testingFun.ml index 2067838..8904f20 100644 --- a/test/testingFun.ml +++ b/test/testingFun.ml @@ -1,5 +1,5 @@ -open Lang.MiniFun -open Lang.MiniFunTypes +open MiniFun.Semantics +open MiniFun.Types (* -------------------------------------------------------------------------- *) (* Identity program *) diff --git a/test/testingImp.ml b/test/testingImp.ml index 9bfa08b..c5785f3 100644 --- a/test/testingImp.ml +++ b/test/testingImp.ml @@ -1,5 +1,5 @@ -open Lang.MiniImp -open Lang.MiniImpTypes +open MiniImp.Semantics +open MiniImp.Types (* -------------------------------------------------------------------------- *) (* Identity program *) diff --git a/test/testingImpParser.expected b/test/testingImpParser.expected new file mode 100644 index 0000000..28a758d --- /dev/null +++ b/test/testingImpParser.expected @@ -0,0 +1,9 @@ +Identity program: 1 +y not defined program: The variable y is not defined. +Factorial program: 3628800 +Hailstone sequence's lenght program: 351 +Sum multiples of 3 and 5 program: 35565945 +Rand program: true +Fibonacci program: 4807526976 +Miller-Rabin primality test program: 0 +Miller-Rabin primality test program: 1 diff --git a/test/testingImpParser.ml b/test/testingImpParser.ml new file mode 100644 index 0000000..676ddc9 --- /dev/null +++ b/test/testingImpParser.ml @@ -0,0 +1,129 @@ +open MiniImp + +let get_result x = + Lexing.from_string x |> Parser.prg MiniImp.Lexer.lex |> Semantics.reduce + +(* -------------------------------------------------------------------------- *) +(* Identity program *) +let program = + "main a b {b := a}" +;; + +Printf.printf "Identity program: %d\n" (get_result program 1);; + +(* -------------------------------------------------------------------------- *) +(* y not defined program *) +let program = + "main a b {x := 1; b := a + x + y}" +;; + +try + Printf.printf "y not defined program: %d\n" (get_result program 100) +with Types.AbsentAssignment s -> + Printf.printf "y not defined program: %s\n" s +;; + +(* -------------------------------------------------------------------------- *) +(* Factorial program *) +let program = +"main a b { + b := 1; + for (i := 1, i <= a, i := i + 1) do { + b := b * i; + } +} +" +;; + +Printf.printf "Factorial program: %d\n" (get_result program 10) +;; + +(* -------------------------------------------------------------------------- *) +(* Hailstone sequence's lenght program *) +let program = +"main a b { + b := 1; + while (not a == 1) do { + b := b + 1; + if ((a % 2) == 1) a := 3 * a + 1 else a := a / 2 + } +}" +;; + +Printf.printf "Hailstone sequence's lenght program: %d\n" (get_result program 77031) +;; + +(* -------------------------------------------------------------------------- *) +(* Sum multiples of 3 and 5 program *) +let program = +"main a b { + b := 0; + for (i := 0, i <= a, i := i+1) do { + if ( i % 3 == 0 || i % 5 == 0) {b := b + i} else {skip} + } +}" +;; + +Printf.printf "Sum multiples of 3 and 5 program: %d\n" (get_result program 12345) +;; + +(* -------------------------------------------------------------------------- *) +(* Rand program *) +let program = + "main a b {b := rand(a)}" +;; + +Printf.printf "Rand program: %b\n" ((get_result program 10) < 10) +;; + +(* -------------------------------------------------------------------------- *) +(* Fibonacci program *) +let program = +"main n fnext { + fnow := 0; + fnext := 1; + while (n > 1) do { + tmp := fnow + fnext; + fnow := fnext; + fnext := tmp; + n := n - 1 + } +}" +;; + +Printf.printf "Fibonacci program: %d\n" (get_result program 48) +;; + +(* -------------------------------------------------------------------------- *) +(* Miller-Rabin primality test program *) +let program = +"main n result { + result := 0; + s := 0; + while (0 == ((n - 1) / (2 ^ s)) % 2) do { + s := s + 1 + }; + d := ((n - 1) / 2 ^ s); + for (i := 20, i > 0, i := i - 1) do { + a := rand(n - 4) + 2; + x := powmod(a, d, n); + for (j := 0, j < s, j := j+1) do { + y := powmod(x, 2, n); + if (y == 1 && (not x == 1) && (not x == n - 1)) + {result := 1} + else + {skip}; + x := y + }; + if (not y == 1) {result := 1} else {skip} + } +}" + +;; + +(* should return 0 because prime *) +Printf.printf "Miller-Rabin primality test program: %d\n" (get_result program 179424673) +;; +(* should return 1 because not prime *) +Printf.printf "Miller-Rabin primality test program: %d\n" (get_result program 179424675) +;; diff --git a/test/testingTypeFun.ml b/test/testingTypeFun.ml index 4a2e40a..69e23bc 100644 --- a/test/testingTypeFun.ml +++ b/test/testingTypeFun.ml @@ -1,5 +1,5 @@ -open Lang.MiniTyFun -open Lang.MiniFunTypes +open MiniFun.TypeChecker +open MiniFun.Types (* -------------------------------------------------------------------------- *) (* Error absent assignment program *)