Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 369 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
369
Dung lượng
2,43 MB
Nội dung
[...]... can run ANTLR on your grammar, you must install ANTLR by downloading it3 and extracting it into an appropriate directory You do not need to run a configuration script or alter an ANTLR configuration file to properly install ANTLR If you want to install ANTLR in /usr/local /antlr- 3.0, do the following: $ cd /usr/local $ tar xvfz antlr- 3.0.tar.gz antlr- 3.0/ antlr- 3.0/build/ antlr- 3.0/build.properties antlr- 3.0/build.xml... antlr- 3.0/build.properties antlr- 3.0/build.xml antlr- 3.0/lib/ antlr- 3.0/lib /antlr- 3.0.jar $ 3 See http://www .antlr. org/download.html 27 E XECUTING ANTLR AND I NVOKING R ECOGNIZERS As of 3.0, ANTLR v3 is still written in the previous version of ANTLR, 2.7.7, and with StringTemplate 3.0 This means you need both of those libraries to run the ANTLR v3 tool You do not need the ANTLR 2.7.7 JAR to run your generated... semantic predicates hoisting of ANTLR v1 (PCCTS) • The v2 license/contributor trail was loose and made big companies afraid to use it ANTLR v3 is my answer to the issues in v2 ANTLR v3 has a very clean and well-organized code base with lots of unit tests ANTLR generates extremely powerful LL(*) recognizers that are fast and easy to read See http://www .antlr. org/blog /antlr3 /antlr2 .bashing.tml for notes... TParser(tokens); // begin parsing at rule r parser.r(); } } 29 ANTLRW ORKS G RAMMAR D EVELOPMENT E NVIRONMENT What’s Available at the ANTLR Website? At the http://www .antlr. org website, you will find a great deal of information and support for ANTLR The site contains the ANTLR download, the ANTLRWorks graphical user interface (GUI) development environment, the ANTLR documentation, prebuilt grammars, examples, articles,... become familiar with ANTLRWorks, the subject of the next section This ANTLR GUI will make your life much easier when building or debugging grammars 1.5 ANTLRWorks Grammar Development Environment ANTLRWorks is a GUI development environment written by Jean Bovet4 that sits on top of ANTLR and helps you edit, navigate, and debug 4 See http://www .antlr. org/works Bovet is the developer of ANTLRWorks, with... immediately to the quick ANTLR tour in Chapter 3, A Quick Tour for the Impatient, on page 59 In the next two sections, you’ll see how to map the big picture diagram in Figure 1.1, on page 24, into Java code and also learn how to execute ANTLR 1.3 Installing ANTLRANTLR is written in Java, so you must have Java installed on your machine even if you are going to use ANTLR with, say, Python ANTLR requires a Java... ' |'\n' |'\r' )+ {$channel=HIDDEN;} ; // ignore whitespace Java class Tool in package org .antlr contains the main program, so you execute ANTLR on grammar file T.g as follows: $ java org .antlr. Tool T.g ANTLR Parser Generator Version 3.0 1989 -2007 $ ls T.g TLexer.java T .g T.tokens TParser.java $ As you can see, ANTLR generates a number of support files as well as the lexer, TLexer.java, and the parser,... view 31 ANTLRW ORKS G RAMMAR D EVELOPMENT E NVIRONMENT Figure 1.4: ANTLRWorks debugger while parsing Java code; the input, parse tree, and grammar are synched at all times ANTLRWorks is written entirely in highly portable Java (using Swing) and is available as open source under the BSD license Because ANTLRWorks communicates with running parsers via sockets, the ANTLRWorks debugger works with any ANTLR. .. not a colon (:), for Windows At this point, ANTLR should be ready to run The next section provides a simple grammar you can use to check whether you have installed ANTLR properly 1.4 Executing ANTLR and Invoking Recognizers Once you have installed ANTLR, you can use it to translate grammars to executable Java code Here is a sample grammar: 28 E XECUTING ANTLR AND I NVOKING R ECOGNIZERS Download Introduction/T.g... recognizers thus feel very natural ANTLR s fundamental approach dovetails your innate language process Why a Completely New Version of ANTLR? For the past four years, I have been working feverishly to design and build ANTLR v3, the subject of this book ANTLR v3 is a completely rewritten version and represents the culmination of twenty years of language research Most ANTLR users will instantly find it . much better book.
1. See http://www .antlr. org:8080/pipermail /antlr- interest/.
2. See
http://www .antlr. org/wiki/display /ANTLR3 /Code+Generation+Targets.
Preface
In. of unit tests. ANTLR generates
extremely powerful LL(*) recognizers that are fast and easy to read.
8. See http://www .antlr. org/blog /antlr3 /antlr2 .bashing.tml