Closed JoAllg closed 2 years ago
Maybe a smaller example would help in communication...
The point is that { {}; }
is not really "nothing" from the perspective of the parser. It is a non-empty block whose first instruction is an empty block. Syntactically, the whole thing is not just an empty block. If you want to eliminate these, write a traversal of the syntax tree produced by the parser. This traversal can return an "optimized" syntax tree with empty blocks removed from sequences.
On thing you can try is to also have a coercion:
_. Instr ::= "{" Instr ";" "}"
but this might make your grammar ambiguous (and you will be getting conflicts reported from the parser generator).
Sorry, I could have shrinked it down even more. Your suggestion for the changed coercion works quite well with my grammar, thanks a lot!
I actually need the BLOCK token only for defined labes such as
dTOK. Instr ::= "TOK" ;
define dTOK = BLOCK[PAIR; NIL] ;
i.e. I want TOK to expand to a list of other tokens. From the documentation I suppose, that this is the only way to do that for lists of arbitrary lenght?
I actually need the BLOCK token only for defined labes
In this case, you should declare the BLOCK rule as internal
(see the linked docs), so it does not end up in the parser.
this is the only way to do that for lists of arbitrary lenght?
I do not have enough insight into your problem/goal to answer this question.
Dear @andreasabel
This is not a bug but more a lack of understanding on my side. I have this example bnfc:
and this file / input to be parsed with the ocaml-menhir backend parser:
As you can see, it mostly consists of nested brackets
{ };
. I would like them to be removed (defintion_. Instr ::= "{" Instr "}" ;
), only the innermost brackets should/could result in aBLOCK
token to be used.Instead
BLOCK
tokens are created for alle bracket pairs. When Testing the input with theTest....ml
, then the computation of the instruction"[Linearized tree]\n\n"^ PrintTest.printTree PrintTest.prtProg t^"\n"
takes very long and has some weird spacing in the closing brackets: https://pastebin.com/K99qFHfBCan you give me a hint on how to get my desired result?