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 Alex
import javacup.runtime.;
implements javacup.runtime.Scanner
type Symbol
function nexttoken
class CalcScanner
eofval return null;
eofval
IDENTIFIER azAZazAZ
NUMBER
return new SymbolCalcSymbolPLUS;
return new SymbolCalcSymbolMINUS;
return new SymbolCalcSymbolTIMES;
return new SymbolCalcSymbolDIVIDE;
NUMBER return new SymbolCalcSymbolN UMBER, new Integeryytext;
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:e PLUS expr:e: RESULT new IntegereintValue eintValue;
:
expr:e MINUS expr:e: RESULT new IntegereintValue eintValue;
:
expr:e TIMES expr:e: RESULT new IntegereintValue eintValue;
:
expr:e DIVIDE expr:e: RESULT new IntegereintValue eintValue;
:
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
