Question: AST File Grammar File Printer File Evaluator Other Files in the project Interpreter Value Reader 4. (10 pt) (Arithlang interpreter basics) Extend ArithLang to support

AST File


Grammar File


Printer File

Evaluator

Other Files in the project
Interpreter

Value

Reader

4. (10 pt) (Arithlang interpreter basics) Extend ArithLang to support a new expression greatest-of (>? a b) for positive numbers, e.g., $ >? 3) 3 $ >? 3 4 2) 4 $ (>? 83) 8 $ >? 8-1) error $ (>?-1) error You will need to modify the following files: (2 pt) Grammar file (ArithLang.g) (2 pt) AST file (AST.java) . (1 pt) Printer file (Printer.java) (5 pt) Evaluator (Evaluator.java) + * 1 package arithlang; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 /** 7 * This class hierarchy represents expressions in the abstract syntax tree 8 * manipulated by this interpreter. 9 10 * @author hridesh 11 12 13 @SuppressWarnings ("rawtypes") 14 public interface AST { 15 public static abstract class ASTNode { 16 public abstract Object accept (Visitor visitor); 17 } 18 public static class Program extends ASTNode 19 Exp_e; 20 21 public Program (Expe) { 22 Le = e; 23 } 24 25 public Exp e() { 26 return _e; 27 } 28 29 public Object accept (Visitor visitor) { 30 return visitor.visit(this); 31 } 32 } 33 public static abstract class Exp extends ASTNode { 34 35 } 36 37 public static class NumExp extends Exp { 38 39 double val; 39 40 public NumExp (double v) { 41 _val = v; 42 } 43 44 public double v() { 45 return val; 46 } 47 48 public Object accept (Visitor visitor) { 49 return visitor.visit(this); 50 } 51 } 52 53 public static abstract class CompoundArithExp extends Exp { 54 List
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
