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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top