Question
Write a generic table-driven predictive parser in Prolog. The parser will be instantiated with the LL(1) grammar for arithmetic expressions with operators-(minus) and*(times). Given an
1.exprterm term_tail
2.term_tail-term term_tail
3.term_tail
4.termnumfactor_tail
5.factor_tail* numfactor_tail
6.factor_tail
a. Write 'transform' whichtranslates a token stream into the generic representation.
eg transform([4,-,15],R).
R = [term(num,4),term(minus,_),term(num,15)].
b.Write parseLL(R,ProdSeq) which takes a transformed list R and produces the production sequence the predictive parser applies.
eg transform([3,-,5],R),parseLL(R,ProdSeq).
ProdSeq = [0, 1, 4, 6, 2, 4, 6, 3].
c.Write Solve, which augments parseLL with computation. eg., transform([3,-,5],R),Solve(R,ProdSeq,V). ProdSeq = [0, 1, 4, 6, 2, 4, 6, 3], V = -2.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started