Loading ...
Sorry, an error occurred while loading the content.

RE: [antlr-interest] Re: Does -traceTreeWalker work in antlr-2.7.0 ?

Expand Messages
  • Monty Zukowski
    It should work. Give it a try and let me know of any problems. Monty
    Message 1 of 14 , Apr 27 6:59 AM
    • 0 Attachment
      It should work. Give it a try and let me know of any problems.

      Monty

      > I saw in your GnuC project that you had Java code within the
      > GnuCEmitter.g that looked like it reported "the things within".
      >
      > Can I "just" transfer this with very little "trouble/work" and get
      > the LookAhead (LA()) data that I need?
    • danreo1952@yahoo.com
      Ok, I got it complied without errors, but I gives me a java.lang.NullPointerException error . I don t know what this really means: 1. It can t fine the
      Message 2 of 14 , May 6, 2001
      • 0 Attachment
        Ok, I got it complied without errors, but I gives me a
        java.lang.NullPointerException "error".
        I don't know what this really means:
        1. It can't fine the method,
        2. I did not set up something properly,
        3. I did not get somthing it wants???

        Section 1. the error report
        Section 2. PascalTreeWalker.g

        Let know what you think.
        Thank You
        Bill B.
        /////////////////////////////
        Section 1.


        2. after dotreeAction: program inflation ( output ) ; var w1 :
        factorial ; i1
        integer ; begin w1 := 10.1 ; i1 := 1 ; writeln ( w1 , i1 ) ; w1 := w1
        * 1.1 ;
        1 := i1 + 1 ; writeln ( w1 , i1 ) ; while ( i1 < 2 ) do ( i1 := i1 +
        1 ; writ
        ln ( i1 ) ; ) end ., the end.
        1. in initializePrinting, oonnee:1.
        parser exception: java.lang.NullPointerException
        java.lang.NullPointerException
        at
        PascalTreeWalker.initializePrinting(PascalTreeWalker.java:63)
        at PascalTreeWalker.translationUnit(PascalTreeWalker.java:356)
        at Main.parseFile(Main.java:99)
        at Main.doFile(Main.java:68)
        at Main.main(Main.java:41)

        [Win95]C:\antlr-2.7.0\examples\java\pascal>

        ////////////////////////////////////
        Section 2.

        header{
        import java.io.IOException;
        import java.io.StreamTokenizer;
        import java.io.InputStreamReader;
        import antlr.CommonAST;
        import antlr.DumpASTVisitor;
        import antlr.CommonAST;
        import antlr.collections.AST;

        import java.util.Stack;
        import java.util.Vector;
        import java.util.Hashtable;
        import java.util.Enumeration;
        import java.io.*;
        import java.lang.*;
        import java.util.*;
        import antlr.collections.*;
        import antlr.collections.impl.*;
        import antlr.debug.misc.*;
        import antlr.*;
        }
        class PascalTreeWalker extends TreeParser;
        options {
        importVocab = Pascal;
        //codeGenMakeSwitchThreshold = 2; // Some optimizations
        //codeGenBitsetTestThreshold = 3;
        k = 4 ; // 2 token lookahead
        defaultErrorHandler = false ; // Don't generate parser error
        handlers
        buildAST = true;
        }
        {
        Utils u = new Utils();
        Hashtable variables = new Hashtable();
        //PreprocessorInfoChannel p = new PreprocessorInfoChannel();
        ////////////////////////////////////////////
        int tabs = 0;
        PrintStream currentOutput = System.out;
        int lineNum = 1;
        String currentSource = "";
        LineObject trueSourceFile;
        final int lineDirectiveThreshold = Integer.MAX_VALUE;
        PreprocessorInfoChannel preprocessorInfoChannel = null;
        Stack sourceFiles = new Stack();
        Integer oonnee = new Integer(1);

        PascalTreeWalker( PreprocessorInfoChannel preprocChannel )
        {
        preprocessorInfoChannel = preprocChannel;
        System.out.println("PascalTreeWalker constructor.....");
        }

        void initializePrinting()
        {
        System.out.println("1. in initializePrinting, oonnee:" + oonnee +
        ".");
        Vector preprocs =
        preprocessorInfoChannel.extractLinesPrecedingTokenNumber( oonnee );
        System.out.println("2. in initializePrinting, preprocs:" + preprocs +
        ".");
        printPreprocs(preprocs);
        if ( currentSource.equals("") ) {
        trueSourceFile = new LineObject(currentSource);
        currentOutput.println("# 1 \"" + currentSource +
        "\"\n");
        sourceFiles.push(trueSourceFile);
        }

        }

        void finalizePrinting() {
        // flush any leftover preprocessing instructions to the
        stream

        printPreprocs(

        preprocessorInfoChannel.extractLinesPrecedingTokenNumber(
        new Integer(
        preprocessorInfoChannel.getMaxTokenNumber() + 1 ) ));
        //print a newline so file ends at a new line
        currentOutput.println();
        }

        void printPreprocs( Vector preprocs )
        {
        // if there was a preprocessingDirective previous to this
        token then
        // print a newline and the directive, line numbers handled
        later
        if ( preprocs.size() > 0 ) {
        if ( trueSourceFile != null ) {
        currentOutput.println(); //make sure we're
        starting a new line unless this is the first line directive
        }
        lineNum++;
        Enumeration e = preprocs.elements();
        while (e.hasMoreElements())
        {
        Object o = e.nextElement();
        if ( o.getClass().getName().equals("LineObject") )
        {
        LineObject l = (LineObject) o;

        // we always return to the trueSourceFile, we
        never enter it from another file
        // force it to be returning if in fact we
        aren't currently in trueSourceFile
        if (( trueSourceFile != null ) //trueSource
        exists
        && (
        !currentSource.equals(trueSourceFile.getSource()) ) //currently not in
        trueSource
        && (
        trueSourceFile.getSource().equals(l.getSource()) ) ) { //returning to
        trueSource
        l.setEnteringFile( false );
        l.setReturningToFile( true );
        }


        // print the line directive
        currentOutput.println(l);
        lineNum = l.getLine();
        currentSource = l.getSource();


        // the very first line directive always
        represents the true sourcefile
        if ( trueSourceFile == null ) {
        trueSourceFile = new
        LineObject(currentSource);
        sourceFiles.push(trueSourceFile);
        }

        // keep our own stack of files entered
        if ( l.getEnteringFile() ) {
        sourceFiles.push(l);
        }

        // if returning to a file, pop the exited
        files off the stack
        if ( l.getReturningToFile() ) {
        LineObject top = (LineObject)
        sourceFiles.peek();
        while (( top != trueSourceFile ) && (!
        l.getSource().equals(top.getSource()) )) {
        sourceFiles.pop();
        top = (LineObject) sourceFiles.peek();
        }
        }
        }
        else { // it was a #pragma or such
        currentOutput.println(o);
        lineNum++;
        }
        }
        }

        }

        void print( TNode t ) {
        int tLineNum = t.getLocalLineNum();
        if ( tLineNum == 0 ) tLineNum = lineNum;

        Vector preprocs =
        preprocessorInfoChannel.extractLinesPrecedingTokenNumber((Integer)t.ge
        tAttribute("tokenNumber"));
        printPreprocs(preprocs);

        if ( (lineNum != tLineNum) ) {
        // we know we'll be newlines or a line directive or it
        probably
        // is just the case that this token is on the next
        line
        // either way start a new line and indent it
        currentOutput.println();
        lineNum++;
        printTabs();
        }

        if ( lineNum == tLineNum ){
        // do nothing special, we're at the right place
        }
        else {
        int diff = tLineNum - lineNum;
        if ( lineNum < tLineNum ) {
        // print out the blank lines to bring us up to
        right line number
        for ( ; lineNum < tLineNum ; lineNum++ ) {
        currentOutput.println();
        }
        printTabs();
        }
        else { // just reset lineNum
        lineNum = tLineNum;
        }
        }
        currentOutput.print( t.getText() + " " );
        }


        /* This was my attempt at being smart about line numbers
        It didn't work quite right but I don't know why, I didn't
        have enough test cases. Worked ok compiling rcs and
        ghostscript
        */
        void printAddingLineDirectives( TNode t ) {
        int tLineNum = t.getLocalLineNum();
        String tSource = (String) t.getAttribute("source");

        if ( tSource == null ) tSource = currentSource;
        if ( tLineNum == 0 ) tLineNum = lineNum;

        Vector preprocs =
        preprocessorInfoChannel.extractLinesPrecedingTokenNumber((Integer)t.ge
        tAttribute("tokenNumber"));
        printPreprocs(preprocs);

        if ( (lineNum != tLineNum) ||
        !currentSource.equals(tSource) ) {
        // we know we'll be newlines or a line directive or it
        probably
        // is just the case that this token is on the next
        line
        // either way start a new line and indent it
        currentOutput.println();
        lineNum++;
        printTabs();
        }

        if ( ( lineNum == tLineNum ) && (
        currentSource.equals(tSource) ) ){
        // do nothing special, we're at the right place
        }
        else if ( currentSource.equals(tSource) ) {
        int diff = tLineNum - lineNum;
        if (diff > 0 && diff < lineDirectiveThreshold) {
        // print out the blank lines to bring us up to
        right line number
        for ( ; lineNum < tLineNum ; lineNum++ ) {
        currentOutput.println();
        }
        }
        else { // print line directive to get us to right line
        number
        // preserve flags 3 and 4 if present in current
        file
        if ( ! sourceFiles.empty() ) {
        LineObject l = (LineObject)
        sourceFiles.peek();
        StringBuffer tFlags = new StringBuffer("");
        if (l.getSystemHeader()) {
        tFlags.append(" 3");
        }
        if (l.getTreatAsC()) {
        tFlags.append(" 4");
        }
        currentOutput.println("# " + tLineNum + " \""
        + tSource + "\"" + tFlags.toString());
        lineNum = tLineNum;
        }
        }

        printTabs();
        }
        else { // different source
        Enumeration sources = sourceFiles.elements();
        // see if we're returning to a file we entered earlier
        boolean returningToEarlierFile = false;
        while (sources.hasMoreElements()) {
        LineObject l = (LineObject) sources.nextElement();
        if (l.getSource().equals(tSource)) {
        returningToEarlierFile = true;
        break;
        }
        }
        if (returningToEarlierFile) {
        // pop off the files we're exiting, but never pop
        the trueSourceFile
        LineObject l = (LineObject) sourceFiles.peek();
        while ( ( l != trueSourceFile ) &&(!
        l.getSource().equals(tSource) ) ) {
        sourceFiles.pop();
        l = (LineObject) sourceFiles.peek();
        }

        // put in the return flag, plus others as needed
        StringBuffer tFlags = new StringBuffer(" 2");
        if (l.getSystemHeader()) {
        tFlags.append(" 3");
        }
        if (l.getTreatAsC()) {
        tFlags.append(" 4");
        }

        currentOutput.println("# " + tLineNum + " \"" +
        tSource + "\"" + tFlags);
        lineNum = tLineNum;
        currentSource = tSource;
        printTabs();
        }
        else { // entering a file that wasn't in the original
        source
        // pretend we're entering it from top of stack
        currentOutput.println("# " + tLineNum + " \"" +
        tSource + "\"" + " 1");
        lineNum = tLineNum;
        currentSource = tSource;
        printTabs();
        }
        }
        currentOutput.print( t.getText() + " " );
        }

        /** It is not ok to print newlines from the String passed in
        as
        it will screw up the line number handling **/
        void print( String s ) {
        currentOutput.print( s + " " );
        }

        void printTabs() {
        for ( int i = 0; i< tabs; i++ ) {
        currentOutput.print( "\t" );
        }
        }

        void commaSep( TNode t ) {
        print( t );
        if ( t.getNextSibling() != null ) {
        print( "," );
        }
        }

        int traceDepth = 0;
        public void reportError(RecognitionException ex) {
        if ( ex != null) {
        System.err.println("ANTLR Tree Parsing
        RecognitionException Error: " + ex.getClass().getName() + " " + ex );
        ex.printStackTrace(System.err);
        }
        }
        public void reportError(NoViableAltException ex) {
        System.err.println("ANTLR Tree Parsing
        NoViableAltException Error: " + ex.toString());
        TNode.printTree( ex.node );
        ex.printStackTrace(System.err);
        }
        public void reportError(MismatchedTokenException ex) {
        if ( ex != null) {
        TNode.printTree( ex.node );
        System.err.println("ANTLR Tree Parsing
        MismatchedTokenException Error: " + ex );
        ex.printStackTrace(System.err);
        }
        }
        public void reportError(String s) {
        System.err.println("ANTLR Error from String: " + s);
        }
        public void reportWarning(String s) {
        System.err.println("ANTLR Warning from String: " + s);
        }
        protected void match(AST t, int ttype) throws
        MismatchedTokenException {
        //System.out.println("match("+ttype+"); cursor is
        "+t);
        super.match(t, ttype);
        }
        public void match(AST t, BitSet b) throws
        MismatchedTokenException {
        //System.out.println("match("+b+"); cursor is "+t);
        super.match(t, b);
        }
        protected void matchNot(AST t, int ttype) throws
        MismatchedTokenException {
        //System.out.println("matchNot("+ttype+"); cursor is
        "+t);
        super.matchNot(t, ttype);
        }
        public void traceIn(String rname, AST t) {
        traceDepth += 1;
        for (int x=0; x<traceDepth; x++) System.out.print(" ");
        super.traceIn(rname, t);
        }
        public void traceOut(String rname, AST t) {
        for (int x=0; x<traceDepth; x++) System.out.print(" ");
        super.traceOut(rname, t);
        traceDepth -= 1;
        }
        ////////////////////////////////////////////
        }

        translationUnit options {
        defaultErrorHandler=false;
        }
        : { initializePrinting(); }
        ( program )?
        { finalizePrinting(); }
        ;

        exception catch [RecognitionException ex]
        {
        reportError(ex);
        System.out.println("PROBLEM TREE:\n" + _t.toStringList());
        if (_t!=null) {_t = _t.getNextSibling();}
        }

        whileStatement
        : { System.out.println( " Starting WHILE loop "); }
        WHILE { System.out.println( " 111. "); }
        LPAREN! { System.out.println( " 222. "); }
        CONDITION { System.out.println( " 333. "); }
        c1:expression
        { StringBuffer a1 = new StringBuffer(c1.toString());
        System.out.println("in condition, a1:" + a1 + "."); }
        ( empty | c:conditionOperator

        c2:term
        { StringBuffer a3 = new StringBuffer(c2.toString());
        System.out.println("in condition, a3:" + a3 + "."); }
        )
        RPAREN DO
        LPAREN cb:CODE_BLOCK (statement SEMI)* RPAREN
        {
        while (condition(c) == 0 )
        {
        code_block(cb);
        }
        }
        ;

        condition returns [int yes]
        {
        yes=0; System.out.println("in condition");
        }
        :
        CONDITION
        c1:term
        { StringBuffer a1 = new StringBuffer(c1.toString());
        System.out.println("in condition, a1:" + a1 + "."); }
        ( empty | co:conditionOperator
        { StringBuffer a2 = new StringBuffer(co.toString());
        System.out.println("in condition, a2:" + a2 + "."); }

        c2:term
        { StringBuffer a3 = new StringBuffer(c2.toString());
        System.out.println("in condition, a3:" + a3 + "."); }
        )
        RPAREN

        {
        if ( co != null && yes == 0 )
        {
        StringBuffer aaaa = new StringBuffer(c1.toString());
        StringBuffer bbbb = new StringBuffer(co.toString());
        StringBuffer cccc = new StringBuffer(c2.toString());
        yes=u.condition(variables, aaaa, bbbb, cccc);
        System.out.println("in condition, yes: " + yes + "..." );
        System.out.println("in condition, aaaa==" + aaaa + "==, bbbb==" + bbbb
        + "==, cccc==" + cccc + "==.");
        }
        }
        ;

        code_block
        : CODE_BLOCK (statement SEMI)*
        ;

        program {
        // Info............hashtable name int var type str_content
        //u.ht_load(variables, "zero", 0, "factorial", "");
        //u.ht_load(variables, "posOne", 1, "factorial", "");
        //u.ht_load(variables, "negOne", -1, "factorial", "");
        //u.ht_dump(variables, "Variable Dump:");
        }
        : programHeadingStatement block
        { System.exit(0); }
        DOT
        ;
        programHeadingStatement
        : PROGRAM identifier
        LPAREN identifier ( COMMA identifier )* RPAREN SEMI
        ;
        block : ( variableDeclarationPart )* statementPart
        ;
        // Declaration Part
        variableDeclarationPart
        : VAR v1:variableDeclaration SEMI ( v2:variableDeclaration
        SEMI )*
        ;
        variableDeclaration
        : id1:identifier COLON ty1:type
        {
        //System.out.println("ident==" + id1 + "==, type==" + ty1 +
        "==.");
        StringBuffer aaaa = new StringBuffer(id1.toString());
        StringBuffer bbbb = new StringBuffer(ty1.toString());
        u.var_declare(variables, aaaa, bbbb);
        }
        ;
        statementPart
        : BEGIN (statement SEMI)* END
        ;
        //BEGIN statement SEMI (statement SEMI)* END
        statement
        : assignmentStatement
        | writelnStatement
        | whileStatement
        ;
        assignmentStatement
        : var1:variable ASSIGN at1:assignmentType
        {
        System.out.println("in assignmentStatement, var1==" + var1 +
        "==, at1==" + at1 + "==;");
        StringBuffer aaaa = new StringBuffer(var1.toString());
        StringBuffer bbbb = new StringBuffer(at1.toString());
        u.var_assign(variables, aaaa, bbbb);
        }
        ;
        assignmentType
        : expression
        | unsignedReal
        | unsignedInteger
        ;
        writelnStatement
        :{ System.out.println(" Starting WRITELN " ); }
        WRITELN LPAREN ii:identifier
        {
        //System.out.println(" WRITELN LPAREN identifier==" + ii +
        "==,");
        StringBuffer aaaa = new StringBuffer(ii.toString());
        u.var_print(variables, aaaa);
        }
        ( COMMA ioi:identifier
        {
        //System.out.println(" COMMA identifier==" + ioi + "==,");
        StringBuffer bbbb = new StringBuffer(ioi.toString());
        u.var_print(variables, bbbb);
        }
        )*
        RPAREN
        {
        //u.ht_dump(variables);
        //System.out.println("\n RPAREN ");
        //System.out.println();
        }
        ;
        expression
        : t1:simpleExpression //{ System.out.println("444. t1:" + t1 +
        "." ); }
        ( empty |
        (ro:mathOperator //{ System.out.println("555. ro:" + ro +
        "." ); }
        t2:simpleExpression //{ System.out.println("666. t2:" + t2 +
        "." ); }
        ) )
        {
        if ( ro != null)
        {
        System.out.println("in expression, term==" + t1 + "==,
        ro==" + ro + "==, t2==" + t2 + "==.");
        StringBuffer aaaa = new StringBuffer(t1.toString());
        StringBuffer bbbb = new StringBuffer(ro.toString());
        StringBuffer cccc = new StringBuffer(t2.toString());
        u.expression(variables, aaaa, bbbb, cccc);
        }
        }
        ;
        simpleExpression
        : ( sign | empty )
        t:term //{ System.out.println("777. t:" + t + "." ); }
        ( ao:mathOperator tt:term )*
        ;
        mathOperator
        : PLUS | MINUS | STAR | SLASH | DIV | MOD
        ;
        conditionOperator
        : EQUAL | NOT_EQUAL | LT | LE | GE | GT | OR | AND
        ;
        term : ff:factor //{ System.out.println("888. ff:" + ff + "." ); }
        ( mo:multiplyingOperator ff1:factor )*
        {
        System.out.println("in term, factor==" + ff + "==, mo==" + mo + "==,
        factor==" + ff1 + "==.");
        }
        ;
        multiplyingOperator
        :
        ;
        factor : vv:variable
        {System.out.println("in factor,variable:" + vv + ".");}
        ;
        variable: id:identifier
        | uI:unsignedInteger
        | uR:unsignedReal
        ;
        unsignedInteger
        : n:NUM_INT
        ;
        unsignedReal
        : n:NUM_REAL
        ;
        identifier
        : IDENT
        | STRING_LITERAL
        ;
        type : st:simpleType
        ;
        simpleType
        : scalarType
        | typeIdentifier
        ;
        scalarType
        : LPAREN id3:identifier ( COMMA id4:identifier )* RPAREN
        ;
        typeIdentifier
        : id5:identifier
        | STRING
        | INTEGER
        | FACTORIAL
        ;
        empty : /* empty */
        ;
        sign : PLUS | MINUS
        ;
        //////////////////////
        // EOF // End of File
      • Ric Klaren
        ... Which line is this line 63? At that place you are referencing an uninitialized reference type variable. E.g. variable of some class which was not
        Message 3 of 14 , May 7, 2001
        • 0 Attachment
          On Sun, May 06, 2001 at 06:20:13PM -0000, danreo1952@... wrote:
          > 1. in initializePrinting, oonnee:1.
          > parser exception: java.lang.NullPointerException
          > java.lang.NullPointerException
          > at
          > PascalTreeWalker.initializePrinting(PascalTreeWalker.java:63)

          Which line is this line 63? At that place you are referencing an
          uninitialized reference type variable. E.g. variable of some class which
          was not initialized with new or a valid pointer.

          Ric
          --
          -----+++++*****************************************************+++++++++-------
          ---- Ric Klaren ----- klaren@... ----- +31 53 4893722 ----
          -----+++++*****************************************************+++++++++-------
          Why don't we just invite them to dinner and massacre them all when they're
          drunk? You heard the man. There's seven hundred thousand of them.
          Ah? ... So it'd have to be something simple with pasta, then.
          --- From: Interesting Times by Terry Pratchet
          -----+++++*****************************************************+++++++++-------
        • danreo1952@yahoo.com
          God your fast. I was thinking about that, this morning while I was driving to work, and I realized what I did not do (had not done). Thanks. Bill B.
          Message 4 of 14 , May 7, 2001
          • 0 Attachment
            God your fast. I was thinking about that, this morning while I was
            driving to work, and I realized what I did not do (had not done).

            Thanks. Bill B.

            System.out.println("1. in initializePrinting, oonnee:" + oonnee +
            ".");
            // The line below (Vector pre...) is creating the problem.
            // The "System.out..." lines is my way of localizing the problem.

            Vector preprocs =
            preprocessorInfoChannel.extractLinesPrecedingTokenNumber( oonnee );

            System.out.println("2. in initializePrinting, preprocs:" + preprocs +
            ".");
            --------------------------------------------------------------------
            --- In antlr-interest@y..., Ric Klaren <klaren@c...> wrote:
            > On Sun, May 06, 2001 at 06:20:13PM -0000, danreo1952@y... wrote:
            > > 1. in initializePrinting, oonnee:1.
            > > parser exception: java.lang.NullPointerException
            > > java.lang.NullPointerException
            > > at
            > > PascalTreeWalker.initializePrinting(PascalTreeWalker.java:63)
            >
            > Which line is this line 63? At that place you are referencing an
            > uninitialized reference type variable. E.g. variable of some class
            which
            > was not initialized with new or a valid pointer.
            >
            > Ric
          • danreo1952@yahoo.com
            When will -traceTreeWalker be fixed? I looked at earlier posts in the group, and at that time -traceTreeWalker did not work. This is very poor work not to fix
            Message 5 of 14 , May 13, 2001
            • 0 Attachment
              When will -traceTreeWalker be fixed?
              I looked at earlier posts in the group, and at that time
              -traceTreeWalker did not work.
              This is very poor work not to fix this problem.
              This is a very basic problem in the system and why, after 2 years,
              it has not been fixed, seems a bit dum.
              Does antlr-2.7.1 -traceTreeWalker work?
              Will antlr-2-7.2 -traceTreeWalker work?

              I am hacking my way thru this. I go into PascaelTreeWalker.java
              and use "System.out.println("_t" + _t + ".");" before the
              creation of the error message.

              Is there a better way???
            • Ric Klaren
              Hi, ... AFAIK it works. I use it having no trouble whatsoever (I use normally my 2.7.1 devel snapshot or later). AFAIK it works in 2.7.1 as well. Furthermore
              Message 6 of 14 , May 14, 2001
              • 0 Attachment
                Hi,

                On Sun, May 13, 2001 at 02:42:21PM -0000, danreo1952@... wrote:
                > When will -traceTreeWalker be fixed?

                AFAIK it works. I use it having no trouble whatsoever (I use normally my
                2.7.1 devel snapshot or later). AFAIK it works in 2.7.1 as well.

                Furthermore it's -traceTreeParser. Like monty replied to you after your
                first mail:

                http://groups.yahoo.com/group/antlr-interest/message/3545

                After spending five minutes getting to figure out again how to run the java
                calc example (why is running java programs such a pain...) I can confirm
                -traceTreeParser works in C++ mode and Java mode in my devel version (so
                probably will work in 2.7.2..)

                > This is very poor work not to fix this problem.

                I already fixed the docu in my devel version. So that will probably go to
                2.7.2.

                > Is there a better way???

                Uhm... <tries typing while sitting on hands to prevent 'smartass remarks'>

                Cheers,

                Ric
                --
                -----+++++*****************************************************+++++++++-------
                ---- Ric Klaren ----- klaren@... ----- +31 53 4893722 ----
                -----+++++*****************************************************+++++++++-------
                Why don't we just invite them to dinner and massacre them all when they're
                drunk? You heard the man. There's seven hundred thousand of them.
                Ah? ... So it'd have to be something simple with pasta, then.
                --- From: Interesting Times by Terry Pratchet
                -----+++++*****************************************************+++++++++-------
              • danreo1952@yahoo.com
                1. The output I am looking for is just like -traceParser in 2.7.0 It shows all lookahead tokens. -traceTreeWalker, according to 2.7.0 docs, or actually
                Message 7 of 14 , May 15, 2001
                • 0 Attachment
                  1.
                  The output I am looking for is just like -traceParser in 2.7.0
                  It shows all "lookahead" tokens.
                  -traceTreeWalker, according to 2.7.0 docs, or "actually"
                  -traceTreeParser is like -trace with a lookahead of "k=1".
                  in 2.7.0 and 2.7.1

                  -traceParser is the best. Why can't it be in -traceTreeParser?

                  2.
                  Yes, I agree. Java examples and Java are hard to setup.

                  Thanks, Bill B.

                  > > When will -traceTreeWalker be fixed?
                  >
                  > AFAIK it works.
                • Monty Zukowski
                  ... Tree parsers can only have lookahead of k=1! This is because a tree is not linear like a stream, it is two dimensional--from any node you can have a
                  Message 8 of 14 , May 15, 2001
                  • 0 Attachment
                    > The output I am looking for is just like -traceParser in 2.7.0
                    > It shows all "lookahead" tokens.
                    > -traceTreeWalker, according to 2.7.0 docs, or "actually"
                    > -traceTreeParser is like -trace with a lookahead of "k=1".
                    > in 2.7.0 and 2.7.1
                    >
                    > -traceParser is the best. Why can't it be in -traceTreeParser?

                    Tree parsers can only have lookahead of k=1! This is because a tree is not
                    linear like a stream, it is two dimensional--from any node you can have a
                    sibling and a child. This is ok because you want to build your ASTs to be easy
                    to parse anyway, and you can do that easily with antlr's tree building
                    mechanisms. If you need them, you can use syntactic predicates, but I've never
                    needed to in a tree.

                    Monty
                  • danreo1952@yahoo.com
                    Ok, Thank You, Bill B. ... is not ... have a ... to be easy ... building ... I ve never
                    Message 9 of 14 , May 15, 2001
                    • 0 Attachment
                      Ok, Thank You, Bill B.

                      --- In antlr-interest@y..., "Monty Zukowski" <mzukowski@b...> wrote:
                      > > The output I am looking for is just like -traceParser in 2.7.0
                      > > It shows all "lookahead" tokens.
                      > > -traceTreeWalker, according to 2.7.0 docs, or "actually"
                      > > -traceTreeParser is like -trace with a lookahead of "k=1".
                      > > in 2.7.0 and 2.7.1
                      > >
                      > > -traceParser is the best. Why can't it be in -traceTreeParser?
                      >
                      > Tree parsers can only have lookahead of k=1! This is because a tree
                      is not
                      > linear like a stream, it is two dimensional--from any node you can
                      have a
                      > sibling and a child. This is ok because you want to build your ASTs
                      to be easy
                      > to parse anyway, and you can do that easily with antlr's tree
                      building
                      > mechanisms. If you need them, you can use syntactic predicates, but
                      I've never
                      > needed to in a tree.
                      >
                      > Monty
                    • Ric Klaren
                      Hi, ... Currently I use a kindoff dirty trick to debug treeparsers. This is C++ but the idea translates wel to java I guess... In every rule I use a custom
                      Message 10 of 14 , May 15, 2001
                      • 0 Attachment
                        Hi,

                        On Tue, May 15, 2001 at 01:12:59PM -0000, danreo1952@... wrote:
                        > -traceParser is the best. Why can't it be in -traceTreeParser?

                        Currently I use a kindoff 'dirty' trick to debug treeparsers. This is C++
                        but the idea translates wel to java I guess... In every rule I use a custom
                        error handler which prints out the input tree in the case of an error.
                        Embedded in the trace you then get the (sub)tree the rule barfed on. Which
                        works pretty well I must say.

                        Maybe together with the remarks here you might use it in java mode...

                        http://www.antlr.org/doc/sor.html#Examining_Debugging ASTs

                        An example of a rule. (Ok this does not work yet with current available
                        ANTLR's I fixed a bug concerning the #xxx_in ast stuff, this morning, I'll
                        release that devel version shortly)

                        assignment:
                        #( "=" IDENTIFIER_AST expression )
                        ;
                        exception
                        catch [antlr::RecognitionException &ex]
                        {
                        // tree printing class template...
                        print_tree<RefModest_AST,TreeParser> pr(*this);
                        pr.pr_tree(#assignment_in);

                        // set error message in treeparser class..
                        error_message = ex.getErrorMessage();
                        // update status
                        this->valid = false;
                        }

                        which produces output similar to:

                        <PROCESS_DEFINITION_AST=proc_def
                        <process IDENTIFIER=File PARAMETER_LIST_AST=params
                        <VARIABLE_DECLARATION_AST=var_decl
                        <TYPE_AST=int IDENTIFIER_AST=status >
                        >
                        <= IDENTIFIER_AST=status INT=0 >
                        <do
                        <:: IDENTIFIER_AST=start
                        <{=
                        <= IDENTIFIER_AST=status INT=1 >
                        >
                        >
                        <:: IDENTIFIER_AST=communication_established
                        <{=
                        <= IDENTIFIER_AST=status INT=0 >
                        >
                        >
                        >
                        >
                        >
                        --------snip----

                        Some might recognize this output as the one of the print_tree thing you can
                        find on Ian Kaplan's site. I adapted it a little bit for my own debugging
                        pleasure.

                        http://www.bearcave.com/software/antlr/antlr_examples.html

                        If there's interest for the template drop me a line.

                        Ric
                        --
                        -----+++++*****************************************************+++++++++-------
                        ---- Ric Klaren ----- klaren@... ----- +31 53 4893722 ----
                        -----+++++*****************************************************+++++++++-------
                        Why don't we just invite them to dinner and massacre them all when they're
                        drunk? You heard the man. There's seven hundred thousand of them.
                        Ah? ... So it'd have to be something simple with pasta, then.
                        --- From: Interesting Times by Terry Pratchet
                        -----+++++*****************************************************+++++++++-------
                      • Monty Zukowski
                        For java I used a similar trick in the GCC parser. Actually Jim Coker wrote that part. See TNode.java. Then if I was having problems I d add a catch clause
                        Message 11 of 14 , May 15, 2001
                        • 0 Attachment
                          For java I used a similar trick in the GCC parser. Actually Jim Coker wrote
                          that part. See TNode.java. Then if I was having problems I'd add a catch
                          clause and dump the tree out there.

                          Also in that code you will find a scheme for indenting the output from trace
                          methods so it is easier to visualize the stack of parser calls.

                          Monty

                          > -----Original Message-----
                          > From: Ric Klaren [mailto:klaren@...]
                          > Sent: Tuesday, May 15, 2001 6:49 AM
                          > To: antlr-interest@yahoogroups.com
                          > Subject: [antlr-interest] Re: Does -traceTreeWalker work in
                          > antlr-2.7.0
                          > ?
                          >
                          >
                          > Hi,
                          > > On Tue, May 15, 2001 at 01:12:59PM -0000, danreo1952@... wrote:
                          > > -traceParser is the best. Why can't it be in -traceTreeParser?
                          >
                          > Currently I use a kindoff 'dirty' trick to debug treeparsers.
                          > This is C++
                          > but the idea translates wel to java I guess... In every rule
                          > I use a custom
                          > error handler which prints out the input tree in the case of an error.
                          > Embedded in the trace you then get the (sub)tree the rule
                          > barfed on. Which
                          > works pretty well I must say.
                          >
                          > Maybe together with the remarks here you might use it in java mode...
                          >
                          > http://www.antlr.org/doc/sor.html#Examining_Debugging ASTs
                          >
                          > An example of a rule. (Ok this does not work yet with current
                          > available
                          > ANTLR's I fixed a bug concerning the #xxx_in ast stuff, this
                          > morning, I'll
                          > release that devel version shortly)
                          >
                          > assignment:
                          > #( "=" IDENTIFIER_AST expression )
                          > ;
                          > exception
                          > catch [antlr::RecognitionException &ex]
                          > {
                          > // tree printing class template...
                          > print_tree<RefModest_AST,TreeParser> pr(*this);
                          > pr.pr_tree(#assignment_in);
                          >
                          > // set error message in treeparser class..
                          > error_message = ex.getErrorMessage();
                          > // update status
                          > this->valid = false;
                          > }
                          >
                          > which produces output similar to:
                          >
                          > <PROCESS_DEFINITION_AST=proc_def
                          > <process IDENTIFIER=File PARAMETER_LIST_AST=params
                          > <VARIABLE_DECLARATION_AST=var_decl
                          > <TYPE_AST=int IDENTIFIER_AST=status >
                          > >
                          > <= IDENTIFIER_AST=status INT=0 >
                          > <do
                          > <:: IDENTIFIER_AST=start
                          > <{=
                          > <= IDENTIFIER_AST=status INT=1 >
                          > >
                          > >
                          > <:: IDENTIFIER_AST=communication_established
                          > <{=
                          > <= IDENTIFIER_AST=status INT=0 >
                          > >
                          > >
                          > >
                          > >
                          > >
                          > --------snip----
                          >
                          > Some might recognize this output as the one of the print_tree
                          > thing you can
                          > find on Ian Kaplan's site. I adapted it a little bit for my
                          > own debugging
                          > pleasure.
                          >
                          > http://www.bearcave.com/software/antlr/antlr_examples.html
                          >
                          > If there's interest for the template drop me a line.
                          >
                          > Ric
                        Your message has been successfully submitted and would be delivered to recipients shortly.