[antlr-interest] Simple question on resolving non-determinism in tree walker

Monty Zukowski monty at codetransform.com
Wed Jun 23 13:05:23 PDT 2004


Typically you'll have the parser change the type so it's not ambiguous. 
  It kinda depends on your parser rule(s), post them and I'll advise 
more specifically.  In general you can do something like:

#(IDENT #(TYPEDECL Type_Name) #(VALUE (constant)?)
| #(IDENT_SUB #(TYPEDECL subRange) #(VALUE (signed_Int)?)

Monty

On Jun 23, 2004, at 12:41 PM, Bharath Sundararaman wrote:

> Hi Grp,
>
> In my tree walker, I am trying resolve non-determinisms between these 
> two
> rules in vain:
>
> #(IDENT #(TYPEDECL Type_Name) #(VALUE (constant)?)
> #(IDENT #(TYPEDECL subRange) #(VALUE (signed_Int)?)
>
> I get a non-determinism warning on TYPEDECL. The problem is, if I club
> TYPEDECL parts to form this rule:
>
> Soln 1:
> --------
> #(IDENT #(TYPEDECL (Type_Name|subRange)) #(VALUE 
> (constant|signed_Int)?)
> -- this will work but It leads to the possibility of "Type_Name" 
> appearing
> with "signed_Int" as its value. Type_Name should only have a "constant"
> value.
>
> Soln 2:
> --------
> #(TYPEDECL (Type_Name #(VALUE (constant)?) | subRange #(VALUE
> (signed_Int)?))
> Should not work either because "VALUE" would become a child of 
> "Type_Name".
>
> I'm sure this is a common problem and that I'm missing something.
>
> Any ideas?
>
> Thanks!
>
>
> -----Original Message-----
> From: Monty Zukowski [mailto:monty at codetransform.com]
> Sent: Tuesday, June 22, 2004 1:56 PM
> To: antlr-interest at yahoogroups.com
> Cc: Monty Zukowski
> Subject: Re: [antlr-interest] Generating tree walkers.
>
>
> On Jun 22, 2004, at 9:14 AM, Bharath Sundararaman wrote:
>
>> I have the lexer, parser and an AST for a PASCAL-like grammar and I
>> would
>> like to perform semantic analysis/symbol table checks/constant folding
>> etc.
>> Is it a cumbersome task to write a tree walker for the abstract syntax
>> tree
>> to perform these checks? When you perform semantic analysis on your
>> input,
>> would you prefer to walk the tree or would you just embed it in your
>> grammar
>> as actions?
>
> I prefer to build the symbol table during the parse (necessary to parse
> C).  Analysis I like to do in tree passes, it's cleaner because it's a
> simplification of the grammar which you build so that it doesn't have
> ambiguities or extraneous punctuation, etc.
>
> Monty
>
> ANTLR & Java Consultant -- http://www.codetransform.com
> ANSI C/GCC transformation toolkit --
> http://www.codetransform.com/gcc.html
> Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list