goccmack / gocc

Parser / Scanner Generator
Other
618 stars 48 forks source link

Grouping in EBNF #130

Closed suntong closed 2 years ago

suntong commented 2 years ago

From here:

Grouping is very useful to eliminate alternatives. Whereas in BNF the possibility of addition or subtraction might be represented by:

<expr> ::= <expr> + <term> | <expr> - <term> EBNF would write:

<expr> ::= <expr> (+|-) <expr>

So I tried,

plus : '+' ;
minus : '-' ;
plus_minus : (plus|minus) ;

But got:

expected one of: . char_lit regDefId [ { (

why is that?

suntong commented 2 years ago

Oh, I should use regular definitions as building blocks, not token definitions, right?