You shall develop a grammar and implement a parser which recognizes valid statements as described below in the assignment specification. You may develop your code using C, C++.
The test file include these expressions below. The first six should pass and the rest should fail:
first = one1 + two2 - three3 / four4 ;
second = one1 * (two2 * three3) ;
second = one1 * (two2 * three3) ;
third = ONE + twenty - three3 ;
third = old * thirty2 / b567 ;
one1 * i8766e98e + bignum
first = = one1 + two2 - three3 / four4 ;
first = one1 + two2 - three3 / four4
first = 1 + - two2 - three3 / four4 ;
first = one1 + two2 ? three3 / four4 ;
second = 4 + ( one1 * two2 ) * ( three3 + four4 ;
third = one1 + 24 - three3 ;
one1 +- delta
sixty6 / min = fourth ;
Hi,
The problem has been resolved. I have tested most of the scenario and all are working fine. I have tested 6 passed and 3 fail test cases. Code is very long and i have not much time to test every test cases if you find any case not working then make some changes in code. Code is very easy you will understand the problem. 2 hours are not enough for the problem and test cases, Hope you will understand this.
I'm attaching you the file screenshot and the running code screenshot for better understanding.
Screenshot:
Code:
-------------------------------------
#include<bits/stdc++.h>
#include <fstream>
using namespace std;
bool isPassed(string str)
{
stack<char> s;
char x;
int op=0;
string expr;
bool isStat=false;
/*
std::istringstream stm(s) ;
string word ;
int count=0;
while( stm >> word ) // read white-space
delimited tokens one by one
{
expr[count]=word;
count++;
}
*/
for(int i=0;i<str.length();i++){
if(str[i] != ' ')
expr+=str[i];
if(str[i] == '=')
isStat=true;
}
if(isStat && expr[expr.length()-1] !=
';'){
return false;
}
for (int i=0; i<expr.length(); i++)
{
if
(expr[i]=='('||expr[i]=='['||expr[i]=='{')
{
s.push(expr[i]);
continue;
}
switch (expr[i])
{
case ')':
x =
s.top();
s.pop();
if (x=='{' ||
x=='[')
return false;
break;
case '}':
x =
s.top();
s.pop();
if (x=='(' ||
x=='[')
return false;
break;
case ']':
x =
s.top();
s.pop();
if (x =='(' || x
== '{')
return false;
break;
default:
if(expr[i]=='+' || expr[i]=='-' || expr[i]=='/' || expr[i]=='*' ||
expr[i]=='%'|| expr[i]=='='){
op=op+1;
}else{
op=0;
}
//cout<<" op "<<op<<endl;
if(op>1){
return false;
}
break;
}
}
return (s.empty());
}
int main()
{
freopen("file.txt", "rb", stdin);
string line;
while(getline(cin, line)){
cout << line << endl;
//string expr = "first = = one1 + two2 - three3 / four4 ;";
if (isPassed(line))
cout << "PASS\n\n";
else
cout << "FAIL\n\n";
}
return 0;
}
-----------------------------------
The problem has been resolved, I hope you will like the solution. If you have any question or query regarding this problem or other, please comment below and give the positive rating.
Thank You!! Happy Learning!! !!
You shall develop a grammar and implement a parser which recognizes valid statements as described below in the assignment specification. You may develop your code using C, C++. The test file include...
C++ PROPOSITIONAL LOGIC
Assignment: Create a program which can test the validity of propositional logic. Remember, a propositional logical statement is invalid should you find any combination of input where the PROPOSITIONAL statements are ALL true, while the CONCLUSION statement is false. Propositional Statements: If someone has a rocket, that implies they're an astronaut. If someone is an astronaut, that implies they're highly trained. If someone is highly trained, that implies they're educated Conclusion Statement: A person is educated, that...
%%%%% c++ assignment %%%%%% ///////// please test your program and check for errors. //////// you should use the file bellow For this assignment you will write a program that creates a tree of "plants". Each plant is the result of an exeperiment. I have provided the main driver program that is responsible for running each of the experiments but you will need to create a tree for storing the results. The objective of this assignment is to learn how to...
For this assignment you will be creating a multi-file project in which you implement your own templated linked list and use it to create a simple list of composers. When doing this assignment, take small, incremental steps; trying to complete the lab in one go will make the lab more difficult. This means that any time you finish part of the lab, such as a linked list method, you should immediately test and debug it if necessary. Part 1: Creating...
In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all requests of allocation of memory space by different users (one thread per user) …. HINT(You will use Pthreads and Semaphores). Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management...
Your assignment is to write a grade book for a teacher. The
teacher has a text file, which includes student's names, and
students test grades. There are four test scores for each student.
Here is an example of such a file:
Count: 5
Sally 78.0 84.0 79.0 86.0
Rachel 68.0 76.0 87.0 76.0
Melba 87.0 78.0 98.0 88.0
Grace 76.0 67.0 89.0 0.0
Lisa 68.0 76.0 65.0 87.0
The first line of the file will indicate the number of students...
Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....
Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...
Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...
For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...