This file contains hidden or 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
using System.Reflection; | |
using System.Windows; | |
using System.Windows.Media; | |
namespace ILC13_A4_GUI { | |
static class DynamicHelper { | |
public static void Merge<T>(T obj, dynamic dyn) { | |
foreach (var prop in dyn.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { | |
var k = prop.Name; |
This file contains hidden or 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
double calcShunt(string[] term) { | |
double[] rStack; // the result-Stack | |
string str; // actual part of the term | |
for (int i = 0; term.length > i; i++) { | |
str = term[i]; | |
// Numbers always go in the result stack | |
if (isNumber(str)) { | |
rStack ~= to!double(str); |
This file contains hidden or 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
/** | |
* The shunting yard algorythm transfers the term into | |
* the polnish reverse notation | |
*/ | |
string[] shuntingYard(string[] lxdTerm) { | |
MATH_OPERATION[] opStack; | |
MATH_OPERATION *pCurOp; | |
string[] output; | |
string str; |
This file contains hidden or 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
/** | |
* helper methods, which check the input | |
*/ | |
bool isOperation(char c) { | |
if (c == '*' || c == '/' || c == '-' || c == '+' || c == '%' | |
|| c == '(' || c == ')' || c == '^' || c == '!') { | |
return true; | |
} else { | |
return false; |
This file contains hidden or 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
static this() { | |
operations = [ | |
'(' : MATH_OPERATION("(", | |
0, | |
MATH_ASSOCIATION.LEFT_ASSOC, | |
-1, | |
null ) | |
/* the other ops... */ | |
]; | |
} |
This file contains hidden or 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
struct MATH_OPERATION | |
{ | |
string op; // the Token | |
int parameter; | |
MATH_ASSOCIATION assoc; | |
int preced; // precedence | |
double function(double[]) calc; | |
}; |
This file contains hidden or 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
/** | |
* Calculate the string term | |
*/ | |
public double calculate(string term) | |
{ | |
string[] lxdTerm; // Our lexed term string | |
string[] output; // The shunting yard string | |
// At first we have to lex the term | |
lxdTerm = lexStr(term); |
This file contains hidden or 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
/** | |
* The lexer split the term into numbers, functions, | |
* math operatoin and variables | |
*/ | |
string[] lexStr(string term) { | |
string[] lxdTerm; | |
char[] tmpNr; | |
char c; | |
int i = 0; |