SlideShare a Scribd company logo
Current C++ code:
parse.h // This file contains the function prototype of the parseName function whose body is
defined in parse.cpp.
string parseName(stringstream& in);
parse.cpp // characters until the next whitespace and returns the name that those characters form.
#include #include #include using namespace std; #include "parse.h"
string parseName(stringstream& in) {
main.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#include "expression.h"
#include "subexpression.h"
#include "symboltable.h"
#include "parse.h"
SymbolTable symbolTable;
void parseAssignments(stringstream& in);
int main() {
const int SIZE = 256;
Expression* expression;
char paren, comma, line[SIZE];
ifstream fin;
fin = ifstream("input.txt");
if (!(fin.is_open())) {
cout << "File did not open" << endl;
system("pause");
return 1;
}
while (true) {
fin.getline(line, SIZE);
if (!fin)
break;
stringstream in(line, ios_base::in);
in >> paren;
cout << line << " ";
try {
expression = SubExpression::parse(in);
in >> comma;
parseAssignments(in);
double result = expression->evaluate();
cout << "Value = " << result << endl;
}
catch (string message) {
cout << message << endl;
}
}
system("pause");
return 0;
}
void parseAssignments(stringstream& in) {
char assignop, delimiter;
string variable;
int value;
do {
variable = parseName(in);
in >> ws >> assignop >> value >> delimiter;
symbolTable.insert(variable, value);
}
while (delimiter == ',');
}
char alnum;
string name = "";
in >> ws;
while (isalnum(in.peek()))
{ in >> alnum; name += alnum;
}
return name; }
operand.h
class Operand: public Expression {
public: static Expression* parse(stringstream& in);
};
operand.cpp
using namespace std; #include "expression.h" #include "subexpression.h" #include "operand.h"
#include "variable.h" #include "literal.h" #include "parse.h"
Expression* Operand::parse(stringstream& in) {
char paren; int value;
in >> ws;
if (isdigit(in.peek())) {
in >> value; Expression* literal = new Literal(value); return literal;
} if (in.peek() == '(') {
in >> paren; return SubExpression::parse(in);
} else
return new Variable(parseName(in)); return 0;
}
subexpression.h
class SubExpression: public Expression {
public: SubExpression(Expression* left, Expression* right);
static Expression* parse(stringstream& in);
protected: Expression* left; Expression* right;
};
SubExpression.cpp
#include #include using namespace std; #include "expression.h" #include "subexpression.h"
#include "operand.h" #include "plus.h" #include "minus.h"
SubExpression::SubExpression(Expression* left, Expression* right) {
this->left = left; this->right = right;
} Expression* SubExpression::parse(stringstream& in) {
Expression* left; Expression* right; char operation, paren; left = Operand::parse(in); in >>
operation; right = Operand::parse(in); in >> paren; switch (operation) {
case '+': return new Plus(left, right);
case '-': return new Minus(left, right);
} return 0; }
plus.h
class Plus: public SubExpression {
public: Plus(Expression* left, Expression* right): SubExpression(left, right) { } double
evaluate() { return left->evaluate() + right->evaluate(); }
};
variable.h
class Variable: public Operand {
public: Variable(string name) { this->name = name; } double evaluate(); private: string name;
};
Variable.cpp
#include #include using namespace std; #include "expression.h" #include "operand.h" #include
"variable.h" #include "symboltable.h" extern SymbolTable symbolTable;
double Variable::evaluate() {
return symbolTable.lookUp(name);
}
minus.h
class Minus: public SubExpression {
public: Minus(Expression* left, Expression* right): SubExpression(left, right) { } double
evaluate() { return left->evaluate() - right->evaluate(); }
};
literal.h
class Literal: public Operand {
public: Literal(double value) { this->value = value; } double evaluate() { return value; } private:
double value; }; expression.h class Expression { public: virtual double evaluate() = 0;
};
symbolTable.h
class SymbolTable {
public: SymbolTable() {} void insert(string variable, double value); double lookUp(string
variable) const; private: struct Symbol { Symbol(string variable, double value) { this->variable =
variable; this->value = value; }
string variable; double value; };
vector elements;
};
symbolTable.cpp
#include #include using namespace std; #include "symboltable.h"
void SymbolTable::insert(string variable, double value) { const Symbol& symbol =
Symbol(variable, value); elements.push_back(symbol);
}
double SymbolTable::lookUp(string variable) const {
for (int i = 0; i < elements.size(); i++) if (elements[i].variable == variable) return
elements[i].value; return -1;
}
I need the following:
1. to modify the program so that it will parse additional types of expressions defined by the
expanded grammar shown below with the additions to the grammar in Bold :
statement expression ',' assignments ';'
expression '(' expressions ')'
expressions unary_expression | binary_expression | ternary_expression |
quaternary_expression
unary_expression expression '~'
binary_expression expression binary_operator expression
binary_operator '+' | '-' | '*' | '/' | '%' | '^' | '<' | '>' | '_'
ternary_expression expression '?' expression expression
quaternary_expression expression '#' expression expression expression
operand literal | variable | expression
assignments assignments ',' assignment | assignment
assignment variable '=' literal
Each new class must be in a separate .h and .cpp pair of files. If all the functions in a class are
one line functions, they can be implemented inline in .h file and the .cpp file can be omitted.
The semantics of the additional binary arithmetic operators are as follows: * Multiplication, /
Division, % Remainder, ^ Exponentiation.
Although two of the three additional binary operators are customarily relational operators in
most languages, that is not true in this language. The semantics of all three of those operators are
as follows: < Minimum (Evaluates to the minimum of the left and right operand) > Maximum
(Evaluates to the maximum of the left and right operand) & Average (Evaluates to the average of
the left and right operand) The single unary operator ~ is the negation operator. Unlike the unary
minus in most languages, it is a postfix operator rather than a prefix one. The single ternary
operator ? is the conditional expression operator. Unlike the conditional expression operator in
C++ and Java, no colon separates the second and third operands. This expression is evaluated as
follows. If the expression to the left of the operator ? is not 0, the value of the expression is the
value of the first expression after the operator ?. If it is 0, the value of the expression is the value
of the second expression after the operator ?. The single quaternary operator # is a variation of
the typical conditional expression operator. Like the ternary conditional expression operator, the
remaining three operands are delimited only by whitespace. This expression is evaluated as
follows. If the expression to the left of the operator # is less than 0, the value of the expression is
the value of the first expression after the operator #. If it is equal to 0, the value of the expression
is the value of the second expression after the operator #. If it is greater than 0, the value of the
expression is the value of the third expression after the operator #.
Ad

