0

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?

user3505334
  • 19
  • 1
  • 4

1 Answers1

1

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)*.

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45