[antlr-interest] AntlrWorks just hangs when trying to step through the tutorial..

Jeffrey Newman jeffn at photorepo.com
Sun Dec 5 16:24:35 PST 2010


I'm just learning Antlr and AntlrWorks.
I have downloaded AntlrWorks (I assume antlr came with it).
It comes up. (On Linux 64, with the latest Java from Sun.
I put the java bins in my path. My CLASSPATH is empty.)

I started on the AntlrWorks tutorial.
Below is the grammer, and the events.

When I ran the interpreter, I was able to see a parse tree. Cool.
When I ran the debugger, it hung.
I tried to single step.
Below is as far as I got before it hung.

Can anyone explain why.

Now, back to Terence's book...

thanks

Jeffrey


>From Events.

0
Commence




1
Enter
rule /home/jeffn/Expr.g:prog




2
Location
(15,1)




3
Enter alt 1




4
Location
(15,9)




5
Enter
subrule 1
1





Grammer

rammar Expr;

@header {
package test;
import java.util.HashMap;
}

@lexer::header {package test;}

@members {
/** Map variable name to Integer object holding value */
HashMap memory = new HashMap();
}

prog:   stat+ ;
                
stat:   expr NEWLINE {System.out.println($expr.value);}
    |   ID '=' expr NEWLINE
        {memory.put($ID.text, new Integer($expr.value));}
    |   NEWLINE
    ;

expr returns [int value]
    :   e=multExpr {$value = $e.value;}
        (   '+' e=multExpr {$value += $e.value;}
        |   '-' e=multExpr {$value -= $e.value;}
        )*
    ;

multExpr returns [int value]
    :   e=atom {$value = $e.value;} ('*' e=atom {$value *= $e.value;})*
    ; 

atom returns [int value]
    :   INT {$value = Integer.parseInt($INT.text);}
    |   ID
        {
        Integer v = (Integer)memory.get($ID.text);
        if ( v!=null ) $value = v.intValue();
        else System.err.println("undefined variable "+$ID.text);
        }
    |   '(' e=expr ')' {$value = $e.value;}
    ;

ID  :   ('a'..'z'|'A'..'Z')+ ;
INT :   '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t')+ {skip();} ;




More information about the antlr-interest mailing list