More Related Content

Similar to Current C++ code- parse-h -- This file contains the function prototype (1).pdf (20)

UNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineeringUNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
2. operator
2. operator2. operator
2. operator
Shankar Gangaju
 
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
prasadmutkule1
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
Functions
FunctionsFunctions
Functions
zeeshan841
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
Digvijaysinh Gohil
 
Function in c
Function in cFunction in c
Function in c
CGC Technical campus,Mohali
 
python fudmentalsYYour score increaseases
python fudmentalsYYour score increaseasespython fudmentalsYYour score increaseases
python fudmentalsYYour score increaseases
ssuser61d324
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
Raghunath A
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
Gnugroup India
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
2 Functions2.pptx
2 Functions2.pptx2 Functions2.pptx
2 Functions2.pptx
RohitYadav830391
 
Functions
FunctionsFunctions
Functions
SANTOSH RATH
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
ankush_kumar
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
UNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineeringUNIT – 3.pptx for first year engineering
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
ESIT135 Problem Solving Using Python Notes of Unit-2 and Unit-3
prasadmutkule1
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
AnisZahirahAzman
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
amiable_indian
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
Digvijaysinh Gohil
 
python fudmentalsYYour score increaseases
python fudmentalsYYour score increaseasespython fudmentalsYYour score increaseases
python fudmentalsYYour score increaseases
ssuser61d324
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
Raghunath A
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
ankush_kumar
 

More from shyamsunder1211 (20)

Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdfCybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
shyamsunder1211
 
Custom objects in Salesforce can result from what activity- System Adm.pdf
Custom objects in Salesforce can result from what activity- System Adm.pdfCustom objects in Salesforce can result from what activity- System Adm.pdf
Custom objects in Salesforce can result from what activity- System Adm.pdf
shyamsunder1211
 
