Пример #1
0
        /// <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));
        }
Пример #2
0
        /// <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;
        }
Пример #3
0
		Indent(Indent engine)
		{
			this.indentStack = engine.indentStack.Clone();
			this.options = engine.options;
			this.curIndent = engine.curIndent;
			this.extraSpaces = engine.extraSpaces;
			this.indentString = engine.indentString;
		}
Пример #4
0
 Indent(Indent engine)
 {
     this.indentStack  = engine.indentStack.Clone();
     this.options      = engine.options;
     this.curIndent    = engine.curIndent;
     this.extraSpaces  = engine.extraSpaces;
     this.indentString = engine.indentString;
 }
Пример #5
0
            //		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);
//					}
//				}
            }
Пример #6
0
            //		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);
//					}
//				}
            }
Пример #7
0
        /// <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);
        }
Пример #8
0
 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 ());
 }
Пример #10
0
 protected LineDescriptor(DocumentLine line, int offset, int length)
 {
     this.Offset = offset;
     this.Length = length;
     this.Spans = line.StartSpan;
 }
Пример #11
0
 public DSpanParser(DSyntaxMode syn, DocumentLine line, CloneableStack<Span> spanStack)
     : base(syn, spanStack)
 {
 }
Пример #12
0
 public override SpanParser CreateSpanParser(DocumentLine line, CloneableStack <Span> spanStack)
 {
     return(new CSharpSpanParser(this, spanStack ?? line.StartSpan.Clone()));
 }
Пример #13
0
 public ASPNetSpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack)
 {
 }
Пример #14
0
		public virtual SpanParser CreateSpanParser (DocumentLine line, CloneableStack<Span> spanStack)
		{
			return new SpanParser (this, spanStack ?? line.StartSpan.Clone ());
		}
Пример #15
0
 public void SetInfix(string infix)
 {
     this.infix = infix;
     expression = InfixToRPN(Parse(infix));
 }
Пример #16
0
 public ExpressionD(string infix)
 {
     this.infix = infix;
     expression = InfixToRPN(Parse(infix));
 }
Пример #17
0
 protected LineDescriptor(DocumentLine line, int offset, int length)
 {
     this.Offset = offset;
     this.Length = length;
     this.Spans  = line.StartSpan;
 }
Пример #18
0
		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);
		}
Пример #19
0
			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));
 }
Пример #21
0
	//		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);
//					}
//				}
			}
Пример #22
0
 public DSpanParser(DSyntaxMode syn, DocumentLine line, CloneableStack <Span> spanStack)
     : base(syn, spanStack)
 {
 }
Пример #23
0
 public ASPNetSpanParser(Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack <Span> spanStack) : base(doc, mode, spanStack)
 {
 }
Пример #24
0
		public override SpanParser CreateSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack)
		{
			return new CSharpSpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ());
		}
Пример #25
0
		public override SpanParser CreateSpanParser (DocumentLine line, CloneableStack<Span> spanStack)
		{
			return new JaySpanParser (this, spanStack ?? line.StartSpan.Clone ());
		}
Пример #26
0
		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);
		}
Пример #28
0
			public JaySpanParser (SyntaxMode mode, CloneableStack<Span> spanStack) : base (mode, spanStack)
			{
			}
Пример #29
0
		public override SpanParser CreateSpanParser (LineSegment line, CloneableStack<Span> spanStack)
		{
			return new ASPNetSpanParser (this, spanStack ?? line.StartSpan.Clone ());
		}
Пример #30
0
 public override SpanParser CreateSpanParser(Mono.TextEditor.DocumentLine line, CloneableStack <Span> spanStack)
 {
     return(new GherkinSpanParser(this, spanStack ?? line.StartSpan.Clone()));
 }
Пример #31
0
 public GherkinSpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack)
 {
 }
Пример #32
0
			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) {};
			}
Пример #33
0
			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) {};
			}
Пример #34
0
		/// <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;
		}
Пример #35
0
			public ASPNetSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) : base (doc, mode, spanStack)
			{}