Subject: Re: A question from final project
From: Karl Lieberherr (lieber@ccs.neu.edu)
Date: Tue Dec 04 2001 - 09:55:22 EST
Hi Ying:
I like your solution of making the class dictionary clean
and making the parser a little more complex by telling the parser
generator from Webgain to use a look-ahead of 2 with
PARSEGEN_ARGS = -LOOKAHEAD:2
I did not know that you can do it globally in the .prj file
and don't have to do it in the grammar.
LL(2) languages are also easy to read and write, similar to
LL(1) languages.
-- Karl
>From bonbonca@ccs.neu.edu Mon Dec 3 21:49:59 2001
>Date: Mon, 3 Dec 2001 21:49:58 -0500 (EST)
>From: Ying Ma <bonbonca@ccs.neu.edu>
>To: Karl Lieberherr <lieber@ccs.neu.edu>
>Subject: A question from final project
>
>Dear Prof Lieberherr,
>
>I was doing the final project when I came across the following problem.
>I made the following class dictionary, hoping that it would parse a simple
>input file like below.
>
>CD:
>-------------------
>import edu.neu.ccs.demeter.dj.*;
>ClassGraphDef = <classdefs> List(ClassDef) .
>ClassDef : ConcreteDef | AbstractDef "." .
>ConcreteDef = <cn> ClassName "=" <parts> List(ClassName) .
>AbstractDef = <cn> ClassName ":" <classes> BarList(ClassName) .
>ClassName = Ident .
>BarList(S) ~ S {"|" *s S} .
>List(S) ~ {S} .
>Main = .
>
>
>BEH
>--------------------
>Main {
> public static void main(String args[]) throws Exception {{
> ClassGraphDef cgf = ClassGraphDef.parse(System.in);
> System.out.println();
> DisplayVisitor dv = new DisplayVisitor();
> cgf.allIdent(dv);
> dv.finish();
> }}
>}
>ClassGraphDef {
> traversal allIdent(DisplayVisitor) {
> to {Ident} ;
> }
>}
>
>
>INPUT
>-------------------
>A = B C.
>B : D | E.
>C = .
>D = .
>E = .
>
>However, when I ran demeterj, I got the following error:
>
>Running the parser generator...
>Java Compiler Compiler Version 2.1 (Parser Generator)
>Copyright (c) 1996-2001 Sun Microsystems, Inc.
>Copyright (c) 1997-2001 WebGain, Inc.
>(type "javacc" with no arguments for help)
>Reading from file gen\Parser.jj . . .
>Warning: Choice conflict involving two expansions at
> line 65, column 5 and line 65, column 25 respectively.
> A common prefix is: <IDENTIFIER>
> Consider using a lookahead of 2 for earlier expansion.
>File "TokenMgrError.java" does not exist. Will create one.
>File "ParseException.java" does not exist. Will create one.
>File "Token.java" does not exist. Will create one.
>File "JavaCharStream.java" does not exist. Will create one.
>Parser generated with 0 errors and 1 warnings.
>Running the compiler...
>gen\Parser.java:61: unreachable statement
> it = _AbstractDef();
> ^
>1 error
>Aborting, compiler exited with error value 1.
>
>
>After I changed the parameter to JavaCC in the prj file:
>
>PARSEGEN_ARGS = -LOOKAHEAD:2
>
>It compiled correctly. I know the "ClassDef" in the cd violates LL(1) as
>the syntax of "ConcreteDef" should start differely from the syntax of
>"AbstractDef". However it seems to me that a parser cannot tell the
>difference between concrete and abstract classes in demeterj cds without
>adding extra syntatic elements before them. I was wondering if I should
>make the change to the input cd files or I can change the parameter to
>JavaCC. Thanks for your time!
>
>Ying
>
>
This archive was generated by hypermail 2b28 : Tue Dec 04 2001 - 09:55:53 EST