Currently there are no taxes on the market for good X- At the current.pdf
Currently there are no taxes on the market for good X- At the current.pdfCurrently there are no taxes on the market for good X- At the current.pdf
Currently there are no taxes on the market for good X- At the current.pdf
shyamsunder1211
 
Current information for the Healey Company follows- Beginning raw mate.pdf
Current information for the Healey Company follows- Beginning raw mate.pdfCurrent information for the Healey Company follows- Beginning raw mate.pdf
Current information for the Healey Company follows- Beginning raw mate.pdf
shyamsunder1211
 
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdf
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdfCurrent Attempt in Progress Your answer is incorrect- Examples of regu.pdf
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdf
shyamsunder1211
 
Current Attempt in Progress These items are taken from the financial s (1).pdf
Current Attempt in Progress These items are taken from the financial s (1).pdfCurrent Attempt in Progress These items are taken from the financial s (1).pdf
Current Attempt in Progress These items are taken from the financial s (1).pdf
shyamsunder1211
 
Current Attempt in Progress The following information is available for.pdf
Current Attempt in Progress The following information is available for.pdfCurrent Attempt in Progress The following information is available for.pdf
Current Attempt in Progress The following information is available for.pdf
shyamsunder1211
 
Current Attempt in Progress Here is financial information for Sunland.pdf
Current Attempt in Progress Here is financial information for Sunland.pdfCurrent Attempt in Progress Here is financial information for Sunland.pdf
Current Attempt in Progress Here is financial information for Sunland.pdf
shyamsunder1211
 
Current Attempt in Progress Below is a partial listing of the adjusted.pdf
Current Attempt in Progress Below is a partial listing of the adjusted.pdfCurrent Attempt in Progress Below is a partial listing of the adjusted.pdf
Current Attempt in Progress Below is a partial listing of the adjusted.pdf
shyamsunder1211
 
Current assets Current assets - contra Current liabilities Current lia.pdf
Current assets Current assets - contra Current liabilities Current lia.pdfCurrent assets Current assets - contra Current liabilities Current lia.pdf
Current assets Current assets - contra Current liabilities Current lia.pdf
shyamsunder1211
 
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdfCuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
shyamsunder1211
 
Cross-sectional surveys can be characterized as- occurring at two po.pdf
Cross-sectional surveys can be characterized as-   occurring at two po.pdfCross-sectional surveys can be characterized as-   occurring at two po.pdf
Cross-sectional surveys can be characterized as- occurring at two po.pdf
shyamsunder1211
 
Criminal convictions and judgments are two components of your personal.pdf
Criminal convictions and judgments are two components of your personal.pdfCriminal convictions and judgments are two components of your personal.pdf
Criminal convictions and judgments are two components of your personal.pdf
shyamsunder1211
 
creatively and demonstrates his genuine care for their well-being on a.pdf
creatively and demonstrates his genuine care for their well-being on a.pdfcreatively and demonstrates his genuine care for their well-being on a.pdf
creatively and demonstrates his genuine care for their well-being on a.pdf
shyamsunder1211
 
Create C# Console Program The labels that stay are the only cursor tha.pdf
Create C# Console Program The labels that stay are the only cursor tha.pdfCreate C# Console Program The labels that stay are the only cursor tha.pdf
Create C# Console Program The labels that stay are the only cursor tha.pdf
shyamsunder1211
 
Create this program in visual studio C# The design of the form A text.pdf
Create this program in visual studio C# The design of the form A text.pdfCreate this program in visual studio C# The design of the form A text.pdf
Create this program in visual studio C# The design of the form A text.pdf
shyamsunder1211
 
Create me an activity diagram for this scenario- A Call Taker receives.pdf
Create me an activity diagram for this scenario- A Call Taker receives.pdfCreate me an activity diagram for this scenario- A Call Taker receives.pdf
Create me an activity diagram for this scenario- A Call Taker receives.pdf
shyamsunder1211
 
Create some simple Python code which does the following- Creates a tup.pdf
Create some simple Python code which does the following- Creates a tup.pdfCreate some simple Python code which does the following- Creates a tup.pdf
Create some simple Python code which does the following- Creates a tup.pdf
shyamsunder1211
 
