posts - 18,  comments - 0,  trackbacks - 0

class L extends Lexer;

options {
 k=5;
 charVocabulary = '\u0000' .. '\uFFFE';
 testLiterals=false;
 caseSensitive = false;
 caseSensitiveLiterals = true;
}

ONE_ARG_OP
 : '~';
TWO_ARG_OP
 : '&' | '|' | '^' | '+' | '-' | '/' | '%'; 
STAR
 : '*';
COMPARE_OP
 : '>' | '<' | ">=" | "<=" | "!=" | "<>" | "=";
NOT_EXIST:
 "not exist";
EXIST:
 "exist";
COMMA
 : ',';
SEMI: ';';
POINT
 : '.';
LPAREN
 : '(';
RPAREN
 : ')';

PARAM_LPAREN
 : '{';

PARAM_RPAREN
 : '}';


COLUMN
 : "column";
WHERE
 : "where";

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

QUOTED_STRING
 : ('"'|'\'') (ESC|~('\''|'"'|'\\'|'\n'|'\r'))* ('"'|'\'')
 ;
protected
ESC
 : '\\'
  ( 'n'
  | 'r'
  | 't'
  | 'b'
  | 'f'
  | '"'
  | '\''
  | '\\'
  | '0'..'3'
   (
    options {
     warnWhenFollowAmbig = false;
    }
   : '0'..'7'
    (
     options {
      warnWhenFollowAmbig = false;
     }
    : '0'..'7'
    )?
   )?
  | '4'..'7'
   (
    options {
     warnWhenFollowAmbig = false;
    }
   : '0'..'7'
   )?
  )
 ;

PARAM_ID
 : PARAM_LPAREN ID PARAM_RPAREN
 ;

ID options {testLiterals=true;}
 : ID_START_LETTER ( ID_LETTER )*;

protected
ID_START_LETTER
    :    'a'..'z'
    | '_'
    |    '\u0080'..'\ufffe'
    ;
protected
ID_LETTER
    : ID_START_LETTER
    | '0'..'9'
    | '/'
    ;

REAL_NUM
 : NUM (POINT DOT_NUM)?
 ;
protected
NUM : '0'
 | NUM_START (NUM_LETTER)*
 ;
protected
DOT_NUM
 : (NUM_LETTER)+
 ;
protected
NUM_START
 : '1'..'9'
 ;
protected
NUM_LETTER
 : '0'..'9'
 ;

ML_COMMENT
 : "/*"
  ( /* '\r' '\n' can be matched in one alternative or by matching
    '\r' in one iteration and '\n' in another.  I am trying to
    handle any flavor of newline that comes in, but the language
    that allows both "\r\n" and "\r" and "\n" to all be valid
    newline is ambiguous.  Consequently, the resulting grammar
    must be ambiguous.  I'm shutting this warning off.
    */
   options {
    generateAmbigWarnings=false;
   }
  :
   { LA(2)!='/' }? '*'
  | '\r' '\n'  {newline();}
  | '\r'   {newline();}
  | '\n'   {newline();}
  | ~('*'|'\n'|'\r')
  )*
  "*/"
  {$setType(Token.SKIP);}
 ;

posted on 2007-04-03 17:59 LORD BLOG 阅读(391) 评论(0)  编辑  收藏 所属分类: 项目笔记

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


网站导航: