예제 #1
0
 /// <summary>
 /// Visits a <see cref="ParenthesisExpression"/>.
 /// </summary>
 /// <param name="parenthesisExpression">The parentheses expression.</param>
 /// <param name="value">The value.</param>
 /// <param name="currentResult">The current result.</param>
 public void Parenthesis(
     ParenthesisExpression parenthesisExpression,
     double value,
     Reference <double> currentResult)
 {
     currentResult.Value = this.Visit(parenthesisExpression.Expression);
 }
예제 #2
0
        public Node VisitExpression(ParenthesisExpression exp)
        {
            var  changed = false;
            Node newCode = exp;

            foreach (var edit in _edits)
            {
                if (edit.CanApply(exp))
                {
                    changed = true;
                    if (edit is Update)
                    {
                        newCode = edit.ModifiedNode.InnerNode;
                    }
                    else if (edit is Insert)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
            if (changed)
            {
                return(newCode);
            }

            return(new ParenthesisExpression(VisitExpression(exp.Expression)));
        }
        public void TestThatExpressionEvaluatesToEvaluatedInnerExpression()
        {
            var expr = new ParenthesisExpression(AnyExpression);

            expr.TryEvaluate(EmptyEnvironment, out string value).Should().BeTrue();
            value.Should().Be(EvaluatedAnyExpression);
        }
 /// <summary>
 /// Visits a <see cref="ParenthesisExpression" />.
 /// </summary>
 /// <param name="parenthesisExpression">The parenthesis expression.</param>
 /// <param name="conversionParameters">The conversion parameters.</param>
 /// <param name="conversionVariables">The conversion variables.</param>
 public void Parenthesis(
     ParenthesisExpression parenthesisExpression,
     ConversionParameters conversionParameters,
     ConversionVariables conversionVariables)
 {
     parenthesisExpression.Expression.Visit(this, conversionParameters, conversionVariables);
 }
        public override void ExplicitVisit(ParenthesisExpression node)
        {
            var function = node.Expression as FunctionCall;
            checkIsSuspected(function);

            base.ExplicitVisit(node);
        }
예제 #6
0
 void facteur(ref Expression ex)
 {
     if (la.kind == 1)
     {
         Get();
         if (StartOf(8))
         {
             ex = new VariableExpression {
                 Name = t.val, Location = new Location(t.line, t.col, t.charPos)
             };
         }
         else if (la.kind == 22)
         {
             ex = new MethodInvocationExpression {
                 Name = t.val, Location = new Location(t.line, t.col, t.charPos)
             }; List <Expression> el = null;
             Get();
             expr_list(ref el);
             (ex as MethodInvocationExpression).Arguments = el;
             Expect(23);
         }
         else
         {
             SynErr(61);
         }
     }
     else if (la.kind == 2)
     {
         Get();
         ex = new IntegralExpression {
             Value = int.Parse(t.val), Location = new Location(t.line, t.col, t.charPos)
         };
     }
     else if (la.kind == 22)
     {
         Expression target = null;
         Get();
         ex = new ParenthesisExpression {
             Location = new Location(t.line, t.col, t.charPos)
         };
         expr(ref target);
         (ex as ParenthesisExpression).Target = target;
         Expect(23);
     }
     else if (la.kind == 17)
     {
         Expression e = null;
         Get();
         ex = new UnaryOperationExpression {
             Location = new Location(t.line, t.col, t.charPos), Operator = Operators.LogicalNot
         };
         facteur(ref e);
         (ex as UnaryOperationExpression).Expression = e;
     }
     else
     {
         SynErr(62);
     }
 }
        public override void ExplicitVisit(ParenthesisExpression node)
        {
            var function = node.Expression as FunctionCall;

            checkIsSuspected(function);

            base.ExplicitVisit(node);
        }
예제 #8
0
        private void DeleteExpression(Expression expr)
        {
            NameExpression name = expr as NameExpression;

            if (name != null)
            {
                var var = Scope.CreateVariable(name, _unit, name.Name);

                return;
            }

            IndexExpression index = expr as IndexExpression;

            if (index != null)
            {
                var values      = _eval.Evaluate(index.Target);
                var indexValues = _eval.Evaluate(index.Index);
                foreach (var value in values)
                {
                    value.DeleteIndex(index, _unit, indexValues);
                }
                return;
            }

            MemberExpression member = expr as MemberExpression;

            if (member != null)
            {
                if (!string.IsNullOrEmpty(member.Name))
                {
                    var values = _eval.Evaluate(member.Target);
                    foreach (var value in values)
                    {
                        value.DeleteMember(member, _unit, member.Name);
                    }
                }
                return;
            }

            ParenthesisExpression paren = expr as ParenthesisExpression;

            if (paren != null)
            {
                DeleteExpression(paren.Expression);
                return;
            }

            SequenceExpression seq = expr as SequenceExpression;

            if (seq != null)
            {
                foreach (var item in seq.Items)
                {
                    DeleteExpression(item);
                }
                return;
            }
        }
예제 #9
0
        /// <summary>
        /// This method visits a parenthesis espression
        /// It accepts the left and right hand side and checks if there is an operator to accept also
        /// </summary>
        /// <param name="parenthesisExpression">The name of the node</param>
        /// <returns>It returns an expression</returns>
        public override object Visit(ParenthesisExpression parenthesisExpression)
        {
            string exp = "(";

            exp += parenthesisExpression.LeftHand.Accept(this);
            exp += parenthesisExpression.Operator?.Accept(this);
            exp += parenthesisExpression.RightHand?.Accept(this);
            exp += ")";
            return(exp);
        }
예제 #10
0
        private static PythonNode Wrap(ParenthesisExpression exp, PythonNode parent)
        {
            var result = new ParenthesisExpressionNode(exp)
            {
                Parent = parent
            };

            result.AddChild(Wrap(exp.Expression, result));
            return(result);
        }
예제 #11
0
 /// <summary>
 /// This method prints the paraenthesisExpression and then make an indentation
 /// It accepts the lef-and righthandside of the expresstion
 /// It accepts the operator if there exist any
 /// Then it outdent
 /// </summary>
 /// <param name="parenthesisExpression">The node to print.</param>
 /// <returns>Returns null</returns>
 public override object Visit(ParenthesisExpression parenthesisExpression)
 {
     Print("ParenthesisExpression");
     Indent++;
     parenthesisExpression.LeftHand.Accept(this);
     parenthesisExpression.Operator?.Accept(this);
     parenthesisExpression.RightHand?.Accept(this);
     Indent--;
     return(null);
 }
예제 #12
0
        /// <summary>
        /// Generates the code for a ParenthesisExpression node.
        /// </summary>
        /// <param name="pe">The ParenthesisExpression node.</param>
        /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
        private void GenerateParenthesisExpression(ParenthesisExpression pe, StringBuilder sb)
        {
            string retstr = String.Empty;

            Generate("(", sb);
            foreach (SYMBOL kid in pe.kids)
            {
                GenerateNodeToSB(pe, kid, sb);
            }
            Generate(")", sb);
        }
예제 #13
0
 protected IExpression MayNegate(IExpression expression)
 {
     if (negate)
     {
         if (expression is BinaryOperationExpression)
         {
             expression = new ParenthesisExpression(null, expression);
         }
         expression = new UnaryOperationExpression(null, UnaryOperator.Not, expression);
     }
     return(expression);
 }
        public void maxDepth_Test_1_11_1111_1()
        {
            // Arrange
            string s             = "(()((())))";
            int    expectedDepth = 4;

            // Act
            int result = ParenthesisExpression.maxDepth(s);

            // Assert
            Assert.AreEqual(expectedDepth, result);
        }
예제 #15
0
파일: DDG.cs 프로젝트: rsumner33/PTVS
        private void DeleteExpression(Expression expr)
        {
            NameExpression name = expr as NameExpression;

            if (name != null)
            {
                var variable = _eval.LookupVariableByName(name.Name, expr);
                if (variable != null)
                {
                    variable.AddReference(name, _unit);
                }
            }

            IndexExpression index = expr as IndexExpression;

            if (index != null)
            {
                var values      = _eval.Evaluate(index.Target);
                var indexValues = _eval.Evaluate(index.Index);
                foreach (var value in values)
                {
                    value.DeleteIndex(index, _unit, indexValues);
                }
            }

            MemberExpression member = expr as MemberExpression;

            if (member != null)
            {
                var values = _eval.Evaluate(member.Target);
                foreach (var value in values)
                {
                    value.DeleteMember(member, _unit, member.Name);
                }
            }

            ParenthesisExpression paren = expr as ParenthesisExpression;

            if (paren != null)
            {
                DeleteExpression(paren.Expression);
            }

            SequenceExpression seq = expr as SequenceExpression;

            if (seq != null)
            {
                foreach (var item in seq.Items)
                {
                    DeleteExpression(item);
                }
            }
        }
        /// <summary>
        /// Adds mo tags for the parethesis and visits the child expression.
        /// </summary>
        /// <param name="parenthesisExpression">The parenthesis expression.</param>
        /// <param name="multiplicationSign">The multiplication sign.</param>
        /// <param name="xElement">The x element.</param>
        public void Parenthesis(
            ParenthesisExpression parenthesisExpression,
            MultiplicationSign multiplicationSign,
            XElement xElement)
        {
            var mrow = new XElement(MathML.Mrow);

            xElement.Add(mrow);
            mrow.Add(new XElement(MathML.Mo, LeftParenthesis));
            parenthesisExpression.Expression.Visit(this, multiplicationSign, mrow);
            mrow.Add(new XElement(MathML.Mo, RightParenthesis));
        }
예제 #17
0
        private IExpression Atom()
        {
            IExpression atom;

            switch (lookAhead.Type)
            {
            case ExpressionTokenType.Identifier:
                return(Identifier());

            case ExpressionTokenType.LeftParen:
                NextToken();
                atom = Expression();
                if (lookAhead.Type != ExpressionTokenType.RightParen)
                {
                    throw UnexpectedTokenException("Expected ')'.");
                }
                atom = new ParenthesisExpression(atom);
                break;

            case ExpressionTokenType.Text:
                var text = lookAhead.Sequence.Substring(1, lookAhead.Sequence.Length - 2);
                atom = new Text(text);
                break;

            case ExpressionTokenType.Integer:
                var integer = long.Parse(lookAhead.Sequence, CultureInfo.InvariantCulture);
                atom = new Integer(integer);
                break;

            case ExpressionTokenType.Decimal:
                var number = double.Parse(lookAhead.Sequence, CultureInfo.InvariantCulture);
                atom = new Number(number);
                break;

            case ExpressionTokenType.True:
            case ExpressionTokenType.False:
                var boolean = lookAhead.Sequence.ToLowerInvariant() == "true";
                atom = new Boolean(boolean);
                break;

            case ExpressionTokenType.RegexPattern:
                var pattern = lookAhead.Sequence.Substring(1, lookAhead.Sequence.Length - 2);
                atom = new RegExp(pattern);
                break;

            default:
                throw UnexpectedTokenException();
            }

            NextToken();
            return(atom);
        }
예제 #18
0
        /// <summary>
        /// Generates the code for a ParenthesisExpression node.
        /// </summary>
        /// <param name="pe">The ParenthesisExpression node.</param>
        /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
        private string GenerateParenthesisExpression(ParenthesisExpression pe)
        {
            string retstr = String.Empty;

            retstr += Generate("(");
            foreach (SYMBOL kid in pe.kids)
            {
                retstr += GenerateNode(kid);
            }
            retstr += Generate(")");

            return(retstr);
        }
        /// <summary>
        /// Visits a <see cref="ParenthesisExpression" />.
        /// </summary>
        /// <param name="parenthesisExpression">The parentheses expression.</param>
        /// <param name="notationParameters">The notation parameters.</param>
        /// <param name="notationVariables">The notation variables.</param>
        public void Parenthesis(
            ParenthesisExpression parenthesisExpression,
            NotationParameters notationParameters,
            NotationVariables notationVariables)
        {
            var requestPrecendence = notationVariables.RequestPrecedence;
            var stringBuilder      = notationParameters.StringBuilder;

            this.HandleLeftPrecedence(requestPrecendence, stringBuilder);
            stringBuilder.Append(Constants.LeftParenthesis);
            parenthesisExpression.Expression.Visit(this, notationParameters, new NotationVariables(false, true));
            stringBuilder.Append(Constants.RightParenthesis);
            this.HandleRightPrecedence(requestPrecendence, stringBuilder);
        }
예제 #20
0
 /// <summary>
 /// Visits a <see cref="ParenthesisExpression" />.
 /// </summary>
 /// <param name="parenthesisExpression">The parentheses expression.</param>
 /// <param name="rewritingParameters">The rewriting parameters.</param>
 /// <param name="currentResult">The current result.</param>
 public void Parenthesis(
     ParenthesisExpression parenthesisExpression,
     RewritingParameters rewritingParameters,
     Reference <Expression> currentResult)
 {
     parenthesisExpression.Expression.Visit(this, rewritingParameters, currentResult);
     if (ReferenceEquals(parenthesisExpression.Expression, currentResult.Value))
     {
         currentResult.Value = parenthesisExpression;
     }
     else
     {
         currentResult.Value = new ParenthesisExpression(currentResult.Value);
     }
 }
        public override void ExplicitVisit(ParenthesisExpression node)
        {
            //Console.WriteLine(prefix + "(");
            //
            //using (new_PrefixScope())
            //{
            //    // the expression can result into: nothing, expression, literal or column
            //    //ParenthesisExpressionVisitor vstor = new ParenthesisExpressionVisitor();
            //    node.Expression.Accept(this);
            //    //if (vstor.result == null)
            //    //{
            //    //    throw new NotImplementedException(node.AsText());
            //    //}
            //}
            //
            //Console.WriteLine(prefix + ")");

            this.lastExpression = TryBuildFromNode(node.Expression, ref lastHasError, ref lastError);
        }
예제 #22
0
        protected override ASTNode FoldParenthesisExpression(ParenthesisExpression node, params Object[] args)
        {
            node = ( ParenthesisExpression )base.FoldParenthesisExpression(node, args);

            if (node.Parent is ParenthesisExpression)
            {
                return(node.Expression);
            }
            else if (node.Expression is ConstantExpression && !(node.Parent is MemberExpression || node.Parent is IndexExpression))
            {
                return(node.Expression);
            }
            if (node.Expression is BinaryOperatorExpression childExpr && node.Parent is BinaryOperatorExpression parentExpr)
            {
                return(ParserData.OpPriorities[childExpr.Operator][0] < ParserData.OpPriorities[parentExpr.Operator][0]
                    ? node : node.Expression);
            }

            return(node);
        }
예제 #23
0
 // ParenthesisExpression
 public override bool Walk(ParenthesisExpression node) { return false; }
예제 #24
0
 public override bool Walk(ParenthesisExpression node) => Save(node, base.Walk(node), _options.ParenthesisedExpression);
예제 #25
0
 protected virtual ASTNode FoldParenthesisExpression(ParenthesisExpression node, params Object[] args)
 {
     node.SetExpression(this.Fold(node.Expression));
     return(node);
 }
예제 #26
0
 public override void PostWalk(ParenthesisExpression node)
 {
 }
예제 #27
0
 // ParenthesisExpression
 public override bool Walk(ParenthesisExpression node)
 {
     return(false);
 }
 public override void ExplicitVisit(ParenthesisExpression fragment)
 {
     _fragments.Add(fragment);
 }
예제 #29
0
 public virtual void PostWalk(ParenthesisExpression node) { }
예제 #30
0
 // ParenthesisExpression
 public override bool Walk(ParenthesisExpression node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
예제 #31
0
 // ParenthesisExpression
 public override bool Walk(ParenthesisExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
예제 #32
0
 protected virtual Object[] AnalyseParenthesisExpression(ParenthesisExpression node, params Object[] args)
 {
     this.Analyse(node.Expression);
     return(null);
 }
예제 #33
0
        /// <summary>
        ///     Generates the code for a ParenthesisExpression node.
        /// </summary>
        /// <param name="pe">The ParenthesisExpression node.</param>
        /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
        private string GenerateParenthesisExpression(ParenthesisExpression pe)
        {
            StringBuilder retVal = new StringBuilder();
            retVal.Append(Generate("("));
            foreach (SYMBOL kid in pe.kids)
                retVal.Append(GenerateNode(kid));
            retVal.Append(Generate(")"));

            return retVal.ToString();
        }
예제 #34
0
        /// <summary>
        ///   Generates the code for a ParenthesisExpression node.
        /// </summary>
        /// <param name = "pe">The ParenthesisExpression node.</param>
        /// <returns>String containing C# code for ParenthesisExpression pe.</returns>
        private string GenerateParenthesisExpression(ParenthesisExpression pe)
        {
            string retstr = "";

            retstr += Generate("(");
            foreach (SYMBOL kid in pe.kids)
                retstr += GenerateNode(kid);
            retstr += Generate(")");

            return retstr;
        }
예제 #35
0
 public override void PostWalk(ParenthesisExpression node) { }
예제 #36
0
 // ParenthesisExpression
 public virtual bool Walk(ParenthesisExpression node)
 {
     return(true);
 }
예제 #37
0
 // ParenthesisExpression
 public virtual bool Walk(ParenthesisExpression node) { return true; }
예제 #38
0
 public virtual void PostWalk(ParenthesisExpression node)
 {
 }
예제 #39
0
 public override void VisitParenthesisExpression(ParenthesisExpression x)
 {
     ConsumeToken(Tokens.T_LPAREN, "(", x.Span.Start);
     VisitElement(x.Expression);
     ConsumeToken(Tokens.T_RPAREN, ")", x.Span.End - 1);
 }
예제 #40
0
 public override void Visit(ParenthesisExpression node) { this.action(node); }