antlr3 - Making some parser rules case-insensitive in antlr -


i wrting small csharp console application reads text console, some manipulations , returns string. this, using antlr. grammar file shown below.

 grammar test; options { language = csharp2; output = ast; } start returns [string res]: expression eof { $res=$expression.res; } ; expression returns [string res] : identifier {$res=$identifier.text} |num {$res=$num.text; |function {$res=function.res} ; function: 'left' '( identifier ')'{some code here} | 'right' '( identifier ')'{some code here} |.......... ; num : (minus)?('0'..'9')+ ; identifier : ('a'..'z'|'a'..'z'|'\\'|'/'|'_'|':'|';'|'?'|'.'|'0'..'9')('a'..'z'|'a'..'z'|'\\'|'/'|'_'|':'|';'|'.'|'?'|'0'..'9')*; 

i have several such functions string manipulations. now, want antlr identify these function names irrespective of case. @ present, accepts lower case letters function names like.. upper(asdf). cannot convert every token lower case in application changes case of identifiers also. how can achieve ?

simply define appropriate token. so, code above:

function : left '(' identifier ')' {some code here} | .......... ; left : ('l'|'l')('e'|'e')('f'|'f')('t'|'t'); 

or, if sure want have cases left:

function : left '(' identifier ')' {some code here} | .......... ; left : ('left'|'left'); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -