![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 4
Rep Power: 0
![]() |
Recursive Decent Parser
Hello, I was wondering if someone could help me with this question:
Write recursive decent parsers for the following grammars: E = “i” [“(“ L “)”] | “(“ L”)” L = E {“,” E} --------------------------------- E = “i” E’ | “(“ L”)” E’ = ε | “(“ L “)” L = E L’ L’ = ε | “,” L where Capital letters are non-terminals. Thanks. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Recursive descent parsers mirror the EBNFs they parse. So in pseudocode, your first example might look something like:
function parse_E(input)
if input = "i"
# handle case "i"
else if input = "i" + "(" + parse_L(substring of input) + ")"
# handle second case
else if input = "(" + parse_L(substring of input) + ")"
# handle third case
else
raise invalid_syntax error
function parse_L(input)
if input = parse_E(substring of input) + ",":
# handle first valid input case
else if input = parse_E(substring of input) + parse_E(substring of input):
# handle second valid input
else
raise invalid_syntax error |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2005
Posts: 4
Rep Power: 0
![]() |
Thanks, that's a great help!
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|