Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 13th, 2006, 7:31 PM   #1
Jhaqen
Newbie
 
Join Date: Nov 2005
Posts: 4
Rep Power: 0 Jhaqen is on a distinguished road
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.
Jhaqen is offline   Reply With Quote
Old Jan 14th, 2006, 4:18 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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
See, it's just a matter of mapping your ENBF into code. Of course, the pseudocode above leaves out all of the details, but hopefully it'll give you the general idea of what you are supposed to do.
Arevos is offline   Reply With Quote
Old Jan 14th, 2006, 6:22 AM   #3
Jhaqen
Newbie
 
Join Date: Nov 2005
Posts: 4
Rep Power: 0 Jhaqen is on a distinguished road
Thanks, that's a great help!
Jhaqen is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC