Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imperative backends misprint mixfix lists #358

Closed
5 tasks done
andreasabel opened this issue Apr 24, 2021 · 2 comments
Closed
5 tasks done

Imperative backends misprint mixfix lists #358

andreasabel opened this issue Apr 24, 2021 · 2 comments
Assignees
Labels
C++ C Haskell Java lists Concerning list categories and separator/terminator/delimiter pragmas printer Concerning the generated printer
Milestone

Comments

@andreasabel
Copy link
Member
andreasabel commented Apr 24, 2021

Affects backends:

For the grammar

[].  [Integer] ::= "";
(:). [Integer] ::= "-" Integer ";" [Integer];

and the input

- 1;
- 2;
- 3;

the backends C/C++/Java render the parsed syntax tree wrongly as:

1 - 2 - 3 - 

Haskell does the right job (reproducing the input), and OCaml almost, with some extra space before the semicolon:

- 1 ;
- 2 ;
- 3 ;

The imperative backends seem to assume that the only terminal in the (:) rule is the separator.

bnfc/source/src/BNFC/CF.hs

Lines 735 to 744 in e91a342

-- | Gets the separator for a list.
getCons :: [Rule] -> String
getCons rs = case find (isConsFun . funRule) rs of
Just (Rule _ _ cats _) -> seper cats
Nothing -> error $ "getCons: no construction function found in "
++ intercalate ", " (map (show . funRule) rs)
where
seper [] = []
seper (Right x:_) = x
seper (Left _:xs) = seper xs

(Found this bug by trying to understand getCons.)

@andreasabel andreasabel added C++ C Java lists Concerning list categories and separator/terminator/delimiter pragmas printer Concerning the generated printer labels Apr 24, 2021
@andreasabel
Copy link
Member Author
andreasabel commented Apr 24, 2021

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' 

andreasabel added a commit that referenced this issue Apr 28, 2021
Instead of with a while loop, we use recursion to print a list also in C.
@andreasabel andreasabel added this to the 2.9.2 milestone May 2, 2021
@andreasabel andreasabel self-assigned this May 2, 2021
andreasabel added a commit that referenced this issue May 2, 2021
andreasabel added a commit that referenced this issue May 2, 2021
This only worked for infix-lists.
andreasabel added a commit that referenced this issue May 2, 2021
andreasabel added a commit that referenced this issue May 2, 2021
@andreasabel
Copy link
Member Author

Fixed for imperative backends by making list printers recursive, instead of using for- or while-loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ C Haskell Java lists Concerning list categories and separator/terminator/delimiter pragmas printer Concerning the generated printer
Projects
None yet
Development

No branches or pull requests

1 participant