There is a special alternative symbol ?
, which allows a grammar to parse a string optionally.
For example:
S: A?;
terminals
A: 'a';
This grammar accepts both a
and the empty string.
Formally, S: A?;
is shorthand for the following grammar rules:
S: AOpt;
AOpt: A | EMPTY;
➡️ Next: One Or More
📘 Back: Table of contents