Create the Function for the program that will prompt the user to enter.pdf
Create the Function for the program that will prompt the user to enter.pdfCreate the Function for the program that will prompt the user to enter.pdf
Create the Function for the program that will prompt the user to enter.pdf
shyamsunder1211
 
Create C# Console Program The labels just stay the cursor should move.pdf
Create C# Console  Program The labels just stay the cursor should move.pdfCreate C# Console  Program The labels just stay the cursor should move.pdf
Create C# Console Program The labels just stay the cursor should move.pdf
shyamsunder1211
 
Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdfCybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
Cybersecurity in the Cloud - In this two-part discussion post- you wil.pdf
shyamsunder1211
 
Custom objects in Salesforce can result from what activity- System Adm.pdf
Custom objects in Salesforce can result from what activity- System Adm.pdfCustom objects in Salesforce can result from what activity- System Adm.pdf
Custom objects in Salesforce can result from what activity- System Adm.pdf
shyamsunder1211
 
Currently there are no taxes on the market for good X- At the current.pdf
Currently there are no taxes on the market for good X- At the current.pdfCurrently there are no taxes on the market for good X- At the current.pdf
Currently there are no taxes on the market for good X- At the current.pdf
shyamsunder1211
 
Current information for the Healey Company follows- Beginning raw mate.pdf
Current information for the Healey Company follows- Beginning raw mate.pdfCurrent information for the Healey Company follows- Beginning raw mate.pdf
Current information for the Healey Company follows- Beginning raw mate.pdf
shyamsunder1211
 
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdf
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdfCurrent Attempt in Progress Your answer is incorrect- Examples of regu.pdf
Current Attempt in Progress Your answer is incorrect- Examples of regu.pdf
shyamsunder1211
 
Current Attempt in Progress These items are taken from the financial s (1).pdf
Current Attempt in Progress These items are taken from the financial s (1).pdfCurrent Attempt in Progress These items are taken from the financial s (1).pdf
Current Attempt in Progress These items are taken from the financial s (1).pdf
shyamsunder1211
 
Current Attempt in Progress The following information is available for.pdf
Current Attempt in Progress The following information is available for.pdfCurrent Attempt in Progress The following information is available for.pdf
Current Attempt in Progress The following information is available for.pdf
shyamsunder1211
 
Current Attempt in Progress Here is financial information for Sunland.pdf
Current Attempt in Progress Here is financial information for Sunland.pdfCurrent Attempt in Progress Here is financial information for Sunland.pdf
Current Attempt in Progress Here is financial information for Sunland.pdf
shyamsunder1211
 
Current Attempt in Progress Below is a partial listing of the adjusted.pdf
Current Attempt in Progress Below is a partial listing of the adjusted.pdfCurrent Attempt in Progress Below is a partial listing of the adjusted.pdf
Current Attempt in Progress Below is a partial listing of the adjusted.pdf
shyamsunder1211
 
Current assets Current assets - contra Current liabilities Current lia.pdf
Current assets Current assets - contra Current liabilities Current lia.pdfCurrent assets Current assets - contra Current liabilities Current lia.pdf
Current assets Current assets - contra Current liabilities Current lia.pdf
shyamsunder1211
 
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdfCuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
Cuck Ai That Appir first noter- fecernd mater mecanil tein- Bret tarie.pdf
shyamsunder1211
 
Cross-sectional surveys can be characterized as- occurring at two po.pdf
Cross-sectional surveys can be characterized as-   occurring at two po.pdfCross-sectional surveys can be characterized as-   occurring at two po.pdf
Cross-sectional surveys can be characterized as- occurring at two po.pdf
shyamsunder1211
 
Criminal convictions and judgments are two components of your personal.pdf
Criminal convictions and judgments are two components of your personal.pdfCriminal convictions and judgments are two components of your personal.pdf
Criminal convictions and judgments are two components of your personal.pdf
shyamsunder1211
 
creatively and demonstrates his genuine care for their well-being on a.pdf
creatively and demonstrates his genuine care for their well-being on a.pdfcreatively and demonstrates his genuine care for their well-being on a.pdf
creatively and demonstrates his genuine care for their well-being on a.pdf
shyamsunder1211
 
