bnfc
bnfc copied to clipboard
Lists of lists
Given this .cf file:
Start. S ::= [[E]] ;
Atom. E ::= Integer;
separator E "*" ;
separator [E] "+" ;
and this test input:
5 * 8 + 1 * 2 + 1
- The haskell backend seems to produce a correct parser, but the printer drops the separators of the outer list:
happy -gca LL/Par.y
reduce/reduce conflicts: 3
[Abstract Syntax]
Start [[Atom 5,Atom 8],[Atom 1,Atom 2],[Atom 1]]
[Linearized tree]
5 * 8 1 * 2 1
- The haskell-gadt backend cannot produce the abstract syntax:
happy -gca LL/Par.y
reduce/reduce conflicts: 3
[3 of 8] Compiling LL.Abs ( LL/Abs.hs, LL/Abs.o )
LL/Abs.hs:21:55:
Couldn't match type ‘Tree a0’ with ‘[E]’
Expected type: Tree a0 -> m [E]
Actual type: Tree a0 -> m (Tree a0)
In the second argument of ‘(.)’, namely ‘f’
In the second argument of ‘(.)’, namely ‘a (r (:)) . f’
- The java backend cannot produce the abstract syntax:
LL/Absyn/ListListE.java:3: error: illegal start of type
public class ListListE extends java.util.LinkedList<[E]>
- The c, cpp, and cpp-nostl backends seem to work almost correctly; they seem to flatten lists when debug printing ASTs.
bison -t -pLL LL.y -o Parser.c
LL.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
[Abstract Syntax]
(Start [(Atom 5), (Atom 8), (Atom 1), (Atom 2), (Atom 1)])
[Linearized Tree]
5 * 8 + 1 * 2 + 1
- The ocaml backend can't produce a printer:
ocamlyacc ParLL.mly
1 rule never reduced
3 reduce/reduce conflicts.
ocamlc -o TestLL BNFC_Util.ml AbsLL.ml SkelLL.ml ShowLL.ml ...
File "ShowLL.ml", line 43, characters 66-74:
Error: This expression has type ('a -> showable) -> 'a list -> showable
but an expression was expected of type ('a -> showable) -> showable
- The latex backend works correctly.
The reduce-reduce conflict seems only to appear at the eof, there are two, however confluent, reduce paths:
eps --> [[E]]
eps --> [E] --> [[E]]
An even shorter test case (still avoiding #163) is:
Start. S ::= [[Integer]] ;
separator Integer "*" ;
separator [Integer] "+" ;
Here, the haskell backend drops both levels of separators in the printer.