S - Intranet - Department of Computer Science: Login
S - Intranet - Department of Computer Science: Login
S - Intranet - Department of Computer Science: Login
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Adding Actions by hand<br />
options<br />
{<br />
LOOKAHEAD=2;<br />
}<br />
PARSER_BEGIN(Calculator)<br />
public class Calculator<br />
{<br />
public static void main(String args[]) throws<br />
ParseException<br />
{<br />
Calculator parser = new<br />
Calculator(System.in);<br />
while (true)<br />
{<br />
parser.parseOneLine();<br />
}<br />
}<br />
}<br />
PARSER_END(Calculator)<br />
SKIP :<br />
{<br />
" "<br />
| "\r"<br />
| "\t"<br />
}<br />
TOKEN:<br />
{<br />
< NUMBER: ()+ ( "." ()+ ) ><br />
| < DIGIT: ["0"-"9"] ><br />
| < EOL: "\n" ><br />
}<br />
void parseOneLine():<br />
{<br />
double a;<br />
}<br />
{<br />
a=expr() { System.out.println(a); }<br />
| <br />
| { System.exit(-1); }<br />
}<br />
3