I'm trying to write a regular expression engine. I'd like to write a recursive descent parser by hand. What would a context-free grammar without left recursion for the language of regular expressions (not the languages that can be described by regular expressions) look like? Would it be easiest to re-factor out the syntactic sugar, i.e. change a+
to aa*
? Thanks in advance!
Left recursion:
Expression = Expression '|' Sequence
| Sequence
;
Sequence = Sequence Repetition
| <empty>
;
Right recursion:
Expression = Sequence '|' Expression
| Sequence
;
Sequence = Repetition Sequence
| <empty>
;
Ambiguous form:
Expression = Expression '|' Expression
| Sequence
;
Sequence = Sequence Sequence
| Repetition
| <empty>
;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With