[antlr-interest] empty tree assertion rule

Gerrit E.G. 'Insh_Allah' Hobbelt Ger.Hobbelt at bermuda-holding.com
Wed Oct 13 19:44:59 PDT 2004


From: "whaefelinger" <ora.et.labora at web.de>
> Q1: does something like 'nullp' already exist and I'm just
>     not aware of?
>
> Q2: is there absolutly no need for 'nullp' because I missed
>     the point?

Q1: nope (AFAIK) - not till today, except in a few (non-ANTLR) grammars
where its brethren were used sporadically - not _systematically_ throughout
as you're implicitly hinting at.
Q2: only reason I can think of : nullp is not useful if you are *not*
interested _at_ _all_ in the class of errors it 'detects' - and who isn't? -
so there's a definite need for 'nullp' when you like to improve error
checking / software quality. ;-)


I like your idea, because this is a way to detect a specific class of errors
which are otherwise hard to properly diagnose&report: 'superfluous /
unexpected additional tree elements'.


Ger





<brain fart> Hm, one could do 'without' nullp if they'd chosen a different
tactic: when each AST is 'terminated' by a sentinel element at creation
time, the grammar/parser could check for the sentinel and throw an exception
if it wasn't in the expected location, but this would 'bloat' the size of
AST data (in a basic, straight-forward implementation) as it would add one
additional element to each AST unless some custom code 'generated' this
token when testing AST elements beyond 'the end of the AST'. But that would
just be rephrasing 'nullp' the other way around: #(PLUS expr expr EOA)
(where EOA == EndOfAST)
Failure to 'match' EOA would cause an exception. Same process as 'nullp'
system, different text though, but same type of solution. 'nullp' expects to
match nothing at all, EOA expects to match a [special] 'EOA' element.
I think 'nullp' is better than EOA, because I expect it has lower (worst
case: equal) cost in storage and run time.
</bf>



 
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