c++ assignment

I need to read code from the python file and then determine variable type using c++ program.

b = []
def setVal():
a = “string”
b = [1, 2, 3]
return
a = 3

Don't use plagiarized sources. Get Your Custom Essay on
c++ assignment
Just from $13/Page
Order Essay

a: int
b:

COSC4315/COSC6345: Determining Data Types in a Dynamic
Language

1 Introduction

Python is interpreted. Here we will take the other route. You will create a ”compiler” program to determine
or infer the data type of each variable. The input source code will be: Python. This “compiler”-style program
will be developed in C++. The output will be a list of variables with their data types, unless the data type
cannot be determined. This list should be alphabetically sorted.

Your program will use regular expression to recognize identifiers, numbers and strings. Your program
will use a simplified context-free grammar to recognize arithmetic expressions with ’+’. In order to detect
data types you will have to perform a partial evaluation using an attribute grammar to extend the parse tree.
Your program does not have to generate intermediate or object code, but this will be required in a future
homework.

The data types in Python will be: bool, int, str, list, . Notice it is not necessary to treat them as
objects.

2 Input

The input is one source code file. The programs will contain the following statements: assignment with
arithmetic expressions, function calls, if/else and while statements, function definitions with up to 2 argu-
ments (like the HW on artimetic operators). The main arithmetic operators will be the ’+’ and ’*’ operator.
The variables can be numbers, strings or lists. In the case of numbers + means addition, for strings it means
concatenation and for lists union. Notice ’*’ is not available for strings or lists; we will ignore Python’s
string repetition. The if condition will be one comparison (no and/or).

You can assume the program will be syntactically correct: detecting syntax errors will be tackled in a
future assignment. You can assume the input source code has no class definitions, no advanced library calls
(e.g. Pandas), and no recursive functions. You can assume there will be no function calls to convert data
types (casting). You can assume lists will not mix data types.

3 Program and output specification

The main program should be called ”gettype.cpp”.
Your program will be compiled:

g++ gettype.cpp -o ˜/bin/gettype

Call syntax from the OS prompt (rename a.out!):

# if in PATH or ˜/bin
gettype file=program1.py

# default
./gettype file=program1.py

3.1 Input and Output:

You will be given a python program as your input file (program1.py).
Your output should be a list of all variables alphabetically sorted with each variable, a colon and its data

type. Do not include any other information.
Example of output:

a: int
c:
cond: bool
l1: list
s: str

4 Requirements

• You should store all the identifiers in some efficient data structure (search time time O(1) or O(log(n))).
These include variable and function identifiers.

• The arithmetic expressions can have up to 8 operands combining + * () and function calls.

• The input is one .py file and it is self-contained (this file will not import other py files).

• You do not have to evaluate any python statement throughout the program. The goal of the homework
is to determine data types.

• In Python a list can mix data types, but in this homework we will take a stricter approach by displaying
a warning when at least one element in the list has a data type conflict with respect to the other ones.

• If one variable is in an expression then entire result is . Therefore, its data type is
.

• It is acceptable to have one variable instance, overwriting the previous occurrence. That is, you do
not have to create new objects.

• You cannot use an existing Python parser. You have to build your own.

• You should use and explore the Python interpreter to verify correctness of your program (use type()
in python to verify). Keep in mind this homework is asking you to develop a ”stricter interpreter” that
performs more static data type checking than the standard Python interpreter.

• The program is required to detect data type conflicts. The program does not have to evaluate the
Python expressions to produce a result.

• You have to create a ”binding” data structure to track data types; which must be clearly highlighted in
your readme file.

• There will not be ”cast” or type conversion function calls since that would require to track types in
functions.

• The program should not halt when encountering syntax or data type errors in the input source code.

• Optional: For each variable you can store its data type and a list of lines where it was set or changed.

• Your program should write error messages to a log file (and optionally to the screen). Your program
should not crash, halt unexpectedly or produce unhandled exceptions. Consider empty input, zeroes
and inconsistent information. Each exception will be -10.

• Test cases: Your program will be tested with 10 test scripts, going from easy to difficult. If your
program fails an easy test script 10-20 points will be deducted. A medium difficulty test case is 10
points off. Difficult cases with specific input issues or complex algorithmic aspects are worth 5 points.

