1 / 19

ANTLR

ANTLR. OUTLINE. 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 t ool that generates sophisticated parser generator using user defined grammars ..

sheri
Download Presentation

ANTLR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ANTLR

  2. OUTLINE • What is ANTLR? • Whatexactlydoes ANTLR do? • How ANTLR is installedtoEclipse? • ANTLR Project Examples • References

  3. What is ANTLR? • ANTLR - ANother Tool for Language Recognition • tool thatgeneratessophisticatedparsergeneratorusinguserdefinedgrammars.. • Using parsergenerators • languageinterpreters • Compilers • othertranslators can be implemented. [1] • ANTLR • compiler generatororcompiler compiler • used to generate the source code for • language recognizers, • analyzers • translators from language specifications. [2]

  4. 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].

  5. What is ANTLR? • ANTLR • used tobuildtranslatorsandinterpretersfor Domain SpecificLanguages (DSLs). • DSLsareveryhighlevellanguages • tailoredtospecifictasks. • NASA uses Domain SpecificCommandLanguagesforspacemissionsto • improvereliability • reduce risk • reducecost • increasethespeed of development. [1]

  6. Whatexactlydoes ANTLR do? • ANTLR reads agrammarthengeneratesthese 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. Sometokens 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) • matchesphrases in your language via the rules (patterns) you specify • typicallyperforms some semantic action for each phrase (or sub-phrase) matched. [2]

  7. Whatexactlydoes ANTLR do? • Tool • uses lexerand parserin 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]

  8. How ANTLR is installedtoEclipse? • Tutorialforinstallation • Installation of ANTLR toEclipse

  9. ANTLR Project Examples • Tutorialforcreatingproject • Creating an ANTLR Project in Eclipse

  10. English SentenceExample • EnglishGrammer.g

  11. English SentenceExample • Test.java

  12. English SentenceExample • SampleOutputs :

  13. English SentenceExample • Parsetrees:

  14. Expression Language Example • Expr.g

  15. Expression Language Example • Expr.g - Continue

  16. Expression Language Example • Test.java

  17. Expression Language Example • Test.java - Continue

  18. Expression Language Example • SampleOutputs :

  19. REFERENCES • [1] T. Parr, TheDefinitive ANTLR Reference, Building Domain-SpecificLanguges, Dallas, Texas : ThePragmatic Bookshelf ,2007 • [2] Five minute introduction to ANTLR 3 : http://www.antlr.org/wiki/display/ANTLR3/Five+minute+introduction+to+ANTLR+3 • [3] http://antlreclipse.sourceforge.net/ • [4] http://vimeo.com/8001326 • [5] http://www.antlr3.org/download/ • [6] http://stackoverflow.com/questions/8343488/antlr-ide-in-eclipse-doesnt-work

More Related