private Node VariableDeclaration() { bool local = false; if (LookAhead(1) == TokenType.VAR) { Match(TokenType.VAR); local = true; } Node result = Variable(); if (LookAhead(1) == TokenType.ASSIGN) { SourcePosition pos = Match(TokenType.ASSIGN).Position; Node value = Expression(); result = new AssignNode(pos, result, value, local); } if (LookAhead(1) == TokenType.END_STATEMENT) { Match(TokenType.END_STATEMENT); } return(result); }
private TypeDescriptor Visit(AssignNode node, Context context) { TypeDescriptor lValue = Visit(node.LValue as dynamic, context); var rValue = Visit(node.Expression as dynamic, context); if (lValue.Type.Equals(TypeInfo.Undefined) || rValue.Type.Equals(TypeInfo.Undefined)) { return(TypeDescriptor.Undefined); } if (!lValue.IsLvalue) { Log("Выражение не lvalue", node); return(TypeDescriptor.Undefined); } if (!lValue.Type.CanBeAssignedWith(rValue.Type)) { Log( string.Format("Типы {0} и {1} не совместимы", lValue.Type.ToString(), rValue.Type.ToString()), node); return(TypeDescriptor.Undefined); } return(lValue); }
private void Visit(AssignNode node) { if (!(node.Left is VariableNode)) { ReportError(new InvalidOperationException("You can only assign values to variables!")); return; } var variableNode = (node.Left as VariableNode); if (!GlobalVariables.ContainsKey(variableNode.Name)) { ReportError(new InvalidOperationException($"Variable \"{variableNode.Name}\" has not been declared!")); return; } var variable = GlobalVariables[variableNode.Name]; var expression = Visit(node.Right); if (expression.GetType().Name != variable.Type) { ReportError(new Exception($"Type Mismatch! Data of type \"{expression.GetType().Name}\" cannot be assigned to " + $"variable \"{variableNode.Name}\" of type \"{variable.Type}\"!")); return; } variable.Value = expression; }
public override void VisitAssignNode(AssignNode a) { if (depth > 0) { Count += 1; } }
public bool VisitAssignNode(AssignNode node, CompilationState state) { node.Left.AcceptVisitor(this, state); state.Write(" = "); node.Right.AcceptVisitor(this, state); return(true); }
public override void Visit(AssignNode node) { PreVisit(node); node.Id.Visit(this); node.Expr.Visit(this); PostVisit(node); }
public void GenerateCode(AssignNode node, ICIL_CodeGenerator codeGenerator) { //GenerateCode(node.ObjId, codeGenerator); GenerateCode(node.Expression, codeGenerator); if (node.ObjId.Symbol.IsAttribute) { // Y.b = X (Set_Attr) var instance = node.ObjId.OwnerType.Self.Holder; codeGenerator.AddInstruction( new SetAttr((Variable)instance, $"{node.ObjId.OwnerType.Name}_{node.ObjId.Text}", node.Expression.Holder)); } else { // Y = X (assign) codeGenerator.AddInstruction( new Assign((Variable)node.ObjId.Symbol.Holder, node.Expression.Holder)); } node.Holder = codeGenerator.DefineVariable(); codeGenerator.AddLocalVariable(new CIL_LocalVariable((Variable)node.Holder)); codeGenerator.AddInstruction( new Assign((Variable)node.Holder, node.Expression.Holder)); }
public override void VisitAssignNode(AssignNode a) { a.Id.Visit(this); NestExpr++; (a.Expr as ExprNode).Visit(this); NestExpr--; }
public override void VisitAssignNode(AssignNode a) { PreVisit(a); a.Id.Visit(this); a.Expr.Visit(this); PostVisit(a); }
public override void VisitAssignNode(AssignNode a) { Text += IndentStr(); a.Id.Visit(this); Text += " := "; a.Expr.Visit(this); }
public void Visit(AssignNode node) { node.exprBody.Accept(this); var(count, type) = VariableManager.GetVariable(node.Id.text); if (type == "") { type = ClassManager.GetPropertyType(VariableManager.CurrentClass, node.Id.text); } var static_type = node.exprBody.staticType.Text; if ((static_type == "Int" || static_type == "Bool" || static_type == "String") && type == "Object") { Code.Add(new PushParamCodeLine(VariableManager.PeekVariableCounter())); Code.Add(new CallLblCodeLine(new LabelCodeLine("_wrapper", static_type), VariableManager.PeekVariableCounter())); Code.Add(new PopParamCodeLine(1)); } if (count != -1) { Code.Add(new AssignVarToVarCodeLine(count, VariableManager.PeekVariableCounter())); } else { int offset = ClassManager.GetOffset(VariableManager.CurrentClass, node.Id.text); Code.Add(new AssignVarToMemCodeLine(0, VariableManager.PeekVariableCounter(), offset)); } }
public override void VisitAssignNode(AssignNode a) { if (CycleOpenedBodyCount > 0) { CyclesOpCount += 1; } }
public override void VisitAssignNode(AssignNode a) { if (depth < 0) { ++opCnt; } }
public override void Visit(AssignNode node) { Console.WriteLine(node.ID); i += 2; VisitChildren(node, Inden()); i -= 2; }
private void Visit(AssignNode node) { if (node.LValue.Expression is IndexNode) { var indexNode = node.LValue.Expression as IndexNode; var where = indexNode.Where; var args = new List <BasicNode>() { indexNode.Index, node.Expression }; var method = new MethodCallNode("Set", where, args); ReplaceNode(node.Parent, node.ChildIndex, method); Visit(indexNode.Where as dynamic); Visit(node.Expression as dynamic); } else { Visit(node.LValue as dynamic); Visit(node.Expression as dynamic); } }
public override Type visitAssign(AssignNode assign, Environment env) { Expression assignLeft = assign.left; bool lValueError = !assignLeft.IsLValue; if (lValueError) { log.error(assign.Pos, messages.assignmentLHS); } Type lType = analyzeExpr(assignLeft, env); Type rType = analyzeExpr(assign.right, env); if (assignLeft is Select s && s.symbol == symtab.arrayLengthField) { log.error(s.Pos, "Array length is read only"); return(symtab.errorType); } if (!lValueError && !typings.isAssignableFrom(lType, rType)) { log.error(assign.Pos, messages.assignmentUncompatible); } return(lType); }
// Statement public override void Visit(AssignNode node) { Symbol variableDCL = SymbolTable.Retrieve(node.ID); if (SymbolTable.Retrieve(node.ID) is null) { throw new VariableNotDeclaredException( $"The variable \"{node.ID}\" cannot be assigned, as it has not been declared."); } base.Visit(node); if (variableDCL is TensorSymbol tensorDcl) { if (tensorDcl.Rows != node.Right.Rows || tensorDcl.Columns != node.Right.Columns) { throw new VariableAssignmentException(node, $"A tensor's dimensions cannot be changed during run-time. " + $"Rows: {tensorDcl.Rows} - {node.Right.Rows}, Columns:{tensorDcl.Columns} - {node.Right.Columns}"); } node.Type = tensorDcl.Type; } else { node.Type = variableDCL.Type; } if (node.Type != node.Right.Type && (node.Type != "double" && node.Right.Type != "int")) { throw new VariableAssignmentException(node, $"Illegal assignment. Left side: \"{node.Type}\", right side: \"{node.Right.Type}\"."); } }
public override void VisitAssignNode(AssignNode a) { a.Parent = st.Peek(); st.Push(a); base.VisitAssignNode(a); st.Pop(); }
public override void VisitAssignNode(AssignNode n) { if (n.Expr is IdNode idn && n.Id.Name == idn.Name) { ReplaceStat(n, new EmptyNode()); } }
public void Visit(AssignNode assign) { assign.Left.Parent = assign; assign.Right.Parent = assign; assign.Left.Accept(this); assign.Right.Accept(this); }
private Node SumExpression() { // term ((PLUS^|MINUS^) term)* Node termExpression = Term(); TokenType next = LookAhead(1); if (LookAhead(2) != TokenType.STRING_LITERAL) { while (next == TokenType.PLUS || next == TokenType.PLUS_PLUS || next == TokenType.PLUS_ASSIGN || next == TokenType.MINUS || next == TokenType.MINUS_MINUS || next == TokenType.MINUS_ASSIGN) { if (next == TokenType.PLUS) { termExpression = new AddOpNode(Match(TokenType.PLUS).Position, termExpression, Term()); } else if (next == TokenType.PLUS_PLUS) { Node increment = new IntegerNode(Match(TokenType.PLUS_PLUS).Position, 1); Node addNode = new AddOpNode(increment.Position, termExpression, increment); termExpression = new AssignNode(termExpression.Position, termExpression, addNode, false); } else if (next == TokenType.PLUS_ASSIGN) { Token plusAssign = Match(TokenType.PLUS_ASSIGN); Node increment = Expression(); Node addNode = new AddOpNode(plusAssign.Position, termExpression, increment); termExpression = new AssignNode(termExpression.Position, termExpression, addNode, false); } else if (next == TokenType.MINUS) { termExpression = new SubtractOpNode(Match(TokenType.MINUS).Position, termExpression, Term()); } else if (next == TokenType.MINUS_MINUS) { Node deincrement = new IntegerNode(Match(TokenType.MINUS_MINUS).Position, 1); Node subtractNode = new SubtractOpNode(deincrement.Position, termExpression, deincrement); termExpression = new AssignNode(termExpression.Position, termExpression, subtractNode, false); } else if (next == TokenType.MINUS_ASSIGN) { Token minusAssign = Match(TokenType.MINUS_ASSIGN); Node deincrement = Expression(); Node subtractNode = new SubtractOpNode(minusAssign.Position, termExpression, deincrement); termExpression = new AssignNode(termExpression.Position, termExpression, subtractNode, false); } next = LookAhead(1); } } return(termExpression); }
public override void VisitAssignNode(AssignNode a) { Text.Append(IndentStr()); a.Id.Visit(this); Text.Append(" = "); a.Expr.Visit(this); Text.Append(";"); }
public override void VisitAssignNode(AssignNode a) { if (currCyc > 0) { opCnt++; } base.VisitAssignNode(a); }
public override void VisitAssignNode(AssignNode a) { // для каких-то визиторов порядок может быть обратный - вначале обойти выражение, потом - идентификатор a.Id.Visit(this); ++CurrNestExprs; (a.Expr as ExprNode).Visit(this); --CurrNestExprs; }
public override void VisitAssignNode(AssignNode a) { // для каких-то визиторов порядок может быть обратный - вначале обойти выражение, потом - идентификатор a.Id.Visit(this); CurrentComplexity = 0; a.Expr.Visit(this); Complexities.Add(CurrentComplexity); }
private object Assign(AssignNode a) { var name = a.Variable.Name; var value = Evaluate(a.Expression); variables[name] = value; return(value); }
public override void VisitAssignNode(AssignNode a) { if (a.Expr is BinOpNode binOp && (binOp.Left is IdNode || binOp.Left is DoubleNumNode || binOp.Left is IntNumNode) && (binOp.Right is IdNode || binOp.Right is DoubleNumNode || binOp.Right is IntNumNode)) { ThreeAddressValueType arg1 = GenVariable(binOp.Left); ThreeAddressValueType arg2 = GenVariable(binOp.Right); AddCode(new ThreeCode(a.Id.ToString(), ThreeCode.ParseOperator(binOp.Op), arg1, arg2)); }
public override void VisitAssignNode(AssignNode a) { if (NowCycle > 0) { CountOp += 1; } a.Id.Visit(this); a.Expr.Visit(this); }
public override void VisitAssignNode(AssignNode a) { if (a == null) { return; } a.Id.Visit(this); a.Expr.Visit(this); }
public override void VisitAssignNode(AssignNode a) { if (CycleDepth > 0) { OpCount++; } a.Id.Visit(this); a.Expr.Visit(this); }