Related articles |
---|
Anyone got an LALR(2) parser-generator ? lindsay-j@rmc.ca (1995-08-25) |
Re: Anyone got an LALR(2) parser-generator ? Martin.Jourdan@inria.fr (1995-09-04) |
Re: Anyone got an LALR(2) parser-generator ? BARRETO%VELAHF@ECCSA.Tr.Unisys.com (1995-09-04) |
Re: Anyone got an LALR(2) parser-generator ? Thomas.Herter@mch.sni.de (1995-09-04) |
Re: Anyone got an LALR(2) parser-generator ? Martin.Jourdan@inria.fr (1995-09-11) |
Re: Anyone got an LALR(2) parser-generator ? farzu@uvg.edu.gt (1995-09-18) |
Re: Anyone got an LALR(2) parser-generator ? grosch@cocolab.sub.com (1995-10-30) |
Newsgroups: | comp.compilers |
From: | farzu@uvg.edu.gt (Frankie Arzu) |
Keywords: | parse, LR(1) |
Organization: | Compilers Central |
References: | 95-09-009 95-09-055 |
Date: | Mon, 18 Sep 1995 00:19:03 GMT |
>"John H. Lindsay" <lindsay-j%rmc.ca@trsvr> wrote:
> I'm working with a language definition that needs an LALR(2)
> parser-generator for a couple of good reasons;
>
Sometimes you can use the scanner lookahead to help with this kind of problem,
for example:
Scanner:
id - Letter Letter*
Parser:
S -> Xid "=" Xid "."
XId -> id | id "." id
In LALR(1) you will have a Shift reduce conflict with ".". But it is
LALR(2).
Using the scanner look ahead, the grammar can be rewrite to:
Scanner:
id - Letter Letter*
struct_id = Letter Letter* LOOKAHEAD("." Letter Letter*)
Parser:
S -> Xid "=" Xid "."
XId -> id | struct_id "." id
And this new LALR(1) grammar doesn't have shift/reduce conflict.
The struct_id token will only be recognice if ("." id) is after the first id.
for the input:
a = a.x.
| | |
| | |-- id
| |---- struct_id
|-------- id
In lex the Lookahead operator is "/", many other scanner/parser geneator have
this operator also.
Maybe you can use somthing like this to help you use a LALR(1) grammar for
your language.
Best Regards,
Frankie Arzu
Computer Science Depatment,
Universidad del Valle de Guatemala
E-mail: farzu@uvg.edu.gt
sunguat!assist!frankie@sun.com
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.