Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

How many distinct ways can the word DEADWOOD be arranged?

Answered: 1 week ago