/// <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); }
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); }
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); } }
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; } }
/// <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); }
private static PythonNode Wrap(ParenthesisExpression exp, PythonNode parent) { var result = new ParenthesisExpressionNode(exp) { Parent = parent }; result.AddChild(Wrap(exp.Expression, result)); return(result); }
/// <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); }
/// <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); }
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); }
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)); }
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); }
/// <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); }
/// <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); }
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); }
// ParenthesisExpression public override bool Walk(ParenthesisExpression node) { return false; }
public override bool Walk(ParenthesisExpression node) => Save(node, base.Walk(node), _options.ParenthesisedExpression);
protected virtual ASTNode FoldParenthesisExpression(ParenthesisExpression node, params Object[] args) { node.SetExpression(this.Fold(node.Expression)); return(node); }
public override void PostWalk(ParenthesisExpression node) { }
// ParenthesisExpression public override bool Walk(ParenthesisExpression node) { return(false); }
public override void ExplicitVisit(ParenthesisExpression fragment) { _fragments.Add(fragment); }
public virtual void PostWalk(ParenthesisExpression node) { }
// ParenthesisExpression public override bool Walk(ParenthesisExpression node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
// ParenthesisExpression public override bool Walk(ParenthesisExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
protected virtual Object[] AnalyseParenthesisExpression(ParenthesisExpression node, params Object[] args) { this.Analyse(node.Expression); return(null); }
/// <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(); }
/// <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; }
// ParenthesisExpression public virtual bool Walk(ParenthesisExpression node) { return(true); }
// ParenthesisExpression public virtual bool Walk(ParenthesisExpression node) { return true; }
public override void VisitParenthesisExpression(ParenthesisExpression x) { ConsumeToken(Tokens.T_LPAREN, "(", x.Span.Start); VisitElement(x.Expression); ConsumeToken(Tokens.T_RPAREN, ")", x.Span.End - 1); }
public override void Visit(ParenthesisExpression node) { this.action(node); }