19
ANTLR

What is ANTLR? What exactly does ANTLR do? How ANTLR is installed to Eclipse? ANTLR Project Examples References

Embed Size (px)

Citation preview

Page 1: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

ANTLR

Page 2: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

OUTLINE

What is ANTLR? What exactly does ANTLR do? How ANTLR is installed to Eclipse? ANTLR Project Examples References

Page 3: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

What is ANTLR?

ANTLR - ANother Tool for Language Recognition › tool that generates sophisticated parser generator using user defined

grammars..› Using parser generators

language interpreters Compilers other translators

can be implemented. [1]

ANTLR › compiler generator or compiler compiler › used to generate the source code for

language recognizers, analyzers translators

from language specifications. [2]

Page 4: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

What is ANTLR?

ANTLR› takes as its input a grammar - a precise description of a language

augmented with semantic actions -› generates source code files and other auxiliary files.› Target language of the generated source code may be

Java C/C++ C# Python Ruby

is specified in the grammar [2].

Page 5: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

What is ANTLR?

ANTLR› used to build translators and interpreters for

Domain Specific Languages (DSLs).› DSLs are very high level languages

tailored to specific tasks.› NASA uses Domain Specific Command

Languages for space missions to improve reliability reduce risk reduce cost increase the speed of development. [1]

Page 6: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

What exactly does ANTLR do?

ANTLR reads a grammar  then generates these tools:› A Lexer: This reads an input character or byte stream (i.e.

characters, binary data, etc.) divides it into tokens using patterns you specify generates a token stream as output.

Some tokens such as whitespace and comments as hidden using a protocol that ANTLR parsers automatically understand and respect.

› A Parser: This reads a token stream (normally generated by a lexer) matches phrases in your language via the rules (patterns) you

specify typically performs some semantic action for each phrase (or sub-

phrase) matched. [2]

Page 7: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

What exactly does ANTLR do?

Tool › uses lexer and parser in series to check

the word-level and phrase-level structure of the input

› if no fatal errors are encountered create an intermediate tree representation

such as an Abstract Syntax Tree (AST) [2]

Page 10: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

English Sentence Example

EnglishGrammer.g

Page 11: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

English Sentence Example

Test.java

Page 12: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

English Sentence Example

Sample Outputs :

Page 13: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

English Sentence Example

Parse trees:

Page 14: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

Expression Language Example

Expr.g

Page 15: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

Expression Language Example

Expr.g - Continue

Page 16: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

Expression Language Example

Test.java

Page 17: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

Expression Language Example

Test.java - Continue

Page 18: What is ANTLR?  What exactly does ANTLR do?  How ANTLR is installed to Eclipse?  ANTLR Project Examples  References

Expression Language Example

Sample Outputs :