grammarbnfc

BNFC to Define Boolean Token


I am trying to write a parser with BNF Converter. The grammar that I am using allows things like a ::= true and b ::= false. So I'm trying to create a token to accomplish this. This is what I have so far:

token BVAL ("true"|"false");

I'm hoping to use it like this:

Exp ::= BVAL "||" BVAL

When I try and run BNFC I get the below error:

user error (syntax error at line 1 before true | false ))

Solution

  • According to the BNFC reference manual, the way you write a sequence of characters in a token rule is, for example, {"true"} rather than "true". (See section 5.1, "The token rule", on page 5.)