[antlr-interest] How to debug grammars on Vista (was: How to debug tree grammar??)

sunao furukawa sadie at kind.ocn.ne.jp
Mon Aug 3 03:55:17 PDT 2009


Hello! Everybody.
some days ago,I got a reply from this mailinglist(David-Sarah Hopwood).
ANTLRWorks generated(debug menu->debug) __Test__.java,
debugging(debug menu->debug remote) T1.g is successful.
But,TestE.java doesn't get a port(DEBUGGER_PORT 48000),
so debug remote(debug menu->debug remote) doesn't work.
I use antlrworks-1.2.3 on Windows Vista Home Basic sp1.
Why cannot I debug remote TestE.java ?
Please tell me the reason that I can debug __Test__.java but I cannot debug 
TestE.java !
File, below,
---------------------------------------------------------------------------
<TestE.java>
import java.io.*;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.debug.DebugEventSocketProxy;

public class TestE {
    private static final int DEBUGGER_PORT = 48000;
    public static void main(String[] args) throws Exception {
        ANTLRInputStream input = new ANTLRInputStream(System.in);
        E3Lexer lexer = new E3Lexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        E3Parser parser = new E3Parser(tokens,DEBUGGER_PORT,new 
RecognizerSharedState());

        E3Parser.prog_return r = parser.prog();

        CommonTree t = (CommonTree)r.getTree();
        CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
        T1 walker = new T1(nodes);
        walker.prog();
    }
}
-----------------------------------------------------------------------------
<__Test__.java>
import java.io.*;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.runtime.debug.DebugEventSocketProxy;


public class __Test__ {
    private static final int DEBUGGER_PORT = 48000;
    public static void main(String args[]) throws Exception {
        E3Lexer lex = new E3Lexer(new 
ANTLRFileStream("C:\\Users\\sunao\\Desktop\\output\\__Test___input.txt"));
        CommonTokenStream tokens = new CommonTokenStream(lex);

        E3Parser parser = new E3Parser(tokens, DEBUGGER_PORT, new 
RecognizerSharedState());

        E3Parser.prog_return r = parser.prog();
        CommonTreeNodeStream nodes = new CommonTreeNodeStream(r.getTree());

        T1 walker = new T1(nodes);
        try {
            walker.prog();
        } catch (RecognitionException e) {
            e.printStackTrace();
        }
    }
------------------------------------------------------------------------------
<E3.g>
grammar E3;

options{
 output = AST;
 ASTLabelType = CommonTree;
}

tokens{
 ASSIGN; ALU_ADD; ALU_SUB; ALU_MUL; ALU_DIV;
}

prog
 : (
   statement
  { if ($statement.tree != null) 
System.out.println($statement.tree.toStringTree());}
   )+

 ;
statement
 : expression NEWLINE!
 | IDENTIFIER '=' expression NEWLINE
  -> ^(ASSIGN IDENTIFIER expression)
 | NEWLINE!
 ;
expression
 : product (aop^ product)*
 ;
aop
 : '+'
  -> ALU_ADD
 | '-'
  -> ALU_SUB
 ;
product
 : factor (pop^ factor)*
 ;
pop
 : '*'
  -> ALU_MUL
 | '/'
  -> ALU_DIV
 ;
factor
 : IDENTIFIER
 | CONSTANT
 | '('! expression ')'!
 ;

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

---------------------------------------------------------------------
<T1.g>
tree grammar T1;

options{
 tokenVocab=E3;
 ASTLabelType = CommonTree;
 output=AST;
}

@header {
import java.util.HashMap;
}

@members {
HashMap memory = new HashMap();
}

prog : statement+ ;

statement
 : e=expression
  { System.out.println($e.value); }
 | ^(ASSIGN id=IDENTIFIER e=expression)
  { memory.put($id.text, new Integer($e.value)); }
 ;
expression returns [int value]
 : ^(ALU_ADD a=expression b=expression)
  {$value = $a.value + $b.value;}
 | ^(ALU_SUB a=expression b=expression)
  {$value = $a.value - $b.value;}
 | ^(ALU_MUL a=expression b=expression)
  {$value = $a.value * $b.value;}
 | ^(ALU_DIV a=expression b=expression)
  {$value = $a.value / $b.value;}
 | IDENTIFIER
  {
  Integer v = (Integer)memory.get($IDENTIFIER.text);
  if (v != null) $value = v.intValue();
  else System.err.println("undefined variable " + $IDENTIFIER.text);
  }
 | CONSTANT
  { $value = Integer.parseInt($CONSTANT.text); }
 ;
-------------------------------------------------------------------------
----- Original Message ----- 
From: "David-Sarah Hopwood" <david-sarah at jacaranda.org>
To: <antlr-interest at antlr.org>
Sent: Tuesday, July 21, 2009 3:48 AM
Subject: Re: [antlr-interest] How to debug grammars on Vista (was: How to 
debug tree grammar??)


> sunao furukawa wrote:
> [...]
>> 4.I started ANTLRWorks debug remote in localhost port 49153.
>> 5.I executed [java TestE],and standard input [a=1 (CRLF) a+2*3 (CRLF)
>> (Ctrl-C)].
>>
>> But I could not debug T1.g and below, error occur.
>> (ASSIGN a 1)
>> line 0:-1 mismatched input '<EOF>' expecting NEWLINE
>> <mismatched token: [@-1,0:0='<no text>',<-1>,0:-1], resync=a+2*3>
>> java.net.BindException: Address already in use: JVM_Bind
> [...]
>> I use Windows Vista Home Basic sp1.IP adress is private(dhcp).
>
> I found that the default port 49153 could not be used on Vista. You
> need to override it:
>
> - in the ANTLRWorks preferences (File menu | Preferences | Debugger tab),
>   set 'Default local port' to an unused port number. I used 48000.
>
>   If you need to use remote debugging (where the debugged process is
>   launched separately from ANTLRWorks), also add -debug to the ANTLR
>   options in the General tab.
>
> - pass this port number into the E3Parser, e.g.:
>
>> public class TestE {
>      private static final int DEBUGGER_PORT = 48000;
>
>>     public static void main(String[] args) throws Exception {
>>         ANTLRInputStream input = new ANTLRInputStream(System.in);
>>         E3Lexer lexer = new E3Lexer(input);
>>         CommonTokenStream tokens = new CommonTokenStream(lexer);
>
>          E3Parser parser = new E3Parser(tokens, DEBUGGER_PORT,
>                                         new RecognizerSharedState());
>
>>         E3Parser.prog_return r = parser.prog();
>>
>>         CommonTree t = (CommonTree)r.getTree();
>>         CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
>>         T1 walker = new T1(nodes);
>>         walker.prog();
>>     }
>> }
>
> This is not dependent on the grammar being a tree grammar.
>
> -- 
> David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 




More information about the antlr-interest mailing list