Closed andreasabel closed 3 years ago
Also, terminals in the nil and singleton rules are dropped:
Top. S ::= "{" [Integer] [Char];
[]. [Integer] ::= "}";
(:). [Integer] ::= "-" Integer ";" [Integer];
(:[]). [Char] ::= "finally" Char ";";
(:). [Char] ::= "*" Char ";" [Char];
with input
{
- 1;
- 2;
- 3;
}
* 'A';
* 'B';
finally 'C';
prints
{
1 - 2 - 3 - 'A' * 'B' * 'C'
Fixed for imperative backends by making list printers recursive, instead of using for
- or while
-loops.
Affects backends:
[String]
and[Char]
, see also #359)For the grammar
and the input
the backends C/C++/Java render the parsed syntax tree wrongly as:
Haskell does the right job (reproducing the input), and OCaml almost, with some extra space before the semicolon:
The imperative backends seem to assume that the only terminal in the
(:)
rule is the separator. https://github.com/BNFC/bnfc/blob/e91a342a99b74e4d0a2a1ad36077f51e209645ba/source/src/BNFC/CF.hs#L735-L744 (Found this bug by trying to understandgetCons
.)