[antlr-interest] Fwd: need help with predicates
Alexandre Porcelli
porcelli at uol.com.br
Thu Aug 9 09:39:03 PDT 2007
Hi Andy and All..
As you are working with visual basic... I think you could create
something like it:
expression //just for this sample
: data_reference
| LITERAL
;
data_reference
: IDENTIFIER
| IDENTIFIER '!' IDENTIFIER
| IDENTIFIER '!' '[' expression ']'
| IDENTIFIER '(' expression ')'
;
LITERAL //With scape logic
: '"'
{
if (input.LA(1) == '"' && input.LA(2) == '"'){
matchAny();
matchAny();
}
}
(options {greedy=false;} : .
{
if (input.LA(1) == '"' && input.LA(2) == '"'){
matchAny();
matchAny();
}
}
)* '"'
;
IDENTIFIER
: LETTER (LETTER|DIGIT|'_')* DATA_TYPE?
;
fragment
DATA_TYPE
: '%'|'#'|'$'|'&'|'@'
;
fragment
LETTER
: 'a'..'z' | '\u0080'..'\ufffe'
;
fragment
DIGIT
: '0'..'9'
;
wdyt?
Best Regards,
Alexandre Porcelli
On 8/9/07, Richard Clark <rdclark at gmail.com> wrote:
> The usual answer to dealing with context-dependant elements is to move
> the decision from the lexer into the parser.
>
> You might do this:
>
> identifier: (ID_FRAGMENT '!' ID_FRAGMENT) => ID_FRAGMENT '!' ID_FRAGMENT
> | ID_FRAGMENT
> /* You still have to deal with the other suffixes */
> ;
>
> ID_FRAGMENT: LETTER (LETTER| DECIMAL_LITERAL)* ;
>
> ...Richard
>
More information about the antlr-interest
mailing list