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

Andy Tripp antlr at jazillian.com
Thu Feb 28 12:33:45 PST 2008


Terence Parr wrote:
>
> syntax is the grammatical structure. Semantics deals with the symbols 
> (IDs).
>
> int x = "foo";
>
> is syntactically ok but semantically wrong.
That example illustrates the problem well.
You mean that to the *parser*, the input is invalid.
To the *lexer*, it's symantically right.

So I think the "syntactic"/"semantic" distinction is orthogonal to the issue
of whether input (to a lexer, parser, or treewalker) is valid.
Whether the example you gave (or any example) is syntactically or
semantically valid all depends on the lexer, parser, or treewalker.
>
>> Terrence has this general mechanism that he's calling "predicates"
>> which checks the structure of the input. That input can be a stream
>> of characters (for lexer), tokens (for parser), or ASTs for treewalker.
>>
>> Now that I think about it, maybe a better name for "syntactic predicate"
>> would be "input pattern predicate" or something like that. The term
>> "syntactic", to me, is a bit misleading because it makes
>> me think of input characters.
>
> why?  i've never seen nor heard this way of thinking about it.
http://dictionary.reference.com/browse/syntax:
4.Computers. the grammatical rules and structural patterns governing the 
ordered use of appropriate words and symbols for issuing commands, 
writing code, etc., in a particular software application or programming 
language.

http://en.wikipedia.org/wiki/Syntax:
...study of the rules that govern the structure of sentences 
<http://en.wikipedia.org/wiki/Sentence>...

Every time I've ever heard anyone talking about "syntax" they were talking
about the input string itself.
>
>> Saying "my treewalker has a
>> syntactic predicate, which of course checks the shape of the input
>> AST" seems a bit odd.
>
> Not sure why.
Because most people (including ANTLR users, I think) would not say that
a treewalker is doing any syntactic checking. They'd say it's checking 
the structure
of the AST.
>
>> I may just be stuck in an old way of thinking,
>> but I just checked dictionary.com and wikipedia, and they're agreeing
>> with me :)
>
> not possible.  syntax is grammatical structure.  i wrote the sem pred 
> wikiped things so they must agree with me ;)
Looks like you wrote the syntactic predicate wikipedia entry, but the
semantic predicate entry doesn't exist.
I guess you coined the term "syntactic predicate", so you can have it 
mean whatever you want it to.
I just think your definition goes way beyond the dictionary definition 
and common usage of "syntax".

The sentence: "Go!" could cause either valid or invalid input to either 
a lexer, parser, or treewalker.
If you want to consider each one's input to be its "syntax", then we have:

lexer syntax is whether the chars are valid (whether an output 
Tokenstream can be created)
parser syntax is whether the token stream is valid (whether an output 
AST can be created)
treewalker syntax is whether the AST is valid

You know all that of course, and I'm clear on what you mean by "syntax".
The point is that anyone might say that sentence is syntactically valid,
and we'd all know what they mean (as you did above). And that meaning 
corresponds only
to the parser (and perhaps lexer) input. People would consider "Go!" to 
be syntactically correct, regardless of whether
a treewalker can handle the AST produced from it.

On the first page of your Tree Grammars chapter, you refer to checking 
the input as:
...validate tree structure...
...write a tree walker that manually checks the structure...
You don't say "check the syntax", as that would be confusing.

As always, sorry for being a pain.
Can't be too big a problem if it didn't bother me until I made a wrong 
assumption that
a "syntactic predicate" was always related to, well, "syntax".
Andy
>
> Ter
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080228/9933a04c/attachment.html 


More information about the antlr-interest mailing list