-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
User
authored and
User
committed
Oct 10, 2017
1 parent
cdaaa71
commit f9c8e14
Showing
10 changed files
with
69 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,3 +240,4 @@ ModelManifest.xml | |
|
||
# FAKE - F# Make | ||
.fake/ | ||
/Parse Infix/thoughts for consideration.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include "infix_evaluator.h" | ||
using namespace std; | ||
|
||
void main() { | ||
|
||
infix_evaluator test; | ||
string test_string = "+!!----"; | ||
test.eval_unaries(0, 7, 5, test_string); | ||
getchar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
#include "infix_evaluator.h" | ||
|
||
void infix_evaluator::eval_stack(int precedence) | ||
{ | ||
} | ||
//infix_string&, int start, length, operand. Can strip spaces | ||
int infix_evaluator::eval_unaries(int start, int length, int operand, string& infix_string) | ||
{ | ||
if (length == 0) | ||
return operand; | ||
else { | ||
int index = start + length - 1; | ||
char token = infix_string[index]; | ||
int count = 1; | ||
while (count < length && infix_string[index] == infix_string[index -1]) { | ||
count++; | ||
index--; | ||
} | ||
if (token == '!') { | ||
if (count % 2 == 0) | ||
eval_unaries(start, length - count, !!operand, infix_string); | ||
else | ||
eval_unaries(start, length - count, !operand, infix_string); | ||
}else if (token == '+') { | ||
if (count % 2 == 0) { | ||
for (int i = 0; i < count / 2; i++) { | ||
operand++; | ||
} | ||
eval_unaries(start, length - count, operand, infix_string); | ||
} | ||
else { | ||
cout << "Binary operator with single operand at index " << index; | ||
} | ||
}else if (token == '-') { | ||
if (count % 2 == 0) { | ||
for (int i = 0; i < count / 2; i++) { | ||
operand--; | ||
} | ||
eval_unaries(start, length - count, operand, infix_string); | ||
} | ||
else { | ||
cout << "Binary operator with single operand at index " << index; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
#pragma once | ||
|
||
#include "infix_to_postfix.h" | ||
#include<string> | ||
#include<stack> | ||
#include<iostream> | ||
using namespace std; | ||
|
||
class infix_to_postfix { | ||
class infix_evaluator { | ||
public: | ||
// @param infix_string is the infix expression to evaluate. | ||
// @return is the value of the string as a single integer | ||
int eval(string infix_string); | ||
private: | ||
//private: | ||
stack<int>operators; | ||
stack<char>operands; | ||
|
||
// evaluates the stacks as far as possible and pushes the result to operators stack. | ||
// @param precedence is the precedence of the next operator to be added to the stack. | ||
// evaluates the stacks as far as possible and pushes the result to operand stack. | ||
// @param precedence is the precedence of the next operator to be added to the operator stack. | ||
void eval_stack(int precedence); | ||
|
||
// evaluates one or many repeated +, -, or ! in a substring of infix_string | ||
// @param start is the first index of the substring | ||
// evaluates one or many repeated +, -, or ! in a substring of infix_string. Whitespace between | ||
// consecutive operators is ignored. | ||
// @param start is an interator to the first index of the substring in the infix_string | ||
// @param length is the length of the substring | ||
// @param operand is the operand which the unary operators will be applied to | ||
// @param operator_string is the string of one or many repeated + and/or - and/or ! | ||
// @return is the value of operand after unary operations have been applied. | ||
int eval_unaries(int start, int length, int operand); | ||
int eval_unaries(int start, int length, int operand, string& infix_string); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.