[antlr-interest] Syntactic predicates

Bharath Sundararaman bharath at starthis.com
Sat Jul 31 10:34:24 PDT 2004


Hi Monty,

Yes, they are parser rules. " I would profile and determine if any
particular rules have performance issues 
and if so I would refactor rules" -- How do you profile your rules? This is
the first time I'm writing a compiler; Once it is done, there are probably
many ways to test its efficiency as a whole. But how can you profile the
structure of individual rules? Can you give me some pointers?

For now, I'm building two versions of the compiler side-by-side. One with
syntactic predicates for clarity and another without it. I'm planning to run
large code files on both and see how well they respond. 

Thanks,

Bharath.

-----Original Message-----
From: Monty Zukowski [mailto:monty at codetransform.com] 
Sent: Friday, July 30, 2004 7:02 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Syntactic predicates


By having rules with capital letters I'm assuming these are lexer 
rules, however your text indicates that they are actually parser rules. 
  Would you please clarify which they are?

I would go for clarity and use the syntactic predicates.  Then I would 
profile and determine if any particular rules have performance issues 
and if so I would refactor rules.  I believe you will find that 
improving your lexer will give you a bigger payoff than tweaking the 
parser, but of course you never really know until you gather 
performance data.

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

On Jul 30, 2004, at 1:36 PM, Bharath Sundararaman wrote:

>
> Hi Antlrs,
>
> If I had 3 rules of the form:
>
> A: ID blue;
> B: ID black;
> C: ID red;
>
> And another rule
>
> Color: A | B | C;
>
> Is it a bad idea to use syntactic predicates instead of splitting out
> common
> factors? I avoid syntactic predicates as much as possible to avoid
> backtracking and subsequent slowing down.
>
> I have many rules with around a dozen alternatives which don't have 
> the exact same left prefix. I'm having a hard time left factoring 
> these rules and even if I did, AST generation is cumbersome because I 
> usually split large complex rules into several parts for readability 
> (if I don't break the
> rules into parts, its very hard to debug errors) and I have to return 
> values
> at many places for AST generation, type checking and so on.
>
> I created two different grammars, one with very less syntactic
> predicates
> and another with more syntactic predicates. Is there a good benchmark 
> to
> compare these grammars based on syntactic predicates? The language I'm
> dealing with is similar to PASCAL. I don't have to deal with classes,
> objects, pointers, overloading etc. Does this give me an edge?
>
> Any comments are welcome.
>
> Thanks,
>
> Bharath.



 
Yahoo! Groups Links



 




 
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