VIRGIN FOREST OF JAVA
不要埋头苦干,要学习,学习,再学习。。。。。
powered by R.Zeus


header
{
//   $Id: hql.g 8805 2005-12-09 12:22:18Z pgmjsd $

package test;


}

class Pascal extends Parser;

prog:   INT
           EOF
            { System.out.println("plain old INT"); }
       
    |   REAL { System.out.println("token REAL"); }
    |RANGE { System.out.println("token RANGE");}
    |MORERANGE{ System.out.println("token MORERANGE");}
    ;

class LexPascal extends Lexer;

WS  :   (' '
    |   '\t'
    |   '\n'
    |   '\r')+
        { $setType(Token.SKIP); }
    ;

protected
INT :   ('0'..'9')+
    ;

protected
REAL:   INT '.' INT
    ;
protected
RANGE
    :   INT ".." INT
    ;
protected
MORERANGE
 :INT "..."  INT;
 
RANGE_OR_INT
    :( INT "..." ) => MORERANGE  { $setType(MORERANGE); }  
    |( INT ".." ) => RANGE  { $setType(RANGE); }
    |   ( INT '.' )  => REAL { $setType(REAL); }
    |   INT                  { $setType(INT); }
    ;   


use protected and '=>' to distinguish all the tokens that has the common lift-prefixes.is there other ways?
see What is a "protected" lexer rule?
posted on 2006-09-06 16:53 R.Zeus 阅读(395) 评论(0)  编辑  收藏 所属分类: ANTLR

只有注册用户登录后才能发表评论。


网站导航: