コード例 #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.cs プロジェクト: 0xb1dd1e/NRefactory
		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
ファイル: CSharpSyntaxMode.cs プロジェクト: thild/monodevelop
            //		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
ファイル: CSharpSyntaxMode.cs プロジェクト: thild/monodevelop
 public override SpanParser CreateSpanParser(Mono.TextEditor.Document doc, SyntaxMode mode, LineSegment line, CloneableStack <Span> spanStack)
 {
     return(new CSharpSpanParser(doc, mode, spanStack ?? line.StartSpan.Clone()));
 }
コード例 #9
0
 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
ファイル: DSyntaxMode.cs プロジェクト: foerdi/Mono-D
 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)
			{
			}
コード例 #20
0
 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
ファイル: DSyntaxMode.cs プロジェクト: lenoil98/Mono-D
 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
ファイル: JaySyntaxMode.cs プロジェクト: nocache/monodevelop
		public override SpanParser CreateSpanParser (DocumentLine line, CloneableStack<Span> spanStack)
		{
			return new JaySpanParser (this, spanStack ?? line.StartSpan.Clone ());
		}
コード例 #26
0
ファイル: SyntaxMode.cs プロジェクト: nieve/monodevelop
		public virtual SpanParser CreateSpanParser (Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack)
		{
			return new SpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ());
		}
コード例 #27
0
		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
ファイル: JaySyntaxMode.cs プロジェクト: nocache/monodevelop
			public JaySpanParser (SyntaxMode mode, CloneableStack<Span> spanStack) : base (mode, spanStack)
			{
			}
コード例 #29
0
ファイル: AspNetSyntaxMode.cs プロジェクト: txdv/monodevelop
		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
ファイル: SyntaxMode.cs プロジェクト: nieve/monodevelop
			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
ファイル: SyntaxMode.cs プロジェクト: llucenic/monodevelop
			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)
			{}