/// <summary> /// Evaluates the expression /// </summary> /// <returns>The result of evaluation</returns> public double Evaluate() { //Create a clone of expression because we don't want to mess with it CloneableStack <Symbol> expr = expression.Clone(); Stack <Symbol> tempStack = new Stack <Symbol>(); double[] values; while (expr.Count() > 0) { if (!expr.Peek().isOperator) { tempStack.Push(expr.Pop()); } else { //Pop values, tempStack should only be 0 op symbols values = new double[expr.Peek().nOps]; for (int i = 0; i < values.Length; i++) { values[i] = tempStack.Pop().eval(null); } tempStack.Push(new Symbol(expr.Pop().eval(values))); } } return(tempStack.Pop().eval(null)); }
/// <summary> /// Creates a new AlIndentEngine instance from the given prototype. /// </summary> /// <param name="prototype"> /// An AlIndentEngine instance. /// </param> public AlIndentEngine(AlIndentEngine prototype) { this.formattingOptions = prototype.formattingOptions; this.textEditorOptions = prototype.textEditorOptions; this.document = prototype.document; this.newLineChar = prototype.newLineChar; this.currentState = prototype.currentState.Clone(this); this.conditionalSymbols = new HashSet <string>(prototype.conditionalSymbols); this.customConditionalSymbols = new HashSet <string>(prototype.customConditionalSymbols); this.wordToken = new StringBuilder(prototype.wordToken.ToString()); this.previousKeyword = string.Copy(prototype.previousKeyword); this.offset = prototype.offset; this.line = prototype.line; this.column = prototype.column; this.isLineStart = prototype.isLineStart; this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken; this.currentChar = prototype.currentChar; this.previousChar = prototype.previousChar; this.previousNewline = prototype.previousNewline; this.currentIndent = new StringBuilder(prototype.CurrentIndent.ToString()); this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment; this.lineBeganInsideVerbatimString = prototype.lineBeganInsideVerbatimString; this.ifDirectiveEvalResults = prototype.ifDirectiveEvalResults.Clone(); this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone(); this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels; }
Indent(Indent engine) { this.indentStack = engine.indentStack.Clone(); this.options = engine.options; this.curIndent = engine.curIndent; this.extraSpaces = engine.extraSpaces; this.indentString = engine.indentString; }
// Span preprocessorSpan; // Rule preprocessorRule; public CSharpSpanParser(CSharpSyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack) { // foreach (Span span in mode.Spans) { // if (span.Rule == "text.preprocessor") { // preprocessorSpan = span; // preprocessorRule = GetRule (span); // } // } }
// Span preprocessorSpan; // Rule preprocessorRule; public CSharpSpanParser(Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack <Span> spanStack) : base(doc, mode, spanStack) { // foreach (Span span in mode.Spans) { // if (span.Rule == "text.preprocessor") { // preprocessorSpan = span; // preprocessorRule = GetRule (span); // } // } }
/// <summary> /// Converts an infix expression represented an array of strings to a /// corresponding RPN expression as a stack. /// </summary> /// <param name="inputTokens"></param> /// <returns></returns> private CloneableStack <Symbol> InfixToRPN(string[] inputTokens) { //ArrayList outList = new ArrayList(); CloneableStack <Symbol> result = new CloneableStack <Symbol>(0); Stack <string> stack = new Stack <string>(); //for all the input tokens read the next token foreach (string token in inputTokens) { if (IsOperator(token)) { //If token is an operator while (stack.Count != 0 && IsOperator(stack.Peek())) { if ((IsAssociative(token, LEFT_ASSOC) && CmpPrecedence(token, stack.Peek()) <= 0) || (IsAssociative(token, RIGHT_ASSOC) && CmpPrecedence(token, stack.Peek()) < 0)) { result.Push(ToSymbol(stack.Pop())); continue; } break; } //Push the new operator on the stack stack.Push(token); } else if (token.Equals("(")) { stack.Push(token); } else if (token.Equals(")")) { while (stack.Count != 0 && !stack.Peek().Equals("(")) { result.Push(ToSymbol(stack.Pop())); } stack.Pop(); } else { result.Push(ToSymbol(token)); } } while (stack.Count != 0) { result.Push(ToSymbol(stack.Pop())); } CloneableStack <Symbol> actualResult = new CloneableStack <Symbol>(result.Count()); while (result.Count() > 0) { actualResult.Push(result.Pop()); } return(actualResult); }
public override SpanParser CreateSpanParser(Mono.TextEditor.Document doc, SyntaxMode mode, LineSegment line, CloneableStack <Span> spanStack) { return(new CSharpSpanParser(doc, mode, spanStack ?? line.StartSpan.Clone())); }
public override SpanParser CreateSpanParser(Mono.TextEditor.DocumentLine line, CloneableStack<Span> spanStack) { return new GherkinSpanParser (this, spanStack ?? line.StartSpan.Clone ()); }
protected LineDescriptor(DocumentLine line, int offset, int length) { this.Offset = offset; this.Length = length; this.Spans = line.StartSpan; }
public DSpanParser(DSyntaxMode syn, DocumentLine line, CloneableStack<Span> spanStack) : base(syn, spanStack) { }
public override SpanParser CreateSpanParser(DocumentLine line, CloneableStack <Span> spanStack) { return(new CSharpSpanParser(this, spanStack ?? line.StartSpan.Clone())); }
public ASPNetSpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack) { }
public virtual SpanParser CreateSpanParser (DocumentLine line, CloneableStack<Span> spanStack) { return new SpanParser (this, spanStack ?? line.StartSpan.Clone ()); }
public void SetInfix(string infix) { this.infix = infix; expression = InfixToRPN(Parse(infix)); }
public ExpressionD(string infix) { this.infix = infix; expression = InfixToRPN(Parse(infix)); }
public static void ScanSpans (Document doc, SyntaxMode mode, Rule rule, CloneableStack<Span> spanStack, int start, int end) { SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack); parser.ParseSpans (start, end - start); }
public JaySpanParser (Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) : base (doc, mode, spanStack) { }
public override SpanParser CreateSpanParser(Mono.TextEditor.DocumentLine line, CloneableStack <Span> spanStack) { return(syntaxMode.CreateSpanParser(line, spanStack)); }
// Span preprocessorSpan; // Rule preprocessorRule; public CSharpSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) : base (doc, mode, spanStack) { // foreach (Span span in mode.Spans) { // if (span.Rule == "text.preprocessor") { // preprocessorSpan = span; // preprocessorRule = GetRule (span); // } // } }
public DSpanParser(DSyntaxMode syn, DocumentLine line, CloneableStack <Span> spanStack) : base(syn, spanStack) { }
public ASPNetSpanParser(Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack <Span> spanStack) : base(doc, mode, spanStack) { }
public override SpanParser CreateSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack) { return new CSharpSpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ()); }
public override SpanParser CreateSpanParser (DocumentLine line, CloneableStack<Span> spanStack) { return new JaySpanParser (this, spanStack ?? line.StartSpan.Clone ()); }
public virtual SpanParser CreateSpanParser (Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack) { return new SpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ()); }
public static void ScanSpans (TextDocument doc, SyntaxMode mode, Rule rule, CloneableStack<Span> spanStack, int start, int end) { if (mode == null) return; SyntaxMode.SpanParser parser = mode.CreateSpanParser (null, spanStack); parser.ParseSpans (start, end - start); }
public JaySpanParser (SyntaxMode mode, CloneableStack<Span> spanStack) : base (mode, spanStack) { }
public override SpanParser CreateSpanParser (LineSegment line, CloneableStack<Span> spanStack) { return new ASPNetSpanParser (this, spanStack ?? line.StartSpan.Clone ()); }
public override SpanParser CreateSpanParser(Mono.TextEditor.DocumentLine line, CloneableStack <Span> spanStack) { return(new GherkinSpanParser(this, spanStack ?? line.StartSpan.Clone())); }
public GherkinSpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack) { }
public SpanParser (Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) { if (doc == null) throw new ArgumentNullException ("doc"); this.doc = doc; this.mode = mode; this.SpanStack = spanStack; this.CurRule = mode; this.ruleStack = CreateRuleStack (); this.CurRule = ruleStack.Peek (); this.CurSpan = spanStack.Count > 0 ? spanStack.Peek () : null; FoundSpanBegin = DefaultFoundSpanBegin; FoundSpanEnd = DefaultFoundSpanEnd; FoundSpanExit = DefaultFoundSpanEnd; ParseChar = delegate (ref int i, char ch) {}; }
public SpanParser (SyntaxMode mode, CloneableStack<Span> spanStack) { if (mode == null) throw new ArgumentNullException ("mode"); this.doc = mode.Document; if (this.doc == null) throw new ArgumentException ("Syntax mode isn't bound to any document.", "mode"); this.mode = mode; this.SpanStack = spanStack; this.CurRule = mode; this.ruleStack = CreateRuleStack (); this.CurRule = ruleStack.Peek (); this.CurSpan = spanStack.Count > 0 ? spanStack.Peek () : null; FoundSpanBegin = DefaultFoundSpanBegin; FoundSpanEnd = DefaultFoundSpanEnd; FoundSpanExit = DefaultFoundSpanEnd; ParseChar = delegate (ref int i, char ch) {}; }
/// <summary> /// Creates a new CSharpIndentEngine instance from the given prototype. /// </summary> /// <param name="prototype"> /// An CSharpIndentEngine instance. /// </param> public CSharpIndentEngine(CSharpIndentEngine prototype) { this.formattingOptions = prototype.formattingOptions; this.textEditorOptions = prototype.textEditorOptions; this.document = prototype.document; this.newLineChar = prototype.newLineChar; this.currentState = prototype.currentState.Clone(this); this.conditionalSymbols = new HashSet<string>(prototype.conditionalSymbols); this.customConditionalSymbols = new HashSet<string>(prototype.customConditionalSymbols); this.wordToken = new StringBuilder(prototype.wordToken.ToString()); this.previousKeyword = string.Copy(prototype.previousKeyword); this.offset = prototype.offset; this.line = prototype.line; this.column = prototype.column; this.isLineStart = prototype.isLineStart; this.isLineStartBeforeWordToken = prototype.isLineStartBeforeWordToken; this.currentChar = prototype.currentChar; this.previousChar = prototype.previousChar; this.previousNewline = prototype.previousNewline; this.currentIndent = new StringBuilder(prototype.CurrentIndent.ToString()); this.lineBeganInsideMultiLineComment = prototype.lineBeganInsideMultiLineComment; this.lineBeganInsideVerbatimString = prototype.lineBeganInsideVerbatimString; this.ifDirectiveEvalResults = prototype.ifDirectiveEvalResults.Clone(); this.ifDirectiveIndents = prototype.ifDirectiveIndents.Clone(); this.EnableCustomIndentLevels = prototype.EnableCustomIndentLevels; }
public ASPNetSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) : base (doc, mode, spanStack) {}