[antlr-interest] (newbie) Unsolved lexer problem

向秦贤 fyaoxy at gmail.com
Thu Aug 16 18:25:51 PDT 2007


Hi, from string literal  view your english seem no problem, but I not sure I
so clear get you meaning:)
I newbie antlr too, :) In my practice , I used to check grammar with
interpreter first, then debug it. now can be gunit it. more convene(e18n
style:))
if more tokens, I would add fragment limiter, else I let it be.
try try this.

grammar Crazy;

textInTextSymbol:Text ;

name    :NAME;

b26      :'('INT ',' INT ')';


INT      :Decimaldigit+;


NAME: Word ( '_' Word )*;


Text     :(AlphaNumeric|Special|Space|'\'')*;


Word:  '.'* AlphaNumeric+ '.'* ;

Space :' ';

AlphaNumeric :(Uppercase|National|Lowercase);

National     :'#'|'@'|'"'|'$'|'['|']'|'{'|'}'|'^'|'~' ;

CharacterString :'\'' ( options{greedy=false;}: (~('\''|'\r'|'\n')| '\''
'\''))* '\'';

Lowercase       :'a'..'z' ;

Uppercase       :'A'..'Z' ;

Apostrophe   :'\'';
Decimaldigit:'0'..'9';

Special
:('+'|'-'|'!'|'>'|';'|'('|')'|'<'|'='|':'|'?'|'&'|'%'|'.'|'_'|',')+;


NEWLINE:'\r' ? '\n' {skip();};

WS : (' ' |'\t' |'\n' |'\r' )+ {skip();} ;

2007/8/17, ali azimi <aliaazimi at yahoo.com>:
>
> Hi,
>
> Thank you so much for any help you might give me. I have a long grammar
> and tree walker which work fine. However I have some problems at lexer level
> which I have not managed to solve for ages.
>
> The grammar at the bottom of this page, is a small part of the grammar
> which I have written. When debugging:
>
> 1) If I give a pair of digit in the form of (x,y), I receive a mismatched
> error. So I need to remove Decimaldigit from Alphanumeric ( which I don't
> want to). If I remove it, and  give the input (x,y) where x or y or both
> of them are a single digit, It gives me mismatched error.
>
> 2) Rule textinTextSymbol give me mismatched error with any text at any
> time.
>
> Could you please help me?
>
> 1) I need my grammar to match (x,y) where x and y are integers which start
> from 0.
> 2)I need my grammar to match texts.
> 3)I need my grammar to match names.
>
> I appreciate so much.
>
> Best regards,
>
> Al
>
>
>
> grammar Crazy;
>
> textInTextSymbol:Text ;
>
> name    :NAME;
>
> b26      :'('INT ',' INT ')';
>
> Decimaldigit:'0'..'9';
>
> INT      :Decimaldigit+;
>
> NAME: Word ( '_' Word )*;
>
> fragment Special      :('+'|'-'|'!'|'>'|';'|'('|')'|'<'|'='|':'|'?'|'&'|'%'|'.'|'_'|',')+;
>
>
> fragment Word:  '.'* AlphaNumeric+ '.'* ;
>
> Text     :(AlphaNumeric|Special|'.'|'_'|Space|'\'')*;
>
> fragment Space :' ';
>
> fragment AlphaNumeric :(Uppercase|National|Lowercase|Decimaldigit);
>
> fragment National     :'#'|'@'|'"'|'$'|'['|']'|'{'|'}'|'^'|'~' ;
>
> fragment CharacterString :'\'' ( options{greedy=false;}:
> (~('\''|'\r'|'\n')| '\'' '\''))* '\'';
>
> fragment Lowercase       :'a'..'z' ;
>
> fragment Uppercase       :'A'..'Z' ;
>
> fragment  Apostrophe   :'\'';
>
> fragment NEWLINE:'\r' ? '\n' {skip();};
>
> WS : (' ' |'\t' |'\n' |'\r' )+ {skip();} ;
>
>
>
>
> ------------------------------
> Ready for the edge of your seat? Check out tonight's top picks<http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/>on Yahoo! TV.
>
>


-- 
致敬
向秦贤
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070817/7988f093/attachment.html 


More information about the antlr-interest mailing list