• You can assume the given python program will be clean and there will be no syntax error. 70% of the
grade for each test case will be to detect errors and 30% of the grade will be for detecting warnings.
Your program must print error where python shows error. You do not have to print all the warnings.

• A program not submitted by the deadline is zero points. A non-working program is worth 10 points.
A program that does some computations correctly, but fails several test cases (especially the easy
ones) is worth 50 points. Only programs that work correctly with most input files that produce correct
results will get a score of 80 or higher. In general, correctness is more important than speed.

• Your program will be initially executed using an automated script. So, make sure you follow the
filename and syntax format given in Section 3.

## a program with comment
l1=[2,3,4]
l2=[“2″,”3″]
a=24
b=”45”
c=a*b #this will give result in python, but for this hw, we will say it is .

a: int
b: int
c: int
d: str
k: bool
m: int
n: str

a: int
b: int

a = 3
b = 2
def setVal():
a = “string”
return
b = b + 1

a=4
b=5
c=”str”

x=20
y=40
z=x+y
w=20+40+80
s1=”str1″
s2=s1+w

a=50
b=45
if a>50: #you donot have to evaluate it
c=30
else:
d=”40″ #output will contain both c and d as we are not evaluatiing python code, just getting all the variable types
m=c+100*45
n=d+”coogs”
k=a>b

def f1(a,b):
return a+b
x=f1(2,3)
y=f1(“str1″,”str2″)
z=f1(2,”3”)

k1: str
k2: str
k3:
k4: str
l1: list
l2: list
l3: list
l4:

a: int
b: str
c:
l1: list
l2: list

s1: str
s2:
w: int
x: int
y: int
z: int

a: int
b: int
c: str

x: int
y: str
z:

l1=[4,5,6]
l2=[“s1″,”s2″,”s3″]
l3=l1+l2
l4=l1*l2
k1=”input”
k2=”output”
k3=k1*k2
k4=k1+k2

What Will You Get?

We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.

Premium Quality

Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.

Experienced Writers

Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.

On-Time Delivery

Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.

24/7 Customer Support

Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.

Complete Confidentiality

Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.

Authentic Sources

We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.

Moneyback Guarantee

Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.

Order Tracking

You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.

image

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

image

Trusted Partner of 9650+ Students for Writing

From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.

Preferred Writer

Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.

Grammar Check Report

Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.

One Page Summary

You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.

Plagiarism Report

You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.

Free Features $66FREE

  • Most Qualified Writer $10FREE
  • Plagiarism Scan Report $10FREE
  • Unlimited Revisions $08FREE
  • Paper Formatting $05FREE
  • Cover Page $05FREE
  • Referencing & Bibliography $10FREE
  • Dedicated User Area $08FREE
  • 24/7 Order Tracking $05FREE
  • Periodic Email Alerts $05FREE
image

Our Services

Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.

  • On-time Delivery
  • 24/7 Order Tracking
  • Access to Authentic Sources
Academic Writing

We create perfect papers according to the guidelines.

Professional Editing

We seamlessly edit out errors from your papers.

Thorough Proofreading

We thoroughly read your final draft to identify errors.

image

Delegate Your Challenging Writing Tasks to Experienced Professionals

Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!

Check Out Our Sample Work

Dedication. Quality. Commitment. Punctuality

Categories
All samples
Essay (any type)
Essay (any type)
The Value of a Nursing Degree
Undergrad. (yrs 3-4)
Nursing
2
View this sample

It May Not Be Much, but It’s Honest Work!

Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.

0+

Happy Clients

0+

Words Written This Week

0+

Ongoing Orders

0%

Customer Satisfaction Rate
image

Process as Fine as Brewed Coffee

We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.

See How We Helped 9000+ Students Achieve Success

image

We Analyze Your Problem and Offer Customized Writing

We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.

  • Clear elicitation of your requirements.
  • Customized writing as per your needs.

We Mirror Your Guidelines to Deliver Quality Services

We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.

  • Proactive analysis of your writing.
  • Active communication to understand requirements.
image
image

We Handle Your Writing Tasks to Ensure Excellent Grades

We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.

  • Thorough research and analysis for every order.
  • Deliverance of reliable writing service to improve your grades.
Place an Order Start Chat Now
image

Order your essay today and save 30% with the discount code Happy