[antlr-interest] Can this non-determinism be removed?

Dan Stanger dan.stanger at ieee.org
Mon Oct 27 11:44:50 PST 2003


I did a project like this.  One thing that you can do is
to do the reflection on the class and determine what
kind of object it is.  Then use a semantic predicate.

Jeff Vincent wrote:

>  Hey, I am building a run-time scripting language that can instantiate
> Java classes and call methods on the objects (using reflection API).
> Today, when a class type is specified, it has to be preceeded with the
> keyword "class", like: class java.lang.String s; However, I want to
> change it so that the "class" keyword is not required, and looks more
> like real java: java.lang.String s; The problem is that the class name
> has the same format as class member reference identifier and matches
> the rule.  identifier :
>      IDENTIFIER^ ( arrayNotation )? ( DOT identifier )?
>   ;So the parser is nondeterministic at my start rule because
> "java.lang.String" could either be part of a class instance
> declaration or a class member reference statement.  My parser's start
> rule is:  start :
>   (   ( d:declaration
>      |   s:statement
>      )*
>   )
>   ; Can predicates be used to remove this?  I tried adding one at the
> start rule, but my attempts failed.  I can provide more information on
> other rules in my parser, but I'm not sure what additional information
> is needed, if indeed the ambiguity can be removed.   It may be
> possible to move the class declaration out of the declaration sub-rule
> and make it part of the start rule, but I am hoping to keep all the
> declaration rules together for clarity and readability. Thanks, Jeff
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list