[antlr-interest] Stopping *

Edward Povazan epovazan at telus.net
Tue Jun 17 19:58:53 PDT 2003


Hello,

I need to parse simple 'function call' type expressions of the form
func(params, keywordparams), examples are
fncall()
fncall(a, b)
fncall(a, b, c=1, d=2)
fncall(c=1, d=2)

fncall(a, c=1, b, d=2) is NOT allowed. And this is where my problem is.
How do I break out of the simply parameter list and into the keyword
parameter list. I keep consuming the comma, and I haven't figured out the
right way to do it. I am hoping there is a simple trick.

The culpit is in the param_list rule - I need a 'stop matching if IDENT
ASSIGN and start matching the kwparam_list rule instead'. How do I use
something like a syntactic predicate (IDENT ASSIGN) => ??? to say 'don't
match anymore' ?

Thanks
-Ed

sigcall: ident LPAREN (arg_list)? RPAREN ;
arg_list: (ident ASSIGN) => kwparam_list | param_list (kwparam_list)? ;
param: (ident LPAREN) => sigcall | ident | number | STRING;
param_list: param (COMMA param)*;
kwparam: ident ASSIGN value;
kwparam_list: kwparam (COMMA kwparam)*;
value: param;
number: INT | REAL;
ident: IDENT;

class SigCallLexer extends Lexer;
options {
    charVocabulary = '\0'..'\377';
    k = 2;
}

LPAREN: '(' ;
RPAREN: ')' ;
COMMA: ',' ;
ASSIGN: '=' ;
IDENT : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*  ;
STRING: '"' ( ~'"' )* '"';
WS: (' ' | '\t' | '\f' | '\n' | "\r\n" | '\r' )
 { $setType(Token.SKIP); } ;
protected
DOT: '.' ;
protected
DIGIT: ('0'..'9') ;
INT { boolean isDecimal=false; } :
 DOT (DIGIT)+ { _ttype = REAL; }
 | (DIGIT)+ { isDecimal = true; } ( {isDecimal}? DOT (DIGIT)* {_ttype =
REAL; } )? ;



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list