Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the grammar in Figure 1 where the terminal int denotes an integer and the terminal id AtomsE Atoms ? Atom Atoms AtomAtom AtomList Atomid

image text in transcribed

Consider the grammar in Figure 1 where the terminal int denotes an integer and the terminal id AtomsE Atoms ? Atom Atoms AtomAtom AtomList Atomid Atomint List ? ( ListBody ) ListBody ? Atoms Figure 1: A simplified grammar for Scheme denotes an identifier. The only other terminals in this grammar are the quote ', the left parenthesis (, and the right parenthesis ) Scheme, a derivative of Lisp, is a list based language where all programs are represented by lists. For example, a simple Scheme program 1 2 adds two numbers together and prints out the result. A scheme interpreter, /local/bin/scheme is available on bluenose. Feel free to give it a try. A program, which is zero or more atoms is executed by evaluating each of the atoms. An atom is either an integer, an identifier, or a list. The evaluation of an integer is the integer, and the evaluation of an identifier, for now, is simply the identifier. The evaluation of a quoted atom is simply the atom itself. E.g., the evaluation of '1 2 3 is 1 23) A list is evaluated by evaluating the first atom of the list and treating the result as a function Then each of the remaining atoms of the list is evaluated, and passed as parameters to the function. For example, the evaluation of C1 2 ), treats+ as a function, and passes 1 and 2 to the function. Applying +to 1 and 2 yields the result 3. Whereas, the evaluation of 1 2 3, evaluates + and 1 as before, but then evaluates 2 3,yielding 6, which is then passed to the + function, which yields the result of 7 CSCI3136 Summer 2018 Assignment6 1. 10 marks] As a Scheme program is being parsed, it is useful to generate a tree representation of the program, where the nodes in the tree are atoms, which can be integers, identifiers, quotes, or lists. Both quote nodes and list nodes are internal nodes, while integers and identifiers are leaf nodes. Suppose you were provided with the operations T ? leaf-node (r) which creates a leaf node and stores the identifier or integer in the node. T ? int-node() which creates a new list (internal) node T ? add(n, T) which prepends node n to the children of node T and returns T Give a synthetic attribute grammar (S-Grammar) for the grammar above that will construct

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago