[antlr-interest] Get an iterator?
Brian Lavender
brian at brie.com
Sun Aug 22 23:05:50 PDT 2010
How do I get an iterator for the one or more? The following doesn't quite seem
to work.
grammar Agenda;
options {language='Java';}
agenda :
l1=bill+ { Iterator it = $l1.iterator() ; } ;
bill returns[String xml] :
active fiscal title author NL
subject NL NL {
$xml = "<BILL>\n";
$xml += $title.xml + "\n";
$xml += $author.xml + "\n";
$xml += $subject.xml + "\n";
$xml += "</flag type=\"active\" status=\"" + $active.text + "\">\n";
$xml += "</flag type=\"fiscal\" status=\"" + $fiscal.text + "\">\n";
$xml += "</BILL>\n";
}
;
title returns [String xml] :
fifteen {
$xml="<Title>" + $fifteen.text + "</Title>";
};
author returns [String xml] :
ten {
$xml="<Author>" + $ten.text + "</Author>";
};
subject returns [String xml] :
ten {
$xml="<Subject>" + $ten.text + "</Subject>";
};
active : FLAG;
fiscal : FLAG;
fifteen : LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR;
ten : LTR LTR LTR LTR LTR LTR LTR LTR LTR LTR;
NL : ('\n'|'\r'|'\r\n');
FLAG : ('Y'|'N');
LTR : . ;
Input to the Lexer/Parser is the following.
YYconstruct bill frank burn
Make lifez
YYeazememnt bill billy bob
roughlife
--
Brian Lavender
http://www.brie.com/brian/
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."
Professor C. A. R. Hoare
The 1980 Turing award lecture
More information about the antlr-interest
mailing list