1

In theoretical terms - not looking for specific implementation details, but how do I write a top-down recursive parser for a simple grammar example such as this:

 HAZ ::= FOO | BAR
 FOO ::= “tea” BAR | POT
 BAR ::= POT
 POT ::= “abc” FOO “tea"
jmc
  • 620
  • 14
  • 24
  • Is this homework? Do you have any thoughts on how you might do this? – ChaosPandion Sep 08 '11 at 03:44
  • Not homework, just study material. I have a general idea of recursive descent parsing however with this particular grammar I was unsure how to handle the ambiguity between FOO and BAR and in particular the recursive loop between POT and FOO – jmc Sep 08 '11 at 07:16

1 Answers1

2

See this answer for a general method for coding top down recursive descent parsers directly from a grammar:

Is there an alternative for flex/bison that is usable on 8-bit embedded systems?

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341