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

Andy Tripp antlr at jazillian.com
Fri Feb 29 14:11:41 PST 2008


Neville Clark wrote:
> Sorry but I have to agree with Terrence.
> He put it very elegantly 
> structure == syntax,
> meaning == semantics
>
> the 
> result = count * 2;
>
> Is valid syntax in a number of languages. 
If you agree that "syntax" means "structure", then which structure are 
you talking about?
The lexical structure (i.e. input character sequence), the parser 
structure (e.g. "syntax"), or
the treewalker structure (i.e. the shape of the tree)?

Of course, I already know which one you mean...you mean the parser 
structure - the
fact that "result = count * 2;" will be valid in some *parser* grammar. 
You're not talking
about the fact that 'r' and the other chars are valid (that's "syntax", 
too, right), or the fact that
the AST produced by a parser is acceptable to some treewalker (that's 
"syntax", too).

How do I know that you're talking about the parser's "syntax" and not 
the lexer's or treewalker's
syntax? Because when people use the word "syntax", that's almost always 
what they mean.
> It can be stored in a tree
> structure. And would still be valid structure or syntax as from above -
> structure == syntax.
>   
Again, that's right for a parser. But do you refer to the input 
structure that a treewalker (or
anything else that accepts a tree-like data structure) as "syntax"? I 
doubt it. You refer to it
as "the structure of the AST" or something like that. Gerald's last 
email notwithstanding.
> But it may NOT be semantically correct. It would depend on the type of the
> two variables etc.
>   
Again, which part are you talking about when you say "semantically 
correct"? If we're talking about
the lexer, can the lexer build an output token stream from this input 
character sequence? If so,
then it's "semantically correct" for the lexer. Then perhaps that token 
stream can't be built into an
AST by the parser. In that case, this single input is "semantically 
correct" for the lexer, but
"semantically incorrect" for the parser. And so on for the tree walker 
or whatever else the
parser hands things off to. The point is that at each phase, the input 
may or may not
be syntactically correct and may or may not be semantically correct. But 
I hate using
the words, expecially "syntactic", because people generally don't use 
them that way, as you've
done here.
> Antlr does not check the semantics - that is left to actions eg you need to
> maintain a symbol table to check the type of the variables.
>   
With the use of semantic predicates, ANTLR certainly does use semantics.
Semantics roughly means "building a meaningful data structure based on 
the input", and if (say) a parser
never builds an AST or symbol tables or anything, then it's not doing 
semantics. And yet
it might certainly be using "semantic predicates" while it's busy "not 
doing semantics".
Hmmmm....I guess I better not question the term "semantic predicate" too...
> nev
>
>   


More information about the antlr-interest mailing list