Skip to content

Instantly share code, notes, and snippets.

@spu95
spu95 / window.cs
Last active December 17, 2015 03:08
a nice piece of code created for a little project for ilc13
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;
@spu95
spu95 / calc.d
Created July 15, 2011 19:36
Shunting-Yard: Calc Shunted String
double calcShunt(string[] term) {
double[] rStack; // the result-Stack
string str; // actual part of the term
for (int i = 0; term.length &gt; i; i++) {
str = term[i];
// Numbers always go in the result stack
if (isNumber(str)) {
rStack ~= to!double(str);
@spu95
spu95 / calc.d
Created July 15, 2011 19:32
Shunting-Yard: Shunting
/**
* 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;
@spu95
spu95 / calc.d
Created July 15, 2011 19:29
Shunting-Yard: HelperFunctions
/**
* 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;
@spu95
spu95 / calc.d
Created July 15, 2011 19:23
Shunting-Yard: Utilities
static this() {
operations = [
'(' : MATH_OPERATION("(",
0,
MATH_ASSOCIATION.LEFT_ASSOC,
-1,
null )
/* the other ops... */
];
}
@spu95
spu95 / calc.d
Created July 15, 2011 19:22
Shunting-Yard: Operator-Struct
struct MATH_OPERATION
{
string op; // the Token
int parameter;
MATH_ASSOCIATION assoc;
int preced; // precedence
double function(double[]) calc;
};
@spu95
spu95 / calc.d
Created July 15, 2011 19:19
Shunting-Yard: Main-Function
/**
* 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);
@spu95
spu95 / calc.d
Created July 14, 2011 19:35
Calculator - Part: Lex
/**
* 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;