Does anyone know how BNF rules expecting the empty string ($\epsilon$ or the ""
) behave during creation of a parse tree using grammar from a string of symbols? For example the BNF grammar:
<r0> ::= <opt-whitespace> "a" <opt-whitespace> "b" <opt-whitespace>
<opt-whitespace> ::= " " <opt-whitespace> | ""
How is the $\epsilon$ read during creation of a parse tree for string in the language? From what I observe, when the parser is recursing <opt-whitespace>
for each next symbol of input, eventually "a"
will be read which is not in the rules for <opt-whitespace>
and the string will not be recognized.
I understand the use of $\epsilon$ when using the grammatical rules to generate the strings of the language, however it causes confusion when I think of how to parse the input.