Question

I have the following 2 production rules in EBNF:

<CharLiteral> ::= ' " ' [ <Printable> ] ' " '

and

<StringLiteral> ::= ' " ' { <Printable> } ' " '

What is the difference between the two? [] imply 1 or more repetitions and {} imply 0 or more repetitions?

Was it helpful?

Solution

In EBNF, [X] means 0 or 1 X and {X} means 0 or more X.

In JavaCC, [X] means 0 or 1 X for grammar productions; in regular expression productions, you should use (X)? instead. To express 0 or more X in JavaCC use (X)*.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top