[antlr-interest] How to write this lexer rule?
chain one
chainone at gmail.com
Tue Jan 13 01:10:54 PST 2009
I want to recognize a function definition and skip it before passing tokens
to the parser.The function definition starts with "FUNCTION" ,ends with
"END_FUNCTION".
Also it could be nested,for example:
FUNCTION value_range_aggregate_rep_item(agg
: AGGREGATE OF representation_item) : BOOLEAN;
FUNCTION cri(agg : AGGREGATE OF representation_item) : BOOLEAN;
BEGIN
IF (SIZEOF(agg) = 3)
AND
(SIZEOF(QUERY(i1 <* agg | ('AUTOMOTIVE_DESIGN.' +
'MEASURE_REPRESENTATION_ITEM' IN TYPEOF(i1)))) = 3)
THEN
RETURN (TRUE);
ELSE
RETURN (FALSE);
END_IF;
END;
END_FUNCTION;
BEGIN
IF ((SIZEOF(agg) = 3)
AND (SIZEOF(QUERY(i <* agg | (
'AUTOMOTIVE_DESIGN.' +
'COMPOUND_REPRESENTATION_ITEM' IN TYPEOF(i))
AND cri(i\compound_representation_item.item_element))) = 1))
THEN
RETURN (TRUE);
ELSE
RETURN (FALSE);
END_IF;
END;
END_FUNCTION;
How to write this lexer rule?
I tried, but failed. Check the following wrong lexer rule I wrote:
FUNCTION_DECL
: 'FUNCTION'
{
$channel=HIDDEN;
}
( options {greedy=false;} : . )* FUNCTION_DECL ( options
{greedy=false;} : . )* 'END_FUNCTION' SEMI
;
I couldn't get it complied with no error.
Could anyone help me with this?
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090113/3b41d172/attachment.html
More information about the antlr-interest
mailing list