Commit bef92ceb authored by POTTIER Francois's avatar POTTIER Francois

Extended the quicktest grammar with some epsilon productions.

Added a few new test inputs.
parent a3ab7448
Lookahead token is now INT (0-3)
State 0:
Shifting (INT) to state 3
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (4-5)
Reducing production expr -> INT
State 16:
Shifting (PLUS) to state 8
State 8:
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (6-7)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (8-9)
Reducing production expr -> INT
State 9:
Shifting (TIMES) to state 5
State 5:
State 13:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now INT (10-11)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (12-13)
Reducing production expr -> INT
State 6:
Reducing production expr -> expr TIMES expr
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (PLUS) to state 8
State 8:
Reducing production expr -> expr TIMES optional_dot expr
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (14-17)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (17-18)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (EOL) to state 17
State 17:
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
State 15:
State 21:
Accepting
......@@ -3,48 +3,56 @@ State 0:
Shifting (LPAREN) to state 2
State 2:
Lookahead token is now INT (1-4)
Shifting (INT) to state 3
Reducing production nothing ->
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
State 4:
Shifting (PLUS) to state 8
State 8:
State 5:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (7-8)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (8-9)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr PLUS expr
State 4:
Shifting (RPAREN) to state 7
State 7:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN expr RPAREN
State 16:
Shifting (TIMES) to state 5
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now INT (12-13)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (14-15)
Reducing production expr -> INT
State 6:
Reducing production expr -> expr TIMES expr
State 16:
Shifting (PLUS) to state 8
State 8:
State 9:
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (16-19)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (19-20)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (EOL) to state 17
State 17:
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
State 15:
State 21:
Accepting
......@@ -3,91 +3,107 @@ State 0:
Shifting (LPAREN) to state 2
State 2:
Lookahead token is now INT (1-4)
Shifting (INT) to state 3
Reducing production nothing ->
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
State 4:
Shifting (PLUS) to state 8
State 8:
State 5:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (7-8)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (8-9)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr PLUS expr
State 4:
Shifting (RPAREN) to state 7
State 7:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN expr RPAREN
State 16:
Shifting (TIMES) to state 5
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (10-11)
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now INT (12-13)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (14-15)
Reducing production expr -> INT
State 6:
Reducing production expr -> expr TIMES expr
State 16:
Shifting (PLUS) to state 8
State 8:
State 9:
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now LPAREN (16-17)
Reducing production optional_dot ->
State 12:
Shifting (LPAREN) to state 2
State 2:
Lookahead token is now INT (17-20)
Shifting (INT) to state 3
Reducing production nothing ->
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (21-22)
Reducing production expr -> INT
State 4:
Shifting (TIMES) to state 5
State 5:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now MINUS (23-24)
Reducing production optional_dot ->
State 8:
Shifting (MINUS) to state 1
State 1:
Lookahead token is now INT (24-25)
Shifting (INT) to state 3
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (25-26)
Reducing production expr -> INT
State 14:
State 20:
Reducing production expr -> MINUS expr
State 6:
Reducing production expr -> expr TIMES expr
State 4:
Shifting (RPAREN) to state 7
State 7:
Lookahead token is now MINUS (27-28)
Reducing production expr -> LPAREN expr RPAREN
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (MINUS) to state 12
State 12:
Reducing production expr -> expr TIMES optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now MINUS (27-28)
Reducing production expr -> LPAREN nothing expr RPAREN
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
Lookahead token is now INT (29-30)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now MINUS (31-32)
Reducing production expr -> INT
State 13:
Reducing production expr -> expr MINUS expr
State 16:
Shifting (MINUS) to state 12
State 12:
State 19:
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
Lookahead token is now INT (33-34)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (34-35)
Reducing production expr -> INT
State 13:
Reducing production expr -> expr MINUS expr
State 16:
Shifting (EOL) to state 17
State 17:
State 19:
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
State 15:
State 21:
Accepting
(122 + . 2) * 3 + (128 * -2) - . 2 - 2
Lookahead token is now LPAREN (0-1)
State 0:
Shifting (LPAREN) to state 2
State 2:
Lookahead token is now INT (1-4)
Reducing production nothing ->
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (5-6)
Reducing production expr -> INT
State 5:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now DOT (7-8)
Shifting (DOT) to state 7
State 7:
Lookahead token is now INT (9-10)
Reducing production optional_dot -> DOT
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (10-11)
Reducing production expr -> INT
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now TIMES (12-13)
Reducing production expr -> LPAREN nothing expr RPAREN
State 22:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now INT (14-15)
Reducing production optional_dot ->
State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (16-17)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr TIMES optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now LPAREN (18-19)
Reducing production optional_dot ->
State 12:
Shifting (LPAREN) to state 2
State 2:
Lookahead token is now INT (19-22)
Reducing production nothing ->
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (23-24)
Reducing production expr -> INT
State 5:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now MINUS (25-26)
Reducing production optional_dot ->
State 8:
Shifting (MINUS) to state 1
State 1:
Lookahead token is now INT (26-27)
Shifting (INT) to state 4
State 4:
Lookahead token is now RPAREN (27-28)
Reducing production expr -> INT
State 20:
Reducing production expr -> MINUS expr
State 9:
Reducing production expr -> expr TIMES optional_dot expr
State 5:
Shifting (RPAREN) to state 10
State 10:
Lookahead token is now MINUS (29-30)
Reducing production expr -> LPAREN nothing expr RPAREN
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
Lookahead token is now DOT (31-32)
Shifting (DOT) to state 7
State 7:
Lookahead token is now INT (33-34)
Reducing production optional_dot -> DOT
State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now MINUS (35-36)
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (MINUS) to state 17
State 17:
Lookahead token is now INT (37-38)
Reducing production optional_dot ->
State 18:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (38-39)
Reducing production expr -> INT
State 19:
Reducing production expr -> expr MINUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
State 21:
Accepting
Lookahead token is now INT (-1--1)
State 0:
Shifting (INT) to state 3
State 3:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
State 16:
Shifting (PLUS) to state 8
State 8:
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (-1--1)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now TIMES (-1--1)
Reducing production expr -> INT
State 9:
Shifting (TIMES) to state 5
State 5:
State 13:
Shifting (TIMES) to state 6
State 6:
Lookahead token is now INT (-1--1)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 8:
Shifting (INT) to state 4
State 4:
Lookahead token is now PLUS (-1--1)
Reducing production expr -> INT
State 6:
Reducing production expr -> expr TIMES expr
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (PLUS) to state 8
State 8:
Reducing production expr -> expr TIMES optional_dot expr
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (PLUS) to state 11
State 11:
Lookahead token is now INT (-1--1)
Shifting (INT) to state 3
State 3:
Reducing production optional_dot ->
State 12:
Shifting (INT) to state 4
State 4:
Lookahead token is now EOL (-1--1)
Reducing production expr -> INT
State 9:
Reducing production expr -> expr PLUS expr
State 16:
Shifting (EOL) to state 17
State 17:
State 13:
Reducing production expr -> expr PLUS optional_dot expr
State 22:
Shifting (EOL) to state 23
State 23:
Reducing production main -> expr EOL
State 15:
State 21:
Accepting
......@@ -43,6 +43,8 @@ and token = parse
{ LPAREN }
| ')'
{ RPAREN }
| '.'
{ DOT }
| _
{ raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
......@@ -2,6 +2,7 @@
%token PLUS MINUS TIMES DIV
%token LPAREN RPAREN
%token EOL
%token DOT
%left PLUS MINUS /* lowest precedence */
%left TIMES DIV /* medium precedence */
......@@ -15,18 +16,30 @@ main:
| e = expr EOL
{ e }
/* Added just to exercise productions with an empty right-hand side. */
nothing:
| /* nothing */
{ () }
/* Added just to exercise productions with an empty right-hand side, in a choice. */
optional_dot:
| /* nothing */
{ () }
| DOT
{ () }
expr:
| i = INT
{ i }
| LPAREN e = expr RPAREN
| LPAREN nothing e = expr RPAREN
{ e }
| e1 = expr PLUS e2 = expr
| e1 = expr PLUS optional_dot e2 = expr
{ e1 + e2 }
| e1 = expr MINUS e2 = expr
| e1 = expr MINUS optional_dot e2 = expr
{ e1 - e2 }
| e1 = expr TIMES e2 = expr
| e1 = expr TIMES optional_dot e2 = expr
{ e1 * e2 }
| e1 = expr DIV e2 = expr
| e1 = expr DIV optional_dot e2 = expr
{ e1 / e2 }
| MINUS e = expr %prec UMINUS
{ - e }
......
......@@ -34,21 +34,23 @@ echo "INT PLUS INT TIMES INT PLUS INT EOL" | $MENHIR --trace --interpret parser.
echo "Comparing results..."
# Compare the results to the reference.
for mode in code table ; do
for f in *.real.in ; do
b=${f%.in}
for f in *.real.in ; do
b=${f%.in}
for mode in code table ; do
echo "($b) Checking output of $mode parser..."
if ! diff -q $b.ref.out $b.$mode.out >/dev/null ; then
echo "($f) The $mode parser produces a wrong result!"
echo "($b) The $mode parser produces a wrong result!"
echo "Expected:"
cat $b.ref.out
echo "Got:"
cat $b.$mode.out
fi
echo "($b) Checking trace of $mode parser..."
if ! diff -q $b.ref.err $b.$mode.err >/dev/null ; then
echo "($b) The $mode parser produces a wrong trace!"
diff $b.ref.err $b.$mode.err
fi
done
if ! diff -q $b.ref.err $b.$mode.err >/dev/null ; then
echo "($f) The $mode parser produces a wrong trace!"
diff $b.ref.err $b.$mode.err
fi
done
# Check the results of the reference interpreter.
......
......@@ -9,11 +9,12 @@
./build.sh
# Build the parser with the code back-end and run it.
echo "Building and running (code)..."
echo "Building (code)..."
make clean >/dev/null
make MENHIR="$MENHIR --trace" >/dev/null
for f in *.real.in ; do
b=${f%.in}
echo "($b) Reconstructing reference output and trace..."
./calc < $f > $b.ref.out 2> $b.ref.err
done
......
Markdown is supported
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