Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

11.2 Problem Set 2: PostScript Stack Commands (in python please) For this assignment you are to implement a PostScript command interpreter using a Stack. You

11.2 Problem Set 2: PostScript Stack Commands (in python please)

For this assignment you are to implement a PostScript command interpreter using a Stack. You must implement the stack using a singly-linked list. Solutions that use a data structure other than a singly-linked list will received no credit. The interpreter must read and execute a string of PostScript commands based on the following definitions: 1. = objn objn-1 obj1 = : objn-1 obj1 This command removes the topmost object form the stack and prints it.

  1. count objn obj1count : [depth of the stack] objn obj1 This command puts the depth of the stack on the top of the stack.
  2. clear objn obj1clear : [empty stack] This command removes all objects from the stack.
  3. dup objn obj1 = : objn objn obj1 This command adds a duplicate copy of the top object to the stack .
  4. exch objn objn-1 obj1 exch : objn-1 objn obj1 This command exchanges the position of the top two elements of the stack.
  5. index objn obj1 a index : objn obja obj1 This command adds a copy of the ath object to the top the stack.
  6. pop objn objn-1 obj1 pop : objn-1 . obj1 This command removes the top element from the stack.
  7. stack This command prints a copy of the entire stack, starting from the top and working to the bottom.. The input will be a series of data and commands separated by a space. The data will go onto the stack. Commands do not go onto the stack. You must write at least one separate method for each of the commands. You may reuse the standard Stack methods discussed in class: push(), pop(), peek() and is_empty(). A template file has been provided.

class Node():

def __init__(self, value): pass

class PostScript():

def __init__(self): pass def push(self, value): pass def pop(self): pass def peek(self): pass def is_empty(self): pass

def stack(self): pass def exch(self): pass def index(self): pass def clear(self): pass def dup(self): pass def equal(self): pass def depth(self): pass stack = PostScript()

def decode(command_list): for object in command_list: if object == '=': stack.equal() elif object == 'count': stack.depth() elif object == 'clear': stack.clear() elif object == 'dup': stack.dup() elif object == 'exch': stack.exch() elif object == 'index': stack.index() elif object == 'pop': stack.pop() elif object == 'stack': stack.stack() else: stack.push(object)

command = input() command_list = command.split() decode(command_list)

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is a financial feasibility analysis?

Answered: 1 week ago

Question

=+j Enabling a productive global workforce.

Answered: 1 week ago

Question

=+ Are you interested in creating or

Answered: 1 week ago

Question

=+working on a micro-multinational?

Answered: 1 week ago