CS考试代考 Python代写 linear model代写 cs考试助攻
1008CSCI 3022 Final Exam CS考试代考 Read the following: • RIGHT NOW! Write your name, student ID and section number on the top of your exam. If you’re handwriting your exam, Read the fol...
View detailsSearch the whole station
Python语言设计代写 In this assignment you will write an interpreter in Python for a simplified PostScript-like language, concentrating on key computational
In this assignment you will write an interpreter in Python for a simplified PostScript-like language, concentrating on key computational features of the abstract machine, omitting all PostScript features related to graphics, and using a somewhat-simplified syntax. The simplified language, SPS, has the following features of PostScript:
– begin requires one dictionary operand on the operand stack; end has no operands.
In Part 1 you will build some essential pieces of the interpreter but not yet the full interpreter. The pieces you build will be driven by Python test code rather than actual PostScript programs. The pieces you are going to build first are:
In our interpreter we will define the operand and dictionary stacks as attributes of the Stacks class in psbuiltins.py file. Both stacks will be represented as Python lists. When using a list as a stack, we will assume that the top of the stack is the end of the list (i.e., the pushing and popping happens at the end of the list).
The opstack will only include the evaluated values, i.e. the values that the PostScript expressions evaluate to. In the opstack:
– The primitive values (i.e., integers,booleans) are represented as Python “int” and “bool” values, respectively.
– The function and variable names will be represented as Python “str” values where the first character is ‘/’.
– String constants will be represented as StrConstant objects.
– Dictionary values will be represented as DictConstant objects.
– Code-array (i.e., function bodies, and bodies of for, if, ifelse expressions) are represented as CodeArray objects.
The dictstack will include the dictionaries where the PostScript variable and function definitions are stored. The dictionary stack needs to support adding and removing dictionaries at the top of the stack (i.e., end of the list), as well as defining and looking up names. Note that dictstack holds all the local and global variables accessible at a particular point in the program, i.e., the referencing environment.
You will write two helper functions, define and lookup, to define a variable and to lookup the values of a variable, respectively.
The define function adds the “name:value” pair to the top dictionary in the dictionary stack. Your psDef function ( i.e., your implementation of the PostScript def operator) should pop the name and value from opstack and call the “define” function.
You should keep the ‘/’ in the name constant when you store it in the dictStack.
"""Helper function. Adds name:value pair to the top dictionary in the dictstack. (Note: If the dictstack is empty, first adds an empty dictionary to the dictstack then adds the name:value to that.""" def define(self, name, value): pass
The lookup function should look-up the value of a given variable in the dictionary stack. In Part 2, when you interpret simple PostScript expressions, you will call this function for variable lookups and function calls.
"""Helper function. Searches the dictstack for a variable or function and returns its value. (Starts searching at the top of the opstack; returns None and prints an error message if name is not found. Make sure to add '/' to the beginning of the name.)""" def lookup(self,name): pass
Operators will be implemented as zero-argument Python functions that manipulate the operand and dictionary stacks. For example, the add operator could be implemented as follows.
"""Pops 2 values from opstack; checks if they are numerical (int); adds them; then pushes the result back to opstack. """ def add(self): if len(self.opstack) > 1: op1 = self.opPop() op2 = self.opPop() if isinstance(op1,int) and isinstance(op2,int): self.opPush(op1 + op2) else: print("Error: add - one of the operands is not a number value") self.opPush(op2) #push the operands back to opstack self.opPush(op1) else: print("Error: add expects 2 operands")
(Note about dict: dict takes an integer operand from the operand stack and pushes a DictConstant value (with `value` {} ) to the operand stack (affects only the operand stack). The initial size argument is ignored ʹPostScript requires this argument for backward compatibility of dict operator with the early PostScript versions). Python语言设计代写
Important Note: For all operators you need to implement basic checks, i.e., check whether there are sufficient number of values in the operand stack and check whether those values have correct types.
For example,
Also, see the add implementation on page 3. You will be deducted points if you don’t do error checking.
We will be using the unittest Python testing framework in this assignment. See
https://docs.python.org/3/library/unittest.html for additional documentation.
The file tests_part1.py provides sample test cases for the SPS operators. This file imports the Stacks class (psbuiltins.py file) which will include your implementations of the SPS operators.
You don’t need to provide new tests in this assingment.
In Python unittest framework, each test function has a “test_” prefix. To run all tests,execute the following command on the command line.
python -m unittest tests_part1.py
You can run tests with more detail (higher verbosity) by passing in the -v flag:
python -m unittest -v tests_part1.py
更多代写:Python代考推荐 Team Viewer作弊 英国Project网课代管 short essay代写 Semester Paper 代写 dissertation代写
合作平台:essay代写 论文代写 写手招聘 英国留学生代写
CSCI 3022 Final Exam CS考试代考 Read the following: • RIGHT NOW! Write your name, student ID and section number on the top of your exam. If you’re handwriting your exam, Read the fol...
View detailsProgramming assignment #3: eigenvalues 数值分析课业代写 Problem 1. Program the power method and inverse power method to compute the maximum and minimum eigenvalue/eigenvector pairs of the symme...
View detailsVolatility Forecasting Homework 波动率预测代写 1.You will estimate the parameters of a few GARCH-type models using about ten years of data (from Jan 1, 2013 to Nov 30, 2022) for SPY 1. ...
View detailsCS579/ECE599 Assignment Homework 1 物理攻击与对策代写 Please complete this assignment (100 pts total) and submit your report/program code on Canvas (all files compressed in one .zip witho...
View details