Debugging your grammars

In this section, you will learn more about debugging ANTLR grammars in the workbench.

System Requirements and limitations

ANTLR Breakpoints

  1. Double click in Expr.g file to open it with the ANTLR editor.
  2. Select the "INT" rule inside the "atom" rule. Right click on the rule an select ANTLR Breakpoints. Note that you can not add breakpoints by double click.
  3. Add ANTLR Breakpoints

  4. The "ANTLR Breakpoints" dialog show information about the selected element. In the breakpoint type list select LT and click OK.
  5. LT ANTLR Breakpoint

  6. The breakpoints are displayed in the vertical rule. To remove a breakpoint you need to open Breakpoints view and remove it from there.
  7. LT ANTLR Breakpoint

  8. Select Interpreter page
  9. Select the "prog" rule in the Rule Panel
  10. Select the "simpleTest" test case in the Test Panel
  11. Select the "Debug (Java)" button
  12. ANTLR Console

    The "Run (Java)"/"Debug (Java)" button are available for saved test case

    You can only run/debug combined/parser grammars

  13. In the Confirm Perspective Switch dialog click Yes.
  14. ANTLR Console

  15. The ANTLR debug perspective.
  16. ANTLR Console

  17. Let's take a look at each view.
  18. The Debug view.
  19. ANTLR Debug View

    This view show the rule invocation stack to the current breakpoint. You can click on any element to follow the invocation path to the current breakpoint.

  20. The ANTLR Debug Events view.
  21. ANTLR Debug Events View

    This view show the debug events generated by ANTLR. The first event (LT INT 1:0 "3") is the last event generated by ANTLR, here you can see the next token ("3") to be consumed by ANTLR.

  22. The ANTLR Debug Tree view.
  23. ANTLR Debug Tree View

    This view show a tree representation of the rules matched by ANTLR.

  24. The ANTLR Debug Input view.
  25. ANTLR Debug Input View

    This view show the current input consumed by ANTLR. At this point there is any token consumed yet. Click on the resume button on the Debug view.

    ANTLR Debug Input View

    Now you can see the previous token "3" already consumed by ANTLR and in the ANTLR Debug Events view you can see the next token ("6") before be consumed by ANTLR.

  26. Click on the resume button on the Debug view to resume the program.
  27. The text "9" is displayed in the Console view.
SourceForge.net Logo