Create C# Console Program The labels that stay are the only cursor tha.pdf
Create C# Console Program The labels that stay are the only cursor tha.pdfCreate C# Console Program The labels that stay are the only cursor tha.pdf
Create C# Console Program The labels that stay are the only cursor tha.pdf
shyamsunder1211
 
Create this program in visual studio C# The design of the form A text.pdf
Create this program in visual studio C# The design of the form A text.pdfCreate this program in visual studio C# The design of the form A text.pdf
Create this program in visual studio C# The design of the form A text.pdf
shyamsunder1211
 
Create me an activity diagram for this scenario- A Call Taker receives.pdf
Create me an activity diagram for this scenario- A Call Taker receives.pdfCreate me an activity diagram for this scenario- A Call Taker receives.pdf
Create me an activity diagram for this scenario- A Call Taker receives.pdf
shyamsunder1211
 
Create some simple Python code which does the following- Creates a tup.pdf
Create some simple Python code which does the following- Creates a tup.pdfCreate some simple Python code which does the following- Creates a tup.pdf
Create some simple Python code which does the following- Creates a tup.pdf
shyamsunder1211
 
Create the Function for the program that will prompt the user to enter.pdf
Create the Function for the program that will prompt the user to enter.pdfCreate the Function for the program that will prompt the user to enter.pdf
Create the Function for the program that will prompt the user to enter.pdf
shyamsunder1211
 
Create C# Console Program The labels just stay the cursor should move.pdf
Create C# Console  Program The labels just stay the cursor should move.pdfCreate C# Console  Program The labels just stay the cursor should move.pdf
Create C# Console Program The labels just stay the cursor should move.pdf
shyamsunder1211
 
Ad

Recently uploaded (20)

How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Ad

