I think that I would define things differently, so as to avoid the problem, to start with something like:
value: num | stringvalue | list ; items: | items value ; list: LEFTBRACE items RIGHTBRACE;
Edit: Separating lists of numbers from lists of strings cannot be done cleanly unless you delete empty lists. The emerging problem is that you want to allow the inclusion of an empty list in a list of numbers or a list of strings, but looking at an empty list, it does not allow the parser to decide which one. For instance:
[[] [] [] [] [] [] [] [] 1]
To figure out what the list is, the parser will have to look ahead to 1 , but the LALR (N) parser can only display N characters to make this decision. Yacc (and Byacc, Bison, etc.) Only LALR (1), so they can only look forward one character. This leaves several possibilities:
- completely exclude empty lists.
- Ask lexer to process an arbitrary number of consecutive empty lists as a single token
- use a parser generator that is not limited to LALR (1) grammars
Inside the yacc grammar, however, I donβt think you can do much - your grammar just does not fit the yacc limits.
source share