- Run Eclipse.
- File – New – Java Project. (Figure 1)
- Write Project Name – Click Finish button. (Figure 2)
- Right Click over Project – Configure – Convert to ANTLR Project. (Figure 3)
- Right click over src director under your Project. New – Other. (Figure 4)
- Select ANTLR – Combined Grammar – Next. (Figure 5)
- Write grammar Name (for ex. T). Click Finish button. (Figure 6)
- Write your grammar. Then when you save your grammer, TLexer.java, TParser.java files are generated automatically under antlr-generated directory. (Figure 7, 8)
- Right click over antlr-generated directory. Build Path – Use as Source Folder. (Figure 9)
- After Step 9, Project will give errors. (Figure 10)
- Right click over Project – Build Path – Configure Build Path. (Figure 11)
- Click Add External JARs… button. Find antlr-3.3 jar which is located in advance. (Figure 12)
- Write your Test. Java file under antlr-genereated directory. (Figure 13)
- Run Test file. (Figure 14)
- The command is correct. So in the console there is no error message. (Figure 15)
- If we don’t add ‘;’ at the end of the command, it will give error in the console. (Figure 16)
TESTING AND GETTING PARSER TREES
- Open grammar file. Then Click interpreter tab. (Figure 17)
- In opened screen, select rule, then write test command. Then click play button. Parse tree will be displayed. (Figure 18)
- Example of wrong command. (Figure 19)
- Click Railroad View tab. (Figure 20)
- You can save this diagrams as jpeg or png or html pages. (Figure 21)
Figure 21
1REFERENCES
[1] T. Parr, The Definitive ANTLR
Reference, Building Domain-Specific Languges, Dallas, Texas : The Pragmatic
Bookshelf , 2007
No comments:
Post a Comment