[antlr-interest] throwing exception with antlr

Ilinca Denisa FRECUS lilincutzy at yahoo.com
Wed Jun 8 06:22:52 PDT 2005


Hello,

I have the following problem when trying to make a
lexer that recognizes only characters or digits: when
it encounters something else, it exits of the code but
doesn't say anything. I would like, for example, to
print a message each time that this protocole is not
matched. Here is my code. Do you have any ideas why it
does't do what I want?
Thank you very much.

Ilinca FRECUS

class SimpleLexer extends Lexer;

options {k=1; filter=false; }

ALPHA : ('a'..'z'|'A'..'Z')+
{System.out.println("Found alpha: "+getText()); }
;

NUMERIC : ('0'..'9')+
{System.out.println("Found numeric: "+getText()); }
;


NEWLINE : ("\r\n")
	{newline();
	$setType(Token.SKIP);
	};

EXIT: {System.exit(0); };



import java.io.*;

public class Main{
	public static void main(String []args){
		SimpleLexer simpleLexer=new SimpleLexer(System.in);
		while(true)  {
			try{
			   simpleLexer.nextToken();
			}catch (Exception e){System.out.println("not
existant token");}
		}
	}
}


		
__________________________________ 
Discover Yahoo! 
Use Yahoo! to plan a weekend, have fun online and more. Check it out! 
http://discover.yahoo.com/


More information about the antlr-interest mailing list