Need help in python ( raed it, then email me)

 

write a python script that is capable of validating the format of an assignment statement in a pretend language as specified below, much like a compiler or interpreter might do. Potential statements to verify will be contained in a file, one per line, where the name of the file is specified as a command line argument. The parsing process will be done incrementally using regular expressions and the intermediate results will be printed out along the way. The format of a statement is described below.

The first two lines of the file will define the valid variables that can be used in the expressions in the rest of the file. The first line will consist of the keyword int, followed by a space and a comma separated list of names. A valid name begins with a letter, and can be followed by any number of digits, letters or hyphens. The second line has the same format, except the keyword at the beginning of the line is the word real.You should validate that the format of each of these lines is correct. If not, print an error message and exit the program. Otherwise, make a list of the valid variable names and their types.

The remaining lines of the file will represent assignment statements. These can be composed of various operators and operands according to a special format which has very little to do with actual Python syntax. The first phase of parsing is to find potential operands. An operand can be either a valid variable name from the lists supplied on the first two lines, or a literal integer or real number. A literal integer can have an optional plus or minus sign to start, followed by a series of digits beginning with a non-zero digit, unless the value is 0 itself. A literal real number begins as an integer does, but is then followed by a period, and at least one digit (no multiple zeros). You should replace occurrences of valid integer variable names with the word intvar. You should replace occurrences of valid real variable names with the word realvar. You should replace occurrences of real literals with the word reallit. You should replace occurrences of integer literals with the word intlit. You should print out intermediate versions of an expression string after replacements for each type of operand have occurred.

There are seven valid operators: 1) = is the assignment operator, 2) + is for integer or real addition, 3) – is for integer or real subtraction, 4) * is for integer or real multiplication, 5) / is for real division, 6) // is for integer division, and 7) ** for exponentiation. You should replace occurrences of these operators with the corresponding words: opequal, opadd, opsub, opmult, oprdivopidiv, and opexp. You should print out intermediate versions of an expression string after replacements for each type of operator have occurred. After having done all of the operand and operator replacements, if there is anything in the revised expression other than the four words for operand types and the seven words for operator types, an error message should be printed and the processing stopped for this expression.

The next phase of parsing is to recognize various terms in the expression that involve multiplication, division, and exponentiation operators. The definition of an integer term is the following: an intvar or intlit followed by opmultopidiv, or opexp, followed by another intvar or intlit. It is represented by the word intterm. It is also possible for an integer term to begin with the word intterm rather than intvar or intlit. The definition of a real term is the following: a realvar or reallit followed by opmultoprdiv, or opexp, followed by another realvar or reallit in the case of multiplication and division, but only by an intvar or intlit for opexp. It is represented by the word realterm. It is also possible for a real term to begin with the word realterm rather than realvar or reallit. You should replace all occurrences of the terms involving multiplication, division, and exponentiation by the appropriate words intterm and realterm and print out the revised expression. If there are any occurrences of opmult, oprdivopidiv, or opexp left in the expression after this step, an error message should be printed and the processing stopped for this expression.

The next phase of parsing is to recognize various subexpressions in the expression that involve addition and subtraction operators. The definition of an integer subexpression is the following: an intvar, intlit or intterm followed by opadd or opsub followed by another intvar, intlit or intterm. It is represented by the word intsub. It is also possible for an integer subexpression to begin with the word intsub rather than intvar, intlit or intterm. The definition of a real subexpression is the following: a realvar, reallit or realterm followed by opadd or opsub followed by another realvar, reallit or realterm. It is represented by the word realsub. It is also possible for a real subexpression to begin with the word realsub rather than realvar, reallit or realterm. You should replace all occurrences of the subexpressions involving addition and subtraction by the appropriate words intsub and realsub and print out the revised expression. If there are any occurrences of opadd or opsub left after this step, an error message should be printed and the processing stopped for this expression.

It is possible to have one pair of parentheses in an expression for grouping. Before doing a final set of parsing for terms and subexpressions, you should first determine if there is such a pair of parentheses. If there is, then you should first process terms and subexpressions in the string bounded by the parentheses. Then you can do parsing for terms and subexpressions across the entire calculation.

The final expression check is to see if a valid statement remains. It takes one of two forms: 1) an intvar followed by opequal followed by an intlit, intvar, intterm or intsub, or 2) a realvar followed by opequalfollowed by a reallit, realvar, realterm or realsub. If you find such a pattern it should be replaced by the word statement and the resulting string should be printed out. If there is anything left in the expression string other than the word statement, an error message should be printed out. 

You should process all lines of the file in this manner, using regular expressions as often as possible. Submit your commented source code here, along with a sample input file of text expressions and the corresponding output generated by the program for these test expressions.

Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with Australia Assessments
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Other
The paper is well-written with few errors.
Customer 452455, June 26th, 2023
Psychology
This paper was beautifully written! Thank you to the tutor for doing an outstanding job and superseding my expectations. Also, thank you to the customer service for ensuring that I receive quality papers.
Customer 452455, April 28th, 2023
Healthcare & Medical
Excellent work! This submission had a mature tone and required minimal edits for clarity. We look forward to your future contributions.
Customer 452441, August 5th, 2022
Military
Excellent Paper
Customer 456821, December 6th, 2022
Military
very good job
Customer 456821, June 15th, 2022
Public Relations (PR)
They did a good Job, with minor mistake, however will use again
Customer 452621, February 9th, 2020
Interior Decoration
Few edits needed
Customer 463337, November 9th, 2022
English 101
Good work.
Customer 456823, May 15th, 2022
Education
Excellent.
Customer 454463, April 25th, 2022
Education
Good response.
Customer 454463, May 5th, 2022
Aviation
Paper was received on time but the revision was late. This was worth the wait as the revision helped me better understand the topic more. Thanks!
Customer 454145, April 12th, 2020
SEO
good work
Customer 463813, April 14th, 2023
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat