this is part of the assignment . part 1 vibhav has done and part is Pawan has done. i would like to have pawan to work on this part 3. if not then i would like to haveKshitij ,Nimesh.whoever works...

2 answer below »
this is part of the assignment . part 1 vibhav has done and part is Pawan has done. i would like to have pawan to work on this part 3. if not then i would like to haveKshitij ,Nimesh.whoever works must use provided tool to run code. all of them know how it works. if they need any additional detail about part 1 and part 2 please text or email me because this server not provide me all files to upload. i upload files and where to run code and all stuff for this assignmentIn this programming assignment, you will be building an interpreter for our PLSL programming language. The grammar rules of the language and its tokens were given in Programming Assignments 1 and 2. However, one rule has been eliminated from the previous specifications, it is the one for the For Statement. You are required to modify the parser you have implemented for the PLSL language to implement an interpreter for it.





CS 280 Spring 2022 Programming Assignment 3 April 14, 2022 Due Date: Sunday, May 1st, 2022, 23:59 Total Points: 20 In this programming assignment, you will be building an interpreter for our PLSL programming language. The grammar rules of the language and its tokens were given in Programming Assignments 1 and 2. However, one rule has been eliminated from the previous specifications, it is the one for the For Statement. You are required to modify the parser you have implemented for the PLSL language to implement an interpreter for it. The modified specifications of the grammar rules are described in EBNF notations. 1. Prog ::= PROGRAM IDENT; DeclBlock ProgBody 2. DeclBlock ::= VAR {DeclStmt;} 3. DeclStmt ::= Ident {, Ident} : (Integer | Real | String) 4. ProgBody ::= BEGIN {Stmt;} END 5. Stmt ::= AssigStmt | IfStmt | WriteLnStmt 6. WriteLnStmt ::= WRITELN (ExprList) 7. IfStmt ::= IF ( LogicExpr ) THEN Stmt [ELSE Stmt] 8. AssignStmt ::= Var := Expr 9. ExprList ::= Expr {, Expr} 10. Expr ::= Term {(+|-) Term} 11. Term ::= SFactor {( * | / ) SFactor} 12. SFactor ::= [(+ | -)] Factor 13. LogicExpr ::= Expr (= | > | <) expr="" 14.="" var="" ::="IDENT" 15.="" factor="" ::="IDENT" |="" iconst="" |="" rconst="" |="" sconst="" |="" (expr)="" the="" following="" points="" describe="" the="" programming="" language.="" you="" have="" already="" implemented="" all="" of="" the="" syntactic="" rules="" of="" the="" language="" as="" part="" of="" the="" parser="" implementation.="" the="" points="" related="" to="" the="" dynamic="" semantics="" (i.e.="" run-time="" checks)="" of="" the="" language="" must="" be="" implemented="" in="" your="" interpreter.="" these="" include="" points="" 5-12="" in="" the="" following="" list.="" these="" points="" are:="" 1.="" the="" language="" has="" three="" types:="" integer,="" real="" and="" string.="" 2.="" the="" precedence="" rules="" of="" the="" pslp="" language="" are="" as="" shown="" in="" the="" table="" 3.="" the="" plus,="" minus,="" mult,="" and="" div="" operators="" are="" left="" associative.="" 4.="" all="" variables="" have="" to="" be="" declared="" in="" declaration="" statements="" in="" the="" declaration="" block.="" 5.="" an="" ifstmt="" evaluates="" a="" logical="" expression="" (logicexpr)="" as="" a="" condition.="" if="" the="" logical="" expression="" value="" is="" true,="" then="" the="" stmt="" block="" is="" executed,="" otherwise="" it="" is="" not.="" an="" else="" part="" for="" an="" ifsmt="" is="" optional.="" 6.="" a="" writelnstmt="" evaluates="" the="" list="" of="" expressions="" (exprlist),="" and="" prints="" their="" values="" in="" order="" from="" left="" to="" right="" followed="" by="" a="" newline.="" 7.="" the="" assop="" operator="" (:=")" in="" the="" assignstmt="" assigns="" a="" value="" to="" a="" variable.="" it="" evaluates="" the="" expr="" on="" the="" right-hand="" side="" and="" saves="" its="" value="" in="" a="" memory="" location="" associated="" with="" the="" left-hand="" side="" variable="" (var).="" a="" left-hand="" side="" variable="" of="" a="" numeric="" type="" can="" be="" assigned="" a="" value="" of="" either="" one="" of="" the="" numeric="" types="" (i.e.,="" integer,="" real)="" of="" the="" language.="" for="" example,="" an="" integer="" variable="" can="" be="" assigned="" a="" real="" value,="" and="" a="" real="" variable="" can="" be="" assigned="" an="" integer="" value.="" in="" either="" case,="" conversion="" of="" the="" value="" to="" the="" type="" of="" the="" variable="" must="" be="" applied.="" however,="" a="" left-hand="" side="" string="" variable="" can="" only="" be="" assigned="" a="" string="" value.="" 8.="" the="" binary="" arithmetic="" operations="" for="" addition="" (plus),="" subtraction="" (minus),="" multiplication="" (mult),="" and="" division="" (div)="" are="" performed="" upon="" two="" numeric="" operands="" (i.e.,="" integer,="" real)="" of="" the="" same="" or="" different="" types.="" if="" the="" operands="" are="" of="" the="" same="" type,="" the="" type="" of="" the="" result="" is="" the="" same="" type="" as="" the="" operator’s="" operands.="" otherwise,="" the="" type="" of="" the="" result="" is="" real.="" 9.="" when="" the="" plus="" operator="" is="" applied="" on="" string="" operands,="" the="" operator="" performs="" string="" concatenation.="" 10.="" the="" equal="" lthan="" and="" gthan="" relational="" operators="" operate="" upon="" two="" compatible="" operands.="" the="" evaluation="" of="" a="" logical="" expression,="" based="" on="" equal,="" lthan="" or="" gthan="" operation,="" produces="" either="" a="" true="" or="" false="" value="" that="" controls="" whether="" the="" statement(s)="" of="" the="" selection="" ifstmt="" is="" executed="" or="" not.="" 11.="" it="" is="" an="" error="" to="" use="" a="" variable="" in="" an="" expression="" before="" it="" has="" been="" assigned.="" 12.="" the="" unary="" sign="" operators="" (+="" or="" -)="" are="" applied="" upon="" unary="" numeric="" operands="" (i.e.,="" integer,="" real).="" precedence="" highest="" ()="" parentheses="" unary="" +,="" unary="" -="" *,="" (left="" associative)="" +="" (add),="" -="" (subtract)="" (left="" associative)="" lowest=","><,> (relational operators) Interpreter Requirements: I. Implement an interpreter for the PLSL language based on the recursive-descent parser developed in Programming Assignment 2. You need to modify the parser functions to include the required actions of the interpreter for evaluating expressions, determining the type of expression values, executing the statements, and checking run-time errors. You may use the lexical analyzer you wrote for Programming Assignment 1 and the parser you wrote for Programming Assignment 2. Otherwise you may use the provided implementations for the lexical analyzer and parser when they are posted. Rename the parse.cpp file as parserInt.cpp to reflect the applied changes on the current parser implementation for building an interpreter. The interpreter should provide the following: • It performs syntax analysis of the input source code statement by statement, then executes the statement if there is no syntactic or semantic error. • It builds information of variables types in the symbol table for all the defined variables. • It evaluates expressions and determines their values and types. You need to implement the overloaded operator functions for the Value class. • The results of an unsuccessful parsing and interpreting are a set of error messages printed by the parser/interpreter functions, as well as the error messages that might be detected by the lexical analyzer. • Any failures due to the process of parsing or interpreting the input program should cause the process of interpretation to stop and return back. • In addition to the error messages generated due to parsing, the interpreter generates error messages due to its semantics checking. The assignment does not specify the exact error messages that should be printed out by the interpreter. However, the format of the messages should be the line number, followed by a colon and a space, followed by some descriptive text, similar to the format used in Programming Assignment 2. Suggested messages of the interpreter’s semantics check might include messages such as "Run-Time Error-Illegal Mixed Type Operands", " Run-Time Error-Illegal Assignment Operation", "Run-Time Error-Illegal Division by Zero", etc. Provided Files You are given the following files for the process of building an interpretation. These are “lex.h’, “lex.cpp”, “val.h”, “parseInt.h”, and “parseInt.cpp” with definitions and partial implementations of some functions. You need to complete the implementation of the interpreter in the provided copy of “parseInt.cpp. “parse.cpp” will be posted later on. “val.h” includes the following: • A class definition, called Value, representing a value object in the interpreted source code for constants, variables or evaluated expressions. It includes: o Four data members of the Value class for holding a value as either an integer, float, string, or boolean. o A data member holding the type of the value as an enum type defined as: enum ValType { VINT, VREAL, VSTRING, VBOOL, VERR }; o Getter methods to return the value of an object based on its type o Getter methods to return the type of the value of an object. o Setter methods to update the value of an object. o Overloaded constructors to initialize an object based on the type of their parameters. o Member methods to check the type of the Value object. o Overloaded operators’ functions for the arithmetic operators (+, -, *, and /) o Overloaded operators’ functions for the relational operators (==, >, and <) o="" a="" friend="" function="" for="" overloading="" the="">< to="" display="" value="" of="" an="" object="" based="" on="" its="" type.="" •="" you="" are="" required="" to="" provide="" the="" implementation="" of="" the="" value="" class="" in="" a="" separate="" file,="" called="" “val.cpp”,="" which="" includes="" the="" implementations="" of="" the="" overloaded="" operator="" functions="" specified="" in="" the="" value="" class="" definition="" (operator+,="" operator-,="" operator*,="" operator/,="" operator="=," operator="">, operator<). “parserint.h” includes the prototype definitions of the parser functions as in “parse.h” header file with the following applied modifications: • extern bool var(istream& in, int& line, lexitem & tok); • extern bool expr(istream& in, int& line, value & retval); • extern bool logicexpr(istream& in, int& line,value & retval); • extern bool term(istream& in, int& line, value & retval); • extern bool sfactor(istream& in, int& line, value & retval); • extern bool factor(istream& in, int& line, value & retval); “parseint.cpp” includes the following: • map containers definitions given in “parse.cpp” for programming assignment 2. • the declaration of a map container for temporaries’ values, called tempsresults. each entry of tempsresults is a pair of a string and a value object, representing a variable name, and its corresponding value object. • a map container symtable that keeps a record of each declared variable in the parsed program and its corresponding type. • the declaration of a pointer variable to a queue container of value objects. • implementations of the interpreter actions in some functions. “parse.cpp” • implementations of parser functions in “parse.cpp” from programming assignment 2. o it will be provided after the deadline of pa 2 submission (including any extensions). “prog3.cpp”: • you are given the testing program “prog3.cpp” that reads a file name from the command line. the file is opened for syntax analysis and interpretation, as a source code of the language. • a call to prog() function is made. if the call fails, the program should stop and display a message as "unsuccessful interpretation ", and display the number of errors detected. for example: unsuccessful interpretation number of syntax errors: 3 • if the call to prog() function succeeds, the program should stop and display the message "successful execution", and the program stops. vocareum automatic grading • you are provided by a set of 14 testing files associated with programming assignment 3. vocareum automatic grading will be based on these testing files. you may use them to “parserint.h”="" includes="" the="" prototype="" definitions="" of="" the="" parser="" functions="" as="" in="" “parse.h”="" header="" file="" with="" the="" following="" applied="" modifications:="" •="" extern="" bool="" var(istream&="" in,="" int&="" line,="" lexitem="" &="" tok);="" •="" extern="" bool="" expr(istream&="" in,="" int&="" line,="" value="" &="" retval);="" •="" extern="" bool="" logicexpr(istream&="" in,="" int&="" line,value="" &="" retval);="" •="" extern="" bool="" term(istream&="" in,="" int&="" line,="" value="" &="" retval);="" •="" extern="" bool="" sfactor(istream&="" in,="" int&="" line,="" value="" &="" retval);="" •="" extern="" bool="" factor(istream&="" in,="" int&="" line,="" value="" &="" retval);="" “parseint.cpp”="" includes="" the="" following:="" •="" map="" containers="" definitions="" given="" in="" “parse.cpp”="" for="" programming="" assignment="" 2.="" •="" the="" declaration="" of="" a="" map="" container="" for="" temporaries’="" values,="" called="" tempsresults.="" each="" entry="" of="" tempsresults="" is="" a="" pair="" of="" a="" string="" and="" a="" value="" object,="" representing="" a="" variable="" name,="" and="" its="" corresponding="" value="" object.="" •="" a="" map="" container="" symtable="" that="" keeps="" a="" record="" of="" each="" declared="" variable="" in="" the="" parsed="" program="" and="" its="" corresponding="" type.="" •="" the="" declaration="" of="" a="" pointer="" variable="" to="" a="" queue="" container="" of="" value="" objects.="" •="" implementations="" of="" the="" interpreter="" actions="" in="" some="" functions.="" “parse.cpp”="" •="" implementations="" of="" parser="" functions="" in="" “parse.cpp”="" from="" programming="" assignment="" 2.="" o="" it="" will="" be="" provided="" after="" the="" deadline="" of="" pa="" 2="" submission="" (including="" any="" extensions).="" “prog3.cpp”:="" •="" you="" are="" given="" the="" testing="" program="" “prog3.cpp”="" that="" reads="" a="" file="" name="" from="" the="" command="" line.="" the="" file="" is="" opened="" for="" syntax="" analysis="" and="" interpretation,="" as="" a="" source="" code="" of="" the="" language.="" •="" a="" call="" to="" prog()="" function="" is="" made.="" if="" the="" call="" fails,="" the="" program="" should="" stop="" and="" display="" a="" message="" as="" "unsuccessful="" interpretation="" ",="" and="" display="" the="" number="" of="" errors="" detected.="" for="" example:="" unsuccessful="" interpretation="" number="" of="" syntax="" errors:="" 3="" •="" if="" the="" call="" to="" prog()="" function="" succeeds,="" the="" program="" should="" stop="" and="" display="" the="" message="" "successful="" execution",="" and="" the="" program="" stops.="" vocareum="" automatic="" grading="" •="" you="" are="" provided="" by="" a="" set="" of="" 14="" testing="" files="" associated="" with="" programming="" assignment="" 3.="" vocareum="" automatic="" grading="" will="" be="" based="" on="" these="" testing="" files.="" you="" may="" use="" them="">
Answered 6 days AfterApr 13, 2022

Answer To: this is part of the assignment . part 1 vibhav has done and part is Pawan has done. i would like to...

Robert answered on Apr 19 2022
93 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here