944,156 Members | Top Members by Rank

Ad:
Nov 28th, 2004
0

Eliminate Left Recursive Grammar

Expand Post »
Hello! Im going to be coding a parser program soon but first i need to eliminate Left Recursive Rules from this Grammar - as i will be doing a recursive desent parser.

Ive looked for some tutorials on how to eliminate the problem, but to no avail - they are a wee bit confusing. Some say i may need to introduce a new terminal but im still not so sure how to do this.

Below is the grammer:
and the rules for the left recursive grammar:

Quote ...
The grammar as written is not LL(1); it has left-recursive rules of the form:
<X list> ::= <X> | <X list> separator <X>
and rules of the form:
<something> ::= α X β | α Y γ
where α, β and γ are strings of terminals and/or non-terminals (α non-null) and X and Y are different terminal symbols.
<program> ::= <procedure list>
<procedure list> ::= <procedure definition> |
<procedure list> ; <procedure definition>
<procedure definition> ::= <procedure heading> <block>
<procedure heading> ::= procedure identifier is |
procedure identifier ( <declaration list> ) is
<declaration list> ::= <declaration> |
<declaration list> ; <declaration>
<declaration> ::= <identifier list> : integer |
<identifier list> : float |
<identifier list> : string
<identifier list> ::= identifier |
<identifier list> , identifier
<block> ::= <declaration list> <statement part>
<statement part> ::= begin <statement list> end
<statement list> ::= <statement> |
<statement list> ; <statement>
<statement> ::= <assignment statement> |
<if statement> |
<while statement> |
<procedure statement> |
<until statement>
<assignment statement> ::= identifier := <expression> |
4
identifier := stringConstant
<if statement> ::= if <condition> then <statement list> end if |
if <condition> then <statement list> else <statement list> end if
<while statement> ::= while <condition> loop <statement list> end loop
<procedure statement> ::= call identifier (<argument list> )
<until statement> ::= do <statement list> until <condition>
<argument list> ::= identifier |
<argument list> , identifier
<condition> ::= identifier <conditional operator> identifier |
identifier <conditional operator> numberConstant |
identifier <conditional operator> stringConstant
<conditional operator> ::= > | >= | = | /= | < | <=
<expression> ::= <term> |
<expression> + <term> |
<expression> - <term>
<term> ::= <factor> |
<term> * <factor> |
<term> / <factor>
<factor> ::= identifier |
numberConstant |
( <expression> )

I would appreciate it if someone could either point me towards a informative tutorial or could show me which of the above lines follow the second LR rule - i think i can find the ones which follow the first rule.

Thanks very much, if im asking to much just give me some pointers if thats ok Because i need to understand
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
MrScruff is offline Offline
89 posts
since Nov 2004
Jan 19th, 2005
0

Re: Eliminate Left Recursive Grammar

It depends on whether or not this is considered left-recursive:

<procedure list> ::= <procedure definition> |
<procedure rdc> ; <procedure definition>
<procedure rdc> ::= <procedure list>
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
Real-tiner is offline Offline
207 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Does random data compress?
Next Thread in Computer Science Forum Timeline: Oracle and PostreSQL grammar classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC