Question: here is the template for the JLex file: / / transform the following to A 3 . lex import java _ cup.runtime. * ; %

here is the template for the JLex file: //transform the following to A3.lex
import java_cup.runtime.*;
%%
%implements java_cup.runtime.Scanner
%type Symbol
%function next_token
%class CalcScanner
%eofval{ return null;
%eofval}
IDENTIFIER =[a-zA-Z_][a-zA-Z0-9_]*
NUMBER =[0-9]+
%%
"+"{ return new Symbol(CalcSymbol.PLUS); }
"-"{ return new Symbol(CalcSymbol.MINUS); }
"*"{ return new Symbol(CalcSymbol.TIMES); }
"/"{ return new Symbol(CalcSymbol.DIVIDE); }
{NUMBER}{ return new Symbol(CalcSymbol.N UMBER, new Integer(yytext()));}
\r|
{}
.{} here is the starting template for javaCup specification: import java.io.*;
/* Terminals (tokens returned by the scanner).*/
terminal PLUS, MINUS, TIMES, DIVIDE, LPAREN, RPAREN;
terminal Integer NUMBER;
/* Non terminals */
non terminal Integer expr;
/* Precedences */
precedence left PLUS, MINUS;
precedence left TIMES, DIVIDE;
/* The rules */
expr ::= expr:e1 PLUS expr:e2{: RESULT = new Integer(e1.intValue()+ e2.intValue());
:}
| expr:e1 MINUS expr:e2{: RESULT = new Integer(e1.intValue()- e2.intValue());
:}
| expr:e1 TIMES expr:e2{: RESULT = new Integer(e1.intValue()* e2.intValue());
:}
| expr:e1 DIVIDE expr:e2{: RESULT = new Integer(e1.intValue()/ e2.intValue());
:}
| LPAREN expr:e RPAREN {: RESULT = e;
:}
| NUMBER:e {: RESULT= e; :}
;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!