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

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 expression as input, the parser will parse the expression, producing as a result the sequence of prductions applied. In addition, the parser will interpret the expression during the predictive parse computing the expression value.The LL(1) grammar for arithmetic expressions with operators-and*is as follows: 0.startexpr

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

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 Programming Questions!