private static IParsingTreeVertex WorkRealSentence(String sentence) { int number = 0; ParsingStack stack = new ParsingStack(); Operation result = GetNeededOperation(sentence[1]); stack.Push(result); sentence = sentence.Remove(0, 3); while (sentence.Length != 0) { try { while (stack.Top().GetCount() == 2) { stack.Pop(); } } catch (StackNullExeption) { return(result); } switch (sentence[0]) { case '+': case '-': case '*': case '/': { Operation pushed = GetNeededOperation(sentence[0]); AddChildToStackTop(stack.Top(), pushed); stack.Push(pushed); sentence = sentence.Remove(0, 1); break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { number = ConvertToInt(ref sentence); Operand added = new Operand(number); number = 0; AddChildToStackTop(stack.Top(), added); break; } case '(': case ')': case ' ': { sentence = sentence.Remove(0, 1); break; } default: { throw new WrongInputException("Unexpected character \"" + sentence[0] + '\n'); } } } throw new ConstructorFailException("Didn't manage..."); }
private static IParsingTreeVertex WorkRealSentence(String sentence) { int number = 0; ParsingStack stack = new ParsingStack(); Operation result = GetNeededOperation(sentence[1]); stack.Push(result); sentence = sentence.Remove(0, 3); while (sentence.Length != 0) { try { while (stack.Top().GetCount() == 2) { stack.Pop(); } } catch(StackNullExeption) { return result; } switch (sentence[0]) { case '+': case '-': case '*': case '/': { Operation pushed = GetNeededOperation(sentence[0]); AddChildToStackTop(stack.Top(), pushed); stack.Push(pushed); sentence = sentence.Remove(0, 1); break; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { number = ConvertToInt(ref sentence); Operand added = new Operand(number); number = 0; AddChildToStackTop(stack.Top(), added); break; } case '(': case ')': case ' ': { sentence = sentence.Remove(0, 1); break; } default: { throw new WrongInputException("Unexpected character \"" + sentence[0] + '\n'); } } } throw new ConstructorFailException("Didn't manage..."); }
public void Initialization() { stack = new ParsingStack(); }