[antlr-interest] "An Introduction to ANTLR" presentation slides

Gerald B. Rosenberg gbr at newtechlaw.com
Thu Feb 28 15:17:04 PST 2008


At 01:48 PM 2/28/2008, Darien Hager wrote:
>Hmm. So...  isnt' it possible to write a "syntactic predicate" which 
>checks whether the next Identifier token is a previously-defined 
>function versus a previously-defined variable? In that case, aren't 
>you checking meaning rather than form, and it is therefore is it a 
>semantic-level predicate?

Not really.   Consider the statements:

do { X } while (Y);
while (Y) { X } ;

They are syntactically different -- reflecting static structure.
They may be semantically the same, depending on preconditions and a 
logical evaluation of X and Y -- reflecting dynamic context that, at 
least in the abstract, evaluates as a boolean.

In the case of Antlr predicates, if the direct value of the predicate 
is a grammar fragment <X Y>, then it is a syntactic predicate.  If 
the direct value is a boolean <X && Y>, then it is a semantic predicate.

The practical reason for distinguishing between semantic and 
syntactic predicates is to identify the correct punctuation to use 
(perhaps that distinction will disappear in Antlr 4).  Otherwise, 
predicates are just predicates, useful for disambiguation.

>Now, academically there may be some excellent reason "syntactic 
>predicate" is an equally accurate term in that case, but for myself 
>and presumably other mere mortals it can be confusing and seems to 
>be vaguely out of step with the rest of the documentation. I think 
>if I hadn't read this thread, "syntactic predicate" would imply to 
>me some relationship with the lexer rules.

The realization that all of Antlr's predicate forms can be used 
equally in the lexer, parser and tree parser should dispel any such inference.  



More information about the antlr-interest mailing list