How can I allow single-line comments with EOF on the end instead of a newline?

Terence Parr

Here is a simple example that works for me.

class CL extends Lexer;

options {
    charVocabulary = 'u0000'..'u007f';
}

{
    public static void main(String[] args) throws Exception {
        CL lexer = new CL(System.in);
        Token t = lexer.nextToken();
        System.out.println("Token: "+t);
        while ( t.getType()!=Token.EOF_TYPE ) {
            System.out.println("Token: "+t);
            t = lexer.nextToken();
        }
    }
}

ID : ( 'a'..'z')+;
WS : ' ' | '
' ;
CMT : "//" (~'
')* ('
')? ;
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact