I am writing a program grammar with lex/yacc. I have an issue about ambiguity of grammar and i need to look EBNF grammar. When I searched semantic of yacc and its declarations, i see grouping({.....}) but i do not know how i can initialize it. For example options([.....]) initialize with |.
%token PROGRAM ID SEMICOLON
program:
PROGRAM ID SEMICOLON
| PROGRAM ‘,’ ID SEMICOLON
is there any way for grouping like that?
yacc does not support EBNF, so you need to convert the EBNF operators to simple BNF to use in yacc. In general, each such operator will require introducing a new symbol. So
[
...]
becomes <new-symbol>
with
<new-symbol> ::= ε | ...
{
...}
becomes <new-symbol>
with1
<new-symbol> ::= ε | <new-symbol> ...
(
...)
becomes <new-symbo>
with
<new-symbol> ::= ...
1If there are any |
operators in ..., you need to insert <new-symbol>
after each one in this substitution