jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question What do "syntax" and "semantics" mean and how are they different?
Topics Tools:ANTLR, Tools:ANTLR:Recognition, Tools:ANTLR:Recognition:Semantic predicates, Tools:ANTLR:Recognition:Semantics, Tools:ANTLR:Translation
Author Terence Parr PREMIUM
Created Sep 3, 1999


Answer
A language is a set of valid sentences. What makes a sentence valid? You can break validity down into two things: syntax and semantics. The term syntax refers to grammatical structure whereas the term semantics refers to the meaning of the vocabulary symbols arranged with that structure. Grammatical (syntactically valid) does not imply sensible (semantically valid), however. For example, the grammatical sentence "cows flow supremely" is grammatically ok (subject verb adverb) in English, but makes no sense. Similarly, in a programming language, your grammar (syntax rules) may allow ID EQUALS ID but the language may only allow the sentence if the text matched for ID does not represent a type name (a semantic rule).

When you write an ANTLR grammar, you are specifying the set of syntax rules obeyed by your language. ANTLR uses this to generate a recognizer for sentences in that language. To apply semantic rules, you must add actions or semantic predicates to the grammar. The actions test the "value" of the various tokens and their relationships to determine semantic validity. For example, if you look up a type name in a symbol table to ensure it's a type not a variable, you are applying a semantic rule.

See the chapter on language in Terence's new (in-progress) book.

Is this item helpful?  yes  no     Previous votes   Yes: 2  No: 0



Comments and alternative answers

Comment on this FAQ entry

There are currently no comments


Ask A Question



 
Related Links

ANTLR FAQ

ANTLR Forum

Download now!

Resources

Documentation

Book in progress

ANTLR Consulting

Wish List
Features
About jGuru
Contact Us

 


Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers