[antlr-interest] Grammar Problem

johnclarke72 johnclarke at hotmail.com
Tue Apr 16 11:10:31 PDT 2002


I am having some problems with an ANTLR grammer that I wrote.  

Basically when I compile the grammar I get the following warning 
message :

warning: lexical nondeterminism between rules STARTTAG and ENDTAG upon
teeny.g:0:      k==1:'<'

When I run my final Java Application and enter :
<i>This is a test</i>

I get the following :

STARTTAG : <i>
TEXT : This
TEXT : is
TEXT : a
TEXT : test
exception: antlr.TokenStreamRecognitionException: unexpected char: /

How can I resolve this error ?  I would be gratefull for all adviced 
offered.  The grammar and Java code have been added to this message.

Thanks in advance

John

The Grammar :
=============

class TeenyLexer extends Lexer;

STARTTAG : "<" ( 'a'..'z' | 'A'..'Z' )+ ">";
ENDTAG   : "</" ( 'a'..'z' | 'A'..'Z' )+ ">";
WORD     : ( 'a'..'z' | 'A'..'Z' | '0'..'9' )+;

// whitespace
WS      :       (       ' '
                |       '\t'
		|	'\r' '\n' { newline(); }
		|	'\n' { newline(); }
		)
		{$setType(Token.SKIP);}	//ignore this token
	;


class TeenyParser extends Parser;

startProcessing :
(
   text:WORD
   {System.out.println("TEXT : "+text.getText());}
   | startTag:STARTTAG
   {System.out.println("STARTTAG : "+startTag.getText());}
   | endTag:ENDTAG
   {System.out.println("ENDTAG : "+endTag.getText());}
)+;

The Java App :
==============

import java.io.*;
import antlr.*;


class TeenyParserApp
{

   public static void main(String[] args)
   {
      try
      {
         TeenyLexer lexer = new TeenyLexer(new DataInputStream
(System.in));
         TokenBuffer buffer = new TokenBuffer(lexer);
         TeenyParser parser = new TeenyParser(buffer);
         parser.startProcessing();
      } catch(Exception e)
        {
          System.err.println("exception: "+e);
        }
    }
}





 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list