Current C++ code- parse-h -- This file contains the function prototype (1).pdf

  • 1. Current C++ code: parse.h // This file contains the function prototype of the parseName function whose body is defined in parse.cpp. string parseName(stringstream& in); parse.cpp // characters until the next whitespace and returns the name that those characters form. #include #include #include using namespace std; #include "parse.h" string parseName(stringstream& in) { main.cpp #include <iostream> #include <fstream> #include <sstream> #include <string> #include <vector> using namespace std; #include "expression.h" #include "subexpression.h" #include "symboltable.h" #include "parse.h" SymbolTable symbolTable; void parseAssignments(stringstream& in); int main() { const int SIZE = 256; Expression* expression; char paren, comma, line[SIZE]; ifstream fin; fin = ifstream("input.txt"); if (!(fin.is_open())) { cout << "File did not open" << endl; system("pause"); return 1; } while (true) { fin.getline(line, SIZE); if (!fin) break;
  • 2. stringstream in(line, ios_base::in); in >> paren; cout << line << " "; try { expression = SubExpression::parse(in); in >> comma; parseAssignments(in); double result = expression->evaluate(); cout << "Value = " << result << endl; } catch (string message) { cout << message << endl; } } system("pause"); return 0; } void parseAssignments(stringstream& in) { char assignop, delimiter; string variable; int value; do { variable = parseName(in); in >> ws >> assignop >> value >> delimiter; symbolTable.insert(variable, value); } while (delimiter == ','); } char alnum; string name = ""; in >> ws; while (isalnum(in.peek())) { in >> alnum; name += alnum; } return name; } operand.h
  • 3. class Operand: public Expression { public: static Expression* parse(stringstream& in); }; operand.cpp using namespace std; #include "expression.h" #include "subexpression.h" #include "operand.h" #include "variable.h" #include "literal.h" #include "parse.h" Expression* Operand::parse(stringstream& in) { char paren; int value; in >> ws; if (isdigit(in.peek())) { in >> value; Expression* literal = new Literal(value); return literal; } if (in.peek() == '(') { in >> paren; return SubExpression::parse(in); } else return new Variable(parseName(in)); return 0; } subexpression.h class SubExpression: public Expression { public: SubExpression(Expression* left, Expression* right); static Expression* parse(stringstream& in); protected: Expression* left; Expression* right; }; SubExpression.cpp
  • 4. #include #include using namespace std; #include "expression.h" #include "subexpression.h" #include "operand.h" #include "plus.h" #include "minus.h" SubExpression::SubExpression(Expression* left, Expression* right) { this->left = left; this->right = right; } Expression* SubExpression::parse(stringstream& in) { Expression* left; Expression* right; char operation, paren; left = Operand::parse(in); in >> operation; right = Operand::parse(in); in >> paren; switch (operation) { case '+': return new Plus(left, right); case '-': return new Minus(left, right); } return 0; } plus.h class Plus: public SubExpression { public: Plus(Expression* left, Expression* right): SubExpression(left, right) { } double evaluate() { return left->evaluate() + right->evaluate(); } }; variable.h class Variable: public Operand { public: Variable(string name) { this->name = name; } double evaluate(); private: string name; }; Variable.cpp #include #include using namespace std; #include "expression.h" #include "operand.h" #include "variable.h" #include "symboltable.h" extern SymbolTable symbolTable; double Variable::evaluate() { return symbolTable.lookUp(name); } minus.h
  • 5. class Minus: public SubExpression { public: Minus(Expression* left, Expression* right): SubExpression(left, right) { } double evaluate() { return left->evaluate() - right->evaluate(); } }; literal.h class Literal: public Operand { public: Literal(double value) { this->value = value; } double evaluate() { return value; } private: double value; }; expression.h class Expression { public: virtual double evaluate() = 0; }; symbolTable.h class SymbolTable { public: SymbolTable() {} void insert(string variable, double value); double lookUp(string variable) const; private: struct Symbol { Symbol(string variable, double value) { this->variable = variable; this->value = value; } string variable; double value; }; vector elements; }; symbolTable.cpp #include #include using namespace std; #include "symboltable.h" void SymbolTable::insert(string variable, double value) { const Symbol& symbol = Symbol(variable, value); elements.push_back(symbol); } double SymbolTable::lookUp(string variable) const { for (int i = 0; i < elements.size(); i++) if (elements[i].variable == variable) return elements[i].value; return -1; }
  • 6. I need the following: 1. to modify the program so that it will parse additional types of expressions defined by the expanded grammar shown below with the additions to the grammar in Bold : statement expression ',' assignments ';' expression '(' expressions ')' expressions unary_expression | binary_expression | ternary_expression | quaternary_expression unary_expression expression '~' binary_expression expression binary_operator expression binary_operator '+' | '-' | '*' | '/' | '%' | '^' | '<' | '>' | '_' ternary_expression expression '?' expression expression quaternary_expression expression '#' expression expression expression operand literal | variable | expression assignments assignments ',' assignment | assignment assignment variable '=' literal Each new class must be in a separate .h and .cpp pair of files. If all the functions in a class are one line functions, they can be implemented inline in .h file and the .cpp file can be omitted. The semantics of the additional binary arithmetic operators are as follows: * Multiplication, / Division, % Remainder, ^ Exponentiation. Although two of the three additional binary operators are customarily relational operators in most languages, that is not true in this language. The semantics of all three of those operators are as follows: < Minimum (Evaluates to the minimum of the left and right operand) > Maximum (Evaluates to the maximum of the left and right operand) & Average (Evaluates to the average of the left and right operand) The single unary operator ~ is the negation operator. Unlike the unary minus in most languages, it is a postfix operator rather than a prefix one. The single ternary operator ? is the conditional expression operator. Unlike the conditional expression operator in C++ and Java, no colon separates the second and third operands. This expression is evaluated as follows. If the expression to the left of the operator ? is not 0, the value of the expression is the value of the first expression after the operator ?. If it is 0, the value of the expression is the value of the second expression after the operator ?. The single quaternary operator # is a variation of the typical conditional expression operator. Like the ternary conditional expression operator, the
  • 7. remaining three operands are delimited only by whitespace. This expression is evaluated as follows. If the expression to the left of the operator # is less than 0, the value of the expression is the value of the first expression after the operator #. If it is equal to 0, the value of the expression is the value of the second expression after the operator #. If it is greater than 0, the value of the expression is the value of the third expression after the operator #.
  翻译: