private Expression ParsePrefixExpression() { PrefixExpression exp = new PrefixExpression(); exp.Token = _currentToken; exp.Operator = _currentToken.Literal; ReadNextToken(); exp.Right = ParseExpression(Precedence.PREFIX); return(exp); }
private Expression ParsePrefixExpression() { var exp = new PrefixExpression(); exp.Token = this._curToken; exp.Operator = this._curToken.Literal; this.NextToken(); exp.Right = this.ParseExpression(Precedence.PREFIX); return(exp); }
private IExpression ParsePrefixExpression() { var expression = new PrefixExpression(currentToken, currentToken.Literal); NextToken(); expression.Right = ParseExpression(ExpressionType.Prefix); return(expression); }
public static Object.Object EvalPrefixExpression(PrefixExpression expression) { Object.Object right = Eval(expression.Right); Object.IntegerObject rightInteger = right as Object.IntegerObject; if(rightInteger == null) { throw new Exception("Prefix expression right is not Object.IntegerObject"); } return new Object.IntegerObject { Value = -1 * rightInteger.Value }; }
private IExpression ParsePrefixExpression() { var pe = new PrefixExpression { Token = CurToken, Operator = CurToken.Literal }; NextToken(); pe.Right = ParseExpression(PREFIX); return(pe); }
public void BuildExpressionTree_Should_Create_ExpressionTree_From_PrefixExpression(string prefixExpressionValue) { IPrefixExpression prefixExpression = new PrefixExpression(prefixExpressionValue); var tree = prefixExpression.BuildExpressionTree(); tree.GetNodes() .Select(n => n.Value) .Should() .BeEquivalentTo(prefixExpression.ParseExpression().Value); }
/* Parses functionCall * prefixExpression arguments | * prefixExpression ':' Identifier arguments */ Statement FunctionCall(PrefixExpression prefixExpr) { var functionCall = prefixExpr.LiftFunctionCall(); if (functionCall == null) { throw new LuaSyntaxException(input, ExceptionMessage.UNEXPECTED_SYMBOL, lexer.Current.Symbol); } return(new Statement.FunctionCall(functionCall)); }
private IExpression ParsePrefixExpression() { var expression = new PrefixExpression { Token = curToken, Operator = curToken.Literal }; NextToken(); expression.Right = ParseExpression(Precedence.Prefix); return(expression); }
public IExpression ParsePrefixExpression() { var expression = new PrefixExpression() { Token = this.CurrentToken, Operator = this.CurrentToken.Literal }; this.ReadToken(); expression.Right = this.ParseExpression(Precedence.PREFIX); return(expression); }
private IExpression ParsePrefixExpression() { var expr = new PrefixExpression { Token = currentToken, Operator = currentToken.Literal }; // move past prefix token NextToken(); expr.Right = ParseExpression(Precedence.Prefix); return(expr); }
private IExpression ParsePrefixExpression() { var expression = new PrefixExpression { Token = _currentToken, Operator = _currentToken.Literal }; NextToken(); expression.Right = ParseExpression(Precedences.PREFIX); return(expression); }
public void Parser_CanParsePrefixExpressions(string input, TokenType expectedOperator, int expectedValue) { AST result = this.subject.ParseProgram(input); Assert.Equal(1, result.Program.Statements.Count); Assert.Empty(result.Errors); ExpressionStatement stmt = this.AssertAndCast <ExpressionStatement>(result.Program.Statements[0]); PrefixExpression exp = this.AssertAndCast <PrefixExpression>(stmt.Expression); Assert.Equal(expectedOperator, exp.Operator); IntegerLiteral intExpression = this.AssertAndCast <IntegerLiteral>(exp.Right); Assert.Equal(expectedValue, intExpression.Value); }
/* Parses assign * variableList '=' expressionList */ Statement Assign(PrefixExpression prefixExpr) { var variable = prefixExpr.LiftVariable(); if (variable == null) { throw new LuaSyntaxException(input, ExceptionMessage.UNEXPECTED_SYMBOL, lexer.Current.Symbol); } var variables = lexer.Current.Symbol == Symbol.Comma ? VariableList(variable) : new List <Variable> { variable }; lexer.Expect(Symbol.Equal); var expressions = ExpressionList(); return(new Statement.Assign(variables, expressions)); }
public void Nandify_Should_Create_ExpressionTree_From_PrefixExpression(string prefixExpressionValue, string expected) { IPrefixExpression prefixExpression = new PrefixExpression(prefixExpressionValue); prefixExpression.NandifyExpression().Should().BeEquivalentTo(expected); }
public static Variable LiftVariable(this PrefixExpression prefixExpression) { var varPrefixExpr = prefixExpression as PrefixExpression.Variable; return(varPrefixExpr != null ? varPrefixExpr.Var : null); }
public void Should_Transform_Passed_Prefix_Expression_To_Infix_Notation(string expressionValue, string expectedResult) { IPrefixExpression expression = new PrefixExpression(expressionValue); expression.TransformToInfix().Should().BeEquivalentTo(expectedResult); }
public MemberId(PrefixExpression prefix, string member) { Prefix = prefix; Member = member; }
public Normal(PrefixExpression prefix, Arguments arguments) { Prefix = prefix; Arguments = arguments; }
/* Parses functionCall * prefixExpression arguments | * prefixExpression ':' Identifier arguments */ Statement FunctionCall(PrefixExpression prefixExpr) { var functionCall = prefixExpr.LiftFunctionCall(); if (functionCall == null) throw new LuaSyntaxException(input, ExceptionMessage.UNEXPECTED_SYMBOL, lexer.Current.Symbol); return new Statement.FunctionCall(functionCall); }
public override Expression VisitPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return null; Expression e = this.VisitTargetExpression(pExpr.Expression); e = this.CheckForGetAccessor(e); if (e == null) return null; pExpr.Expression = new LRExpression(e); TypeNode t = pExpr.Type; if (t == null) return null; t = this.typeSystem.RemoveNullableWrapper(t); if (!t.IsPrimitiveNumeric && t != SystemTypes.Char && !(t is EnumNode) && !(t is Pointer) && pExpr.OperatorOverload == null) { this.HandleError(pExpr, Error.NoSuchOperator, pExpr.Operator == NodeType.Add ? "++" : "--", this.GetTypeName(t)); return null; } if (t is Pointer && ((Pointer)t).ElementType == SystemTypes.Void) { this.HandleError(pExpr, Error.VoidError); return null; } return pExpr; }
public virtual Differences VisitPrefixExpression(PrefixExpression pExpr1, PrefixExpression pExpr2){ Differences differences = new Differences(pExpr1, pExpr2); if (pExpr1 == null || pExpr2 == null){ if (pExpr1 != pExpr2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } PrefixExpression changes = (PrefixExpression)pExpr2.Clone(); PrefixExpression deletions = (PrefixExpression)pExpr2.Clone(); PrefixExpression insertions = (PrefixExpression)pExpr2.Clone(); Differences diff = this.VisitExpression(pExpr1.Expression, pExpr2.Expression); if (diff == null){Debug.Assert(false); return differences;} changes.Expression = diff.Changes as Expression; deletions.Expression = diff.Deletions as Expression; insertions.Expression = diff.Insertions as Expression; Debug.Assert(diff.Changes == changes.Expression && diff.Deletions == deletions.Expression && diff.Insertions == insertions.Expression); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (pExpr1.Operator == pExpr2.Operator) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public override Expression VisitPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return null; if (this.typeSystem.IsNullableType(pExpr.Type)) return VisitLiftedPrefixExpression(pExpr); StatementList statements = new StatementList(); BlockExpression result = new BlockExpression(new Block(statements)); LRExpression lrExpr = this.VisitTargetExpression(pExpr.Expression) as LRExpression; if (lrExpr == null) return null; LocalList locals = lrExpr.Temporaries; ExpressionList subs = lrExpr.SubexpressionsToEvaluateOnce; for (int i = 0, n = locals.Count; i < n; i++) statements.Add(new AssignmentStatement(locals[i], subs[i],pExpr.SourceContext)); TypeNode rType = pExpr.Type; EnumNode eType = rType as EnumNode; if (eType != null) rType = eType.UnderlyingType; Expression newVal = null; if (pExpr.OperatorOverload != null){ ExpressionList arguments = new ExpressionList(1); arguments.Add(this.VisitExpression(lrExpr.Expression)); newVal = new MethodCall(new MemberBinding(null, pExpr.OperatorOverload), arguments, NodeType.Call, rType); }else{ Expression e = this.typeSystem.AutoDereferenceCoercion(lrExpr.Expression); Expression one = GetOneOfType(rType); newVal = new BinaryExpression(this.VisitExpression(e), one, pExpr.Operator, rType is Pointer ? rType : one.Type); } Local temp = new Local(Identifier.Empty, newVal.Type); statements.Add(new AssignmentStatement(temp, newVal,pExpr.SourceContext)); Expression target = this.VisitTargetExpression(lrExpr.Expression); MethodCall mcall = target as MethodCall; if (mcall != null){ mcall.Operands.Add(temp); statements.Add(new ExpressionStatement(mcall)); }else if (target != null){ if (target.Type is Reference) { target = new AddressDereference(target, rType); } statements.Add(new AssignmentStatement(target, this.typeSystem.ExplicitCoercion(temp, target.Type, this.TypeViewer),pExpr.SourceContext)); } statements.Add(new ExpressionStatement(temp,pExpr.SourceContext)); result.Type = pExpr.Type; return result; }
public virtual Expression VisitLiftedPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return null; if (!this.typeSystem.IsNullableType(pExpr.Type)) { Debug.Assert(false); return null; } LRExpression lrExpr = this.VisitTargetExpression(pExpr.Expression) as LRExpression; if (lrExpr == null) return null; TypeNode urType = this.typeSystem.RemoveNullableWrapper(pExpr.Type); TypeNode paramType = urType; LocalList locals = lrExpr.Temporaries; ExpressionList subs = lrExpr.SubexpressionsToEvaluateOnce; StatementList statements = new StatementList(); BlockExpression result = new BlockExpression(new Block(statements)); for (int i = 0, n = locals.Count; i < n; i++) statements.Add(new AssignmentStatement(locals[i], subs[i])); EnumNode eType = urType as EnumNode; if (eType != null) urType = eType.UnderlyingType; Local temp = new Local(Identifier.Empty, pExpr.Type); Local tempNew = new Local(Identifier.Empty, pExpr.Type); Expression e = this.typeSystem.ExplicitCoercion(lrExpr.Expression, pExpr.Type, this.TypeViewer); statements.Add(new AssignmentStatement(temp, this.VisitExpression(e))); Method hasValue = this.GetTypeView(pExpr.Type).GetMethod(StandardIds.getHasValue); Method getValueOrDefault = this.GetTypeView(pExpr.Type).GetMethod(StandardIds.GetValueOrDefault); Method ctor = this.GetTypeView(pExpr.Type).GetMethod(StandardIds.Ctor, paramType); Block pushValue = new Block(); Block done = new Block(); Expression tempHasValue = new MethodCall(new MemberBinding(new UnaryExpression(temp, NodeType.AddressOf), hasValue), null); statements.Add(new Branch(tempHasValue, pushValue)); statements.Add(new AssignmentStatement(new AddressDereference(new UnaryExpression(tempNew, NodeType.AddressOf), pExpr.Type), new Literal(null, CoreSystemTypes.Object))); statements.Add(new Branch(null, done)); statements.Add(pushValue); Expression value = new MethodCall(new MemberBinding(new UnaryExpression(temp, NodeType.AddressOf), getValueOrDefault), null); value.Type = paramType; Expression one = GetOneOfType(urType); Expression newUVal = new BinaryExpression(value, one, pExpr.Operator, urType is Pointer ? urType : one.Type); Construct cons = new Construct(new MemberBinding(null, ctor), new ExpressionList(newUVal)); result.Type = ctor.DeclaringType; statements.Add(new AssignmentStatement(tempNew, cons)); statements.Add(done); Expression target = this.VisitTargetExpression(lrExpr.Expression); MethodCall mcall = target as MethodCall; if (mcall != null) { mcall.Operands.Add(tempNew); statements.Add(new ExpressionStatement(mcall)); } else if (target != null) { if (target.Type is Reference) { Local temp2 = new Local(Identifier.Empty, pExpr.Type); statements.Add(new AssignmentStatement(temp2, tempNew)); tempNew = temp2; target = new AddressDereference(target, pExpr.Type); } statements.Add(new AssignmentStatement(target, tempNew)); } statements.Add(new ExpressionStatement(tempNew)); result.Type = pExpr.Type; result.SourceContext = pExpr.SourceContext; result.Block.SourceContext = pExpr.SourceContext; return result; }
public static FunctionCall LiftFunctionCall(this PrefixExpression prefixExpression) { var funcCallPrefixExpr = prefixExpression as PrefixExpression.FunctionCall; return(funcCallPrefixExpr != null ? funcCallPrefixExpr.Call : null); }
public override Expression VisitPrefixExpression(PrefixExpression pExpr){ if (pExpr == null) return null; Expression e = pExpr.Expression = this.VisitTargetExpression(pExpr.Expression); if (e == null) return null; pExpr.Type = this.typeSystem.Unwrap(e.Type); pExpr.OperatorOverload = this.GetPrefixOrPostfixOperatorOverload(e, pExpr.Type, pExpr.Operator); return pExpr; }
/* Parses functionCall * prefixExpression arguments | * prefixExpression ':' Identifier arguments */ Statement FunctionCall(PrefixExpression prefixExpr) { var functionCall = prefixExpr.LiftFunctionCall(); if (functionCall == null) throw ReportSyntaxError(ExceptionMessage.UNEXPECTED_SYMBOL, Current.Symbol); return new Statement.FunctionCall(functionCall) { Span = functionCall.Span }; }
/* Parses assign * variableList '=' expressionList */ Statement Assign(PrefixExpression prefixExpr) { var variable = prefixExpr.LiftVariable(); if (variable == null) throw new LuaSyntaxException(input, ExceptionMessage.UNEXPECTED_SYMBOL, lexer.Current.Symbol); var variables = lexer.Current.Symbol == Symbol.Comma ? VariableList(variable) : new List<Variable> {variable}; lexer.Expect(Symbol.Equal); var expressions = ExpressionList(); return new Statement.Assign(variables, expressions); }
public virtual void VisitPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return; this.VisitExpression(pExpr.Expression); }
public virtual Expression VisitPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return null; pExpr.Expression = this.VisitExpression(pExpr.Expression); return pExpr; }
public void Should_Remove_Brackets_Commans_And_WhiteSpaces_From_Passed_Expression(string expressionValue, string expectedResult) { IExpression expression = new PrefixExpression(expressionValue); expression.ParseExpression().Value.Should().BeEquivalentTo(expectedResult); }
public Table(PrefixExpression prefix, string name, Arguments arguments) { Prefix = prefix; Name = name; Arguments = arguments; }
public MemberExpr(PrefixExpression prefix, Expression member) { Prefix = prefix; Member = member; }
/* Parses assign * variableList '=' expressionList */ Statement Assign(PrefixExpression prefixExpr) { var variable = prefixExpr.LiftVariable(); if (variable == null) throw ReportSyntaxError(ExceptionMessage.UNEXPECTED_SYMBOL, Current.Symbol); var variables = VariableList(variable); Expect(Symbol.Equal); var expressions = ExpressionList(); Debug.Assert(variables.Count > 0); Debug.Assert(expressions.Count > 0); return new Statement.Assign(variables, expressions) { Span = new SourceSpan(variables.First().Span.Start, expressions.Last().Span.End) }; }
public virtual Expression VisitPrefixExpression(PrefixExpression pExpr1, PrefixExpression pExpr2) { if (pExpr1 == null) return null; if (pExpr2 == null) pExpr1.Expression = this.VisitExpression(pExpr1.Expression, null); else pExpr1.Expression = this.VisitExpression(pExpr1.Expression, pExpr2.Expression); return pExpr1; }
public virtual Expression VisitPrefixExpression(PrefixExpression pExpr, PrefixExpression changes, PrefixExpression deletions, PrefixExpression insertions){ this.UpdateSourceContext(pExpr, changes); if (pExpr == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return pExpr; }
public override Expression VisitPrefixExpression(PrefixExpression pExpr) { if (pExpr == null) return null; return base.VisitPrefixExpression((PrefixExpression)pExpr.Clone()); }