文法に基づいて AST ツリーから type フィールドと text フィールドを出力すると、これが得られます
type=5 text=and
type=14 text==
type=4 text=ALIAS
type=20 text=a
type=7 text=ATTR_NAME
type=20 text=column_b
type=36 text=STR_VAL
type=35 text="asdfds"
type=14 text==
type=4 text=ALIAS
type=20 text=a
type=7 text=ATTR_NAME
type=20 text=yyyy
type=12 text=DEC_VAL
type=11 text=564.555
生成されたレクサーの有効な型 int は次のとおりです。
public static final int EOF=-1;
public static final int ALIAS=4;
public static final int AND=5;
public static final int ATTR_NAME=7;
public static final int DECIMAL=11;
public static final int DEC_VAL=12;
public static final int EQ=14;
public static final int ID=20;
public static final int STR_VAL=36;
ツリーに type=20 を入れたくない!!! 代わりに、タイプ 20 のノードを 1 レベル上に移動して、テキストが情報 (トークン名ではない) になり、タイプが 4、7、または ALIAS または ATTR_NAME タイプになるようにします。これを行う方法はありますか?
私の現在の文法のこの部分は、現在のように架空のトークン ATTR_NAME と ALIAS を使用しています (文法をさらに追加する必要がある場合はコメントしてください。ただし、これで十分だと思います)
primaryExpr
: compExpr
| inExpr
| parameterExpr
| attribute
;
parameterExpr
: attribute (EQ | NE | GT | LT | GE | LE)^ parameter
| aliasdAttribute (EQ | NE | GT | LT | GE | LE)^parameter
;
compExpr
: attribute (EQ | NE | GT | LT | GE | LE)^ value
| aliasdAttribute(EQ | NE | GT | LT | GE | LE)^value
;
alias
: ID
;
inExpr : attribute IN^ valueList
;
attribute: ID -> ^(ATTR_NAME ID);
aliasdAttribute
: alias(DOT)(ID) -> ^(ALIAS alias ) ^(ATTR_NAME ID)
;