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.

Get 20% Discount on This Paper
Pages (550 words)
Approximate price: -

Try it now!

Get 20% Discount on This Paper

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Australia Assessments has gained an international reputation of being the leading website in custom assignment writing services. Once you give us the instructions of your paper through the order form, we will complete the rest.

Essays

Essay Writing Services

As we work towards providing the best custom assignment services, our company provides assignment services for any type of academic essay. We will help you develop professionally written essays that are rich in content and free from plagiarism.

Admissions

Admission and Business Papers

Our skilled team of professional writers will ensure that we help you craft a remarkable admission essay for your desired Master's program in your institution of choice. We won't stop there. Once you enter the job market, we will be available to secure you a position at your desired worksite by creating an outstanding portfolio or resume.

Editing

Editing and Proofreading

Our editorial team is always available for all editing and proofreading services. They check completed papers by our writers and also provide professional opinions to papers completed by our clients.

Coursework

Technical papers

We harbor professional academic writers with different qualifications in diverse academic fields. As such, we are capable of handling both simple and technical papers. Ensure that you provide us with correct and complete instructions in the order form.