Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a calculator prefix expression interpreter in Prolog as described in the section on attribute grammars in this chapter. The interpreter will read an expression

Implement a calculator prefix expression interpreter in Prolog as described in the section on attribute grammars in this chapter. The interpreter will read an expression from the keyboard and print its result. The interpreter should start with a calk predicate. Here is the calk predicate to get you started.

image


The program reads a list of tokens from the keyboard. The preprocess predicate should take the list of values and add numb tags to any number it finds in the list. This makes writing the grammar a lot easier. Any number like 6 in L should be replaced by numb ((6) in the list Pregl. The expr predicate represents the start symbol of your grammar. Finally, the interpret predicate is the attribute grammar evaluation of the AST represented by Tree. To make this project easy, write it incrementally. Print the results as you go so you can see what works and what doesn’t. The print predicate will print its argument while the nl predicate will print a newline. Don’t write the entire calk predicate right away. Write one piece, test it, and then move on to the next piece.

calc :- readln (L,___, lowercase), preprocess (L, PreL), print (PreL), nl, expr (Tree, PreL, []), print (Tree), nl, interpret (Tree , 0,_, Val), print (Val), nl.

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

Step: 3

blur-text-image

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

Applied Regression Analysis And Other Multivariable Methods

Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg

5th Edition

1285051084, 978-1285963754, 128596375X, 978-1285051086

More Books

Students also viewed these Programming questions

Question

How is the Cisco Nexus Dashboard solution licensed?

Answered: 1 week ago

Question

1. Identify the domain and range of the graph. 4 -+ 2 3 7

Answered: 1 week ago