Sunday, May 18, 2014

CREATING ANTLR PROJECT


  1.  Run Eclipse.
  2. File – New – Java Project. (Figure 1)



    Figure 1
  3. Write Project Name – Click Finish button. (Figure 2)



    Figure 2

  4. Right Click over Project – Configure – Convert to ANTLR Project. (Figure 3)



    Figure 3

  5. Right click over src director under your Project. New – Other. (Figure 4)



    Figure 4

  6. Select ANTLR – Combined Grammar – Next. (Figure 5)



    Figure 5

  7. Write grammar Name (for ex. T). Click Finish button. (Figure 6)



    Figure 6

  8. Write your grammar. Then when you save your grammer, TLexer.java, TParser.java files are generated automatically under antlr-generated directory. (Figure 7, 8)


    Figure 7



    Figure 8

  9. Right click over antlr-generated directory. Build Path – Use as Source Folder. (Figure 9)



    Figure 9

  10. After Step 9, Project will give errors. (Figure 10)



    Figure 10

  11. Right click over Project – Build Path – Configure Build Path. (Figure 11)



    Figure 11

  12. Click Add External JARs… button. Find antlr-3.3 jar which is located in advance. (Figure 12)



    Figure 12

  13. Write your Test. Java file under antlr-genereated directory. (Figure 13)



    Figure 13

  14.  Run Test file.  (Figure 14)



    Figure 14

  15. The command is correct. So in the console there is no error message. (Figure 15)



    Figure 15

  16. If we don’t add ‘;’ at the end of the command, it will give error in the console. (Figure 16)



    Figure 16

TESTING AND GETTING PARSER TREES

  1. Open grammar file. Then Click interpreter tab. (Figure 17)



    Figure 17

  2. In opened screen, select rule, then write test command. Then click play button. Parse tree will be displayed. (Figure 18)



    Figure 18

  3. Example of wrong command. (Figure 19)



    Figure 19

  4. Click Railroad View tab. (Figure 20)



    Figure 20

  5. 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