Question: Consider the following grammar for applied Lambda expressions: :: = | + | - | * | /

Consider the following grammar for applied Lambda expressions:
::=|"+"|"-"|"*"|"/"|"%"// constants
|// variable
|"("*")"// application
|"(""L"+"."+")"// abstraction
Implement the following:
Write a JJTree specification Prog2.jjt to generate the AST for any applied Lambda expression.
Implement the method String astToString() to convert the AST of a Lambda expression into its concrete syntax form.
Implement the method Set FV() to find the set of free variables of a Lambda expression AST.
Implement the method void dumpFV() to dump a Lambda expression AST with free variables.
Implement the method SimpleNode substitute(String var, SimpleNode expr) for substituting all the free occurrences of the variable var with a copy of the Lambda expression AST expr in this Lambda expresson AST.
Implement the method SimpleNode normalOrderEvaluate() for performing a normal order evaluation of this Lambda expression.
Create a tar file named Prog2.tar from your program files for this assignment and submit it by the due date through Canvas.
Here is a sample execution for the main part:
[hs15@zeus Prog2]$ java Prog2
>>> Lambda Expression Evaluator
Enter an applied Lambda expression:
((L f x1. f (f x1))(L n .*2(- n 1))3)
The abstract syntax tree:
appl
appl
lamb
f
lamb
x1
appl
f
appl
f
x1
lamb
n
appl
appl
mul
2
appl
appl
sub
n
1
3
The Lambda expression in the concrete syntax:
(((L f .(L x1.(f (f x1))))(L n .((*2)((- n)1))))3)
The abstract syntax tree with free variables:
appl []
appl []
lamb []
f [f]
lamb [f]
x1[x1]
appl [f, x1]
f [f]
appl [f, x1]
f [f]
x1[x1]
lamb []
n [n]
appl [n]
appl []
mul []
2[]
appl [n]
appl [n]
sub []
n [n]
1[]
3[]
Enter an applied Lambda expression:
(L x1. f (f x1))
The abstract syntax tree:
lamb
x1
appl
f
appl
f
x1
Enter the variable to be substituted:
f
Enter the substituting applied Lambda expression:
(L n .*2(- n 1))
The abstract syntax tree:
lamb
n
appl
appl
mul
2
appl
appl
sub
n
1
The substitution result:
lamb
x1
appl
lamb
n
appl
appl
mul
2
appl
appl
sub
n
1
appl
lamb
n
appl
appl
mul
2
appl
appl
sub
n
1
x1
Enter an applied Lambda expression:
((L f x1. f (f x1))(L n .*2(- n 1))3)
The normal order evaluation result:
6
give next code and files of classes i need to create and changes to be made to those files im doing project in eclipse soo kindly give accordingly and ive removed simplenode.java methods in prog2.jjt file as i got errors soo give me code for rest of evaluation methods and prog2.java (main)code also im attaching screenshots of warnings and the files generated by .jjt thank you i have already done until jjtree but next part im getting error at parsing soo can u give code for rest of the project Java Compiler Compiler Version 7.0.12(Parser Generator)
(type "javacc" with no arguments for help)
Reading from file Prog 2.jj...
Warning: Choice conflict involving two expansions at
line 39, column 4 and line 39, column 36 respectively.
A common prefix is: "(""("
Consider using a lookahead of 3 or more for earlier expansion.
Warning: Choice conflict involving two expansions at
line 39, column 20 and line 39, column 36 respectively.
A common prefix is: "("
Consider using a lookahead of 2 for earlier expansion.
File "TokenMgrError.java" does not exist. Will create one.
File "ParseException.java" does not exist. Will create one.|
File "Token.java" does not exist. Will create one.
File "SimpleCharStream.java" does not exist. Will create one.
Parser generated with 0 errors and 2 warnings. Prog 9

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!