[antlr-interest] Best practices to insert breakpoint when generating code?

Chan David lifesting at gmail.com
Mon Sep 26 20:38:46 PDT 2011


Hi, Antlr fellows:

I wrote a simple parser and a weak runtime to make a prototype of our DSL. I
followed the de-facto definition steps:


   1. Define a lex grammar to describe tokens.
   2. Define a parser grammar to describe syntax and build an AST.
   3. Define a tree grammar to genereate DSL source code via StringTemplate
   which includes my hand-written execution code as runtime.

Now I want to run this DSL code in Eclipse directly. So I must let DSL
support debugging.  I must embbed a hook function in every start of a
statement. I named this function 'breakpoint', it need a line number as
argument.

For example, there's a "x=1" statement in my DSL where AST is ^(ASSIGN, x,
1) . I insert a function like below:

assignStmt @init{
  breakpoint(Problem: how to get line number here?);
} :  ^(ASSIGN, ID, INT) {
 .....//Omitted
}

I don't know how to get line number at the start of a statement, further, I
doubt whether this method is correct.

Thank for you help!


More information about the antlr-interest mailing list