09 Jul write a python script that is capable of validating the format of a
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, oprdiv, opidiv, 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 opmult, opidiv, 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 opmult, oprdiv, 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, oprdiv, opidiv, 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.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.