public void Visit(NegNode node) { Visit(node as UnaryNode); if (object_return_type) { Code.Add(new AssignStrToVarCodeLine(return_type, "Int")); } }
public void Visit(NegNode node) { UnaryOperationVisit(node); if (special_object_return_type) { SetReturnType("Int"); } }
public override ASTN VisitBitcompl([NotNull] BitcomplContext context) { NegNode node = new NegNode(context) { expr = VisitExpr(context.expr()) as ExprNode }; return(node); }
public void CheckSemantic(NegNode node, IScope scope = null) { CheckSemantic(node.Expression, scope); if (node.Expression.ComputedType.Name != "Int") { Logger.LogError(node.Line, node.CharPositionInLine, $"Cannot implicity convert type '{node.Expression.ComputedType}'to 'Int'"); return; } node.ComputedType = node.Expression.ComputedType; }
public void GenerateCode(NegNode node, ICIL_CodeGenerator codeGenerator) { node.Holder = codeGenerator.DefineVariable(); codeGenerator.AddLocalVariable( new CIL_LocalVariable((Variable)node.Holder)); GenerateCode(node.Expression, codeGenerator); codeGenerator.AddInstruction( new CilNeg((Variable)node.Holder, node.Expression.Holder)); }
public void Visit(NegNode node) { node.Operand.Accept(this); if (node.Operand.StaticType.Text != "Int") { errors.Add(SemanticError.InvalidUseOfOperator(node, node.Operand.StaticType)); } if (!scope.IsDefinedType("Int", out node.StaticType)) { errors.Add(SemanticError.NotDeclaredType(new TypeNode(node.Line, node.Column, "Int"))); } }
public void Visit(NegNode node) { node.expr.Accept(this); if (node.expr.staticType.Text != "Int") { errors.Add(ErrorSemantic.InvalidUseOfOperator(node, node.expr.staticType)); } if (!scope.IsDefinedType("Int", out node.staticType)) { errors.Add(ErrorSemantic.NotDeclaredType(new TypeNode(node.line, node.column, "Int"))); } }
public abstract T Visit(NegNode node);
public ValType CheckValueType(Node node, Scope inner, Scope outer) { switch (node.GetNodeType()) { case NodeType.Variable: VariableNode variableNode = node as VariableNode; if (!inner.variables.TryGetValue(variableNode.name, out VariableNode val)) { if (!outer.variables.TryGetValue(variableNode.name, out val)) { throw new SemanticException(SemanticErrorCode.UndeclaredVariable, "Variable \"" + variableNode.name + "\" is not declared.", node.Line); } else { variableNode.ValType = val.ValType; variableNode.LocalIndex = val.LocalIndex; } } else { variableNode.ValType = val.ValType; variableNode.LocalIndex = val.LocalIndex; } return(variableNode.ValType); case NodeType.Assign: AssignNode assignNode = node as AssignNode; ValType left = CheckValueType(assignNode.left, inner, outer); ValType right = CheckValueType(assignNode.right, inner, outer); if (assignNode.left.ValType != right && !(assignNode.left.ValType == ValType.Double && right == ValType.Int)) { throw new SemanticException(SemanticErrorCode.IllegalCast, "Cannot cast " + Enum.GetName(typeof(ValType), right) + " to " + Enum.GetName(typeof(ValType), assignNode.left.ValType) + ".", assignNode.right.Line); } if (right == ValType.Int && assignNode.left.ValType == ValType.Double) { DoubleCastNode dcn = new DoubleCastNode(assignNode.right.Line); dcn.content = assignNode.right; assignNode.right = dcn; } assignNode.ValType = left; return(left); case NodeType.Int: return(ValType.Int); case NodeType.Double: return(ValType.Double); case NodeType.Bool: return(ValType.Bool); case NodeType.BinaryOp: BinaryOpNode binaryOpNode = node as BinaryOpNode; ValType l = CheckValueType(binaryOpNode.left, inner, outer); ValType r = CheckValueType(binaryOpNode.right, inner, outer); int v = (int)l * (int)r; if (binaryOpNode.type == BinaryOpType.BitAnd || binaryOpNode.type == BinaryOpType.BitOr) { if (v != 1) { throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Int value.", node.Line); } return(ValType.Int); } else { if (v > 1 && v < 4) { if (l == ValType.Double) { DoubleCastNode dcn = new DoubleCastNode(binaryOpNode.right.Line); dcn.content = binaryOpNode.right; binaryOpNode.right = dcn; } else { DoubleCastNode dcn = new DoubleCastNode(binaryOpNode.left.Line); dcn.content = binaryOpNode.left; binaryOpNode.left = dcn; } binaryOpNode.ValType = ValType.Double; return(ValType.Double); } else if (l == ValType.Bool || r == ValType.Bool) { throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Int or Double.", binaryOpNode.Line); } } binaryOpNode.ValType = l; return(l); case NodeType.LogicOp: LogicOpNode logicOpNode = node as LogicOpNode; left = CheckValueType(logicOpNode.left, inner, outer); right = CheckValueType(logicOpNode.right, inner, outer); if (left != ValType.Bool) { string typeString = Enum.GetName(typeof(ValType), left); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Bool, but got " + typeString + ".", logicOpNode.left.Line); } if (right != ValType.Bool) { string typeString = Enum.GetName(typeof(ValType), right); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Bool, but got " + typeString + ".", logicOpNode.right.Line); } logicOpNode.ValType = ValType.Bool; return(ValType.Bool); case NodeType.Comparison: ComparisonNode comparisonNode = node as ComparisonNode; left = CheckValueType(comparisonNode.left, inner, outer); right = CheckValueType(comparisonNode.right, inner, outer); if (left != right) { if (left == ValType.Bool || right == ValType.Bool) { throw new SemanticException(SemanticErrorCode.IllegalCast, "Comparison arguments are not the same type.", comparisonNode.Line); } else if (left == ValType.Int && right == ValType.Double) { DoubleCastNode dcn = new DoubleCastNode(comparisonNode.left.Line); dcn.content = comparisonNode.left; comparisonNode.left = dcn; } else if (right == ValType.Int && left == ValType.Double) { DoubleCastNode dcn = new DoubleCastNode(comparisonNode.right.Line); dcn.content = comparisonNode.right; comparisonNode.right = dcn; } } comparisonNode.ValType = ValType.Bool; return(ValType.Bool); case NodeType.Parenthesis: ParenthesisNode parenthesisNode = node as ParenthesisNode; ValType type = CheckValueType(parenthesisNode.content, inner, outer); parenthesisNode.ValType = type; return(type); case NodeType.IntCast: IntCastNode intCastNode = node as IntCastNode; CheckInScope(intCastNode.content, inner, outer); intCastNode.ValType = ValType.Int; return(ValType.Int); case NodeType.DoubleCast: DoubleCastNode doubleCastNode = node as DoubleCastNode; CheckInScope(doubleCastNode.content, inner, outer); doubleCastNode.ValType = ValType.Double; return(ValType.Double); case NodeType.Not: NotNode notNode = node as NotNode; type = CheckValueType(notNode.content, inner, outer); if (type != ValType.Bool) { string typeString = Enum.GetName(typeof(ValType), type); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Bool, but got " + typeString + ".", notNode.content.Line); } notNode.ValType = ValType.Bool; return(ValType.Bool); case NodeType.Minus: MinusNode minusNode = node as MinusNode; type = CheckValueType(minusNode.content, inner, outer); if (type == ValType.Bool) { string typeString = Enum.GetName(typeof(ValType), type); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Int or Double.", minusNode.content.Line); } minusNode.ValType = type; return(type); case NodeType.Neg: NegNode negNode = node as NegNode; type = CheckValueType(negNode.content, inner, outer); if (type != ValType.Int) { string typeString = Enum.GetName(typeof(ValType), type); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Int, but got " + typeString + ".", negNode.content.Line); } negNode.ValType = type; return(ValType.Int); } return(ValType.None); }
public void CheckInScope(Node node, Scope inner, Scope outer) { switch (node.GetNodeType()) { case NodeType.Block: Scope newOuter = new Scope(outer); newOuter.AddScope(inner); GoDeeperInScope(node as BlockNode, newOuter); break; case NodeType.If: IfNode ifNode = node as IfNode; ValType type = CheckValueType(ifNode.check, inner, outer); if (type == ValType.Bool) { CheckInScope(ifNode.ifBlock, inner, outer); if (!(ifNode.elseBlock is null)) { CheckInScope(ifNode.elseBlock, inner, outer); } } else { string typeString = Enum.GetName(typeof(ValType), type); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Bool, but got " + typeString + ".", node.Line); } break; case NodeType.While: WhileNode whileNode = node as WhileNode; type = CheckValueType(whileNode.check, inner, outer); if (type == ValType.Bool) { CheckInScope(whileNode.block, inner, outer); } else { string typeString = Enum.GetName(typeof(ValType), type); throw new SemanticException(SemanticErrorCode.IllegalCast, "Expected Bool, but got " + typeString + ".", node.Line); } break; case NodeType.Read: ReadNode readNode = node as ReadNode; CheckInScope(readNode.target, inner, outer); break; case NodeType.Write: WriteNode writeNode = node as WriteNode; if (!(writeNode.content is StringNode)) { CheckInScope(writeNode.content, inner, outer); } break; case NodeType.Variable: VariableNode variableNode = node as VariableNode; CheckValueType(variableNode, inner, outer); break; case NodeType.Init: InitNode initNode = node as InitNode; if (inner.variables.ContainsKey(initNode.variable.name)) { throw new SemanticException(SemanticErrorCode.VariableAlreadyDeclared, "Variable \"" + initNode.variable.name + "\" already declared in scope", initNode.variable.Line); } else { inner.variables.Add(initNode.variable.name, initNode.variable); } initNode.variable.LocalIndex = locals.Count; locals.Add(new LocalVariable { Name = initNode.variable.name, Type = initNode.variable.ValType }); break; case NodeType.Assign: AssignNode assignNode = node as AssignNode; CheckValueType(assignNode, inner, outer); break; case NodeType.BinaryOp: BinaryOpNode binaryOpNode = node as BinaryOpNode; CheckValueType(binaryOpNode, inner, outer); break; case NodeType.Comparison: ComparisonNode comparisonNode = node as ComparisonNode; CheckValueType(comparisonNode, inner, outer); break; case NodeType.Parenthesis: ParenthesisNode parenthesisNode = node as ParenthesisNode; CheckInScope(parenthesisNode.content, inner, outer); break; case NodeType.Int: case NodeType.Double: case NodeType.Bool: case NodeType.String: break; case NodeType.LogicOp: LogicOpNode logicNode = node as LogicOpNode; CheckValueType(logicNode, inner, outer); break; case NodeType.IntCast: IntCastNode intCastNode = node as IntCastNode; CheckValueType(intCastNode, inner, outer); break; case NodeType.DoubleCast: DoubleCastNode doubleCastNode = node as DoubleCastNode; CheckValueType(doubleCastNode, inner, outer); break; case NodeType.Not: NotNode notNode = node as NotNode; CheckValueType(notNode, inner, outer); break; case NodeType.Minus: MinusNode minusNode = node as MinusNode; CheckValueType(minusNode, inner, outer); break; case NodeType.Neg: NegNode negNode = node as NegNode; CheckValueType(negNode, inner, outer); break; } }
// $ANTLR start "unaryExpression" // JavaScript.g:313:1: unaryExpression : ( postfixExpression | 'delete' ( LT )* unaryExpression | 'void' ( LT )* unaryExpression | 'typeof' ( LT )* unaryExpression | '++' unaryExpression | '--' unaryExpression | '+' ( LT )* unaryExpression | '-' ( LT )* unaryExpression | '~' ( LT )* unaryExpression | '!' ( LT )* unaryExpression ); public JavaScriptParser.unaryExpression_return unaryExpression() // throws RecognitionException [1] { JavaScriptParser.unaryExpression_return retval = new JavaScriptParser.unaryExpression_return(); retval.Start = input.LT(1); object root_0 = null; IToken string_literal369 = null; IToken LT370 = null; IToken string_literal372 = null; IToken LT373 = null; IToken string_literal375 = null; IToken LT376 = null; IToken string_literal378 = null; IToken string_literal380 = null; IToken char_literal382 = null; IToken LT383 = null; IToken char_literal385 = null; IToken LT386 = null; IToken char_literal388 = null; IToken LT389 = null; IToken char_literal391 = null; IToken LT392 = null; JavaScriptParser.postfixExpression_return postfixExpression368 = default(JavaScriptParser.postfixExpression_return); JavaScriptParser.unaryExpression_return unaryExpression371 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression374 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression377 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression379 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression381 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression384 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression387 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression390 = default(JavaScriptParser.unaryExpression_return); JavaScriptParser.unaryExpression_return unaryExpression393 = default(JavaScriptParser.unaryExpression_return); object string_literal369_tree=null; object LT370_tree=null; object string_literal372_tree=null; object LT373_tree=null; object string_literal375_tree=null; object LT376_tree=null; object string_literal378_tree=null; object string_literal380_tree=null; object char_literal382_tree=null; object LT383_tree=null; object char_literal385_tree=null; object LT386_tree=null; object char_literal388_tree=null; object LT389_tree=null; object char_literal391_tree=null; object LT392_tree=null; try { // JavaScript.g:314:2: ( postfixExpression | 'delete' ( LT )* unaryExpression | 'void' ( LT )* unaryExpression | 'typeof' ( LT )* unaryExpression | '++' unaryExpression | '--' unaryExpression | '+' ( LT )* unaryExpression | '-' ( LT )* unaryExpression | '~' ( LT )* unaryExpression | '!' ( LT )* unaryExpression ) int alt199 = 10; alt199 = dfa199.Predict(input); switch (alt199) { case 1 : // JavaScript.g:314:4: postfixExpression { root_0 = (object)adaptor.GetNilNode(); PushFollow(FOLLOW_postfixExpression_in_unaryExpression2837); postfixExpression368 = postfixExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, postfixExpression368.Tree); } break; case 2 : // JavaScript.g:315:4: 'delete' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); string_literal369=(IToken)Match(input,104,FOLLOW_104_in_unaryExpression2843); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal369_tree = new DeleteNode(string_literal369) ; root_0 = (object)adaptor.BecomeRoot(string_literal369_tree, root_0); } // JavaScript.g:315:28: ( LT )* do { int alt192 = 2; int LA192_0 = input.LA(1); if ( (LA192_0 == LT) ) { alt192 = 1; } switch (alt192) { case 1 : // JavaScript.g:315:28: LT { LT370=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2849); if (state.failed) return retval; } break; default: goto loop192; } } while (true); loop192: ; // Stops C# compiler whining that label 'loop192' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2853); unaryExpression371 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression371.Tree); } break; case 3 : // JavaScript.g:316:4: 'void' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); string_literal372=(IToken)Match(input,105,FOLLOW_105_in_unaryExpression2859); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal372_tree = new VoidNode(string_literal372) ; root_0 = (object)adaptor.BecomeRoot(string_literal372_tree, root_0); } // JavaScript.g:316:24: ( LT )* do { int alt193 = 2; int LA193_0 = input.LA(1); if ( (LA193_0 == LT) ) { alt193 = 1; } switch (alt193) { case 1 : // JavaScript.g:316:24: LT { LT373=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2865); if (state.failed) return retval; } break; default: goto loop193; } } while (true); loop193: ; // Stops C# compiler whining that label 'loop193' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2869); unaryExpression374 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression374.Tree); } break; case 4 : // JavaScript.g:317:4: 'typeof' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); string_literal375=(IToken)Match(input,106,FOLLOW_106_in_unaryExpression2875); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal375_tree = new TypeOfExpr(string_literal375) ; root_0 = (object)adaptor.BecomeRoot(string_literal375_tree, root_0); } // JavaScript.g:317:28: ( LT )* do { int alt194 = 2; int LA194_0 = input.LA(1); if ( (LA194_0 == LT) ) { alt194 = 1; } switch (alt194) { case 1 : // JavaScript.g:317:28: LT { LT376=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2881); if (state.failed) return retval; } break; default: goto loop194; } } while (true); loop194: ; // Stops C# compiler whining that label 'loop194' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2885); unaryExpression377 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression377.Tree); } break; case 5 : // JavaScript.g:318:4: '++' unaryExpression { root_0 = (object)adaptor.GetNilNode(); string_literal378=(IToken)Match(input,107,FOLLOW_107_in_unaryExpression2891); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal378_tree = new preIncExpr(string_literal378) ; root_0 = (object)adaptor.BecomeRoot(string_literal378_tree, root_0); } PushFollow(FOLLOW_unaryExpression_in_unaryExpression2897); unaryExpression379 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression379.Tree); } break; case 6 : // JavaScript.g:319:4: '--' unaryExpression { root_0 = (object)adaptor.GetNilNode(); string_literal380=(IToken)Match(input,108,FOLLOW_108_in_unaryExpression2903); if (state.failed) return retval; if ( state.backtracking == 0 ) {string_literal380_tree = new preDecExpr(string_literal380) ; root_0 = (object)adaptor.BecomeRoot(string_literal380_tree, root_0); } PushFollow(FOLLOW_unaryExpression_in_unaryExpression2909); unaryExpression381 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression381.Tree); } break; case 7 : // JavaScript.g:320:4: '+' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); char_literal382=(IToken)Match(input,99,FOLLOW_99_in_unaryExpression2915); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal382_tree = new PosNode(char_literal382) ; root_0 = (object)adaptor.BecomeRoot(char_literal382_tree, root_0); } // JavaScript.g:320:20: ( LT )* do { int alt195 = 2; int LA195_0 = input.LA(1); if ( (LA195_0 == LT) ) { alt195 = 1; } switch (alt195) { case 1 : // JavaScript.g:320:20: LT { LT383=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2921); if (state.failed) return retval; } break; default: goto loop195; } } while (true); loop195: ; // Stops C# compiler whining that label 'loop195' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2925); unaryExpression384 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression384.Tree); } break; case 8 : // JavaScript.g:321:4: '-' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); char_literal385=(IToken)Match(input,100,FOLLOW_100_in_unaryExpression2931); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal385_tree = new NegNode(char_literal385) ; root_0 = (object)adaptor.BecomeRoot(char_literal385_tree, root_0); } // JavaScript.g:321:20: ( LT )* do { int alt196 = 2; int LA196_0 = input.LA(1); if ( (LA196_0 == LT) ) { alt196 = 1; } switch (alt196) { case 1 : // JavaScript.g:321:20: LT { LT386=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2937); if (state.failed) return retval; } break; default: goto loop196; } } while (true); loop196: ; // Stops C# compiler whining that label 'loop196' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2941); unaryExpression387 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression387.Tree); } break; case 9 : // JavaScript.g:322:4: '~' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); char_literal388=(IToken)Match(input,109,FOLLOW_109_in_unaryExpression2947); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal388_tree = new BinaryNotNode(char_literal388) ; root_0 = (object)adaptor.BecomeRoot(char_literal388_tree, root_0); } // JavaScript.g:322:26: ( LT )* do { int alt197 = 2; int LA197_0 = input.LA(1); if ( (LA197_0 == LT) ) { alt197 = 1; } switch (alt197) { case 1 : // JavaScript.g:322:26: LT { LT389=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2953); if (state.failed) return retval; } break; default: goto loop197; } } while (true); loop197: ; // Stops C# compiler whining that label 'loop197' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2957); unaryExpression390 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression390.Tree); } break; case 10 : // JavaScript.g:323:4: '!' ( LT )* unaryExpression { root_0 = (object)adaptor.GetNilNode(); char_literal391=(IToken)Match(input,110,FOLLOW_110_in_unaryExpression2963); if (state.failed) return retval; if ( state.backtracking == 0 ) {char_literal391_tree = new LogicalNotNode(char_literal391) ; root_0 = (object)adaptor.BecomeRoot(char_literal391_tree, root_0); } // JavaScript.g:323:27: ( LT )* do { int alt198 = 2; int LA198_0 = input.LA(1); if ( (LA198_0 == LT) ) { alt198 = 1; } switch (alt198) { case 1 : // JavaScript.g:323:27: LT { LT392=(IToken)Match(input,LT,FOLLOW_LT_in_unaryExpression2969); if (state.failed) return retval; } break; default: goto loop198; } } while (true); loop198: ; // Stops C# compiler whining that label 'loop198' has no statements PushFollow(FOLLOW_unaryExpression_in_unaryExpression2973); unaryExpression393 = unaryExpression(); state.followingStackPointer--; if (state.failed) return retval; if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression393.Tree); } break; } retval.Stop = input.LT(-1); if ( (state.backtracking==0) ) { retval.Tree = (object)adaptor.RulePostProcessing(root_0); adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);} } catch (RecognitionException re) { ReportError(re); Recover(input,re); // Conversion of the second argument necessary, but harmless retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re); } finally { } return retval; }
public void Visit(NegNode node) { throw new NotImplementedException(); }
protected override void DoAction(int action) { #pragma warning disable 162, 1522 switch (action) { case 2: // start -> Program, block, EOF #line 22 "D:\MINICompiler\kompilator.y" { if (syntaxErrorLines.Count != 0) { YYAbort(); } ProgramTree.block = ValueStack[ValueStack.Depth - 2] as BlockNode; ProgramTree.Line = ValueStack[ValueStack.Depth - 3].Line; } #line default break; case 3: // block -> OpenBracket, lines, CloseBracket #line 34 "D:\MINICompiler\kompilator.y" { BlockNode node; if (ValueStack[ValueStack.Depth - 2] is null) { node = new BlockNode(); } else { node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode); } node.Line = ValueStack[ValueStack.Depth - 3].Line; CurrentSemanticValue = node; } #line default break; case 5: // lines -> lines, instruction #line 44 "D:\MINICompiler\kompilator.y" { BlockNode node; if (ValueStack[ValueStack.Depth - 2] is null) { node = new BlockNode(); } else { node = new BlockNode(ValueStack[ValueStack.Depth - 2] as BlockNode); } node.instructions.Add(ValueStack[ValueStack.Depth - 1]); CurrentSemanticValue = node; } #line default break; case 6: // lines -> EOF #line 52 "D:\MINICompiler\kompilator.y" { syntaxErrorLines.Add(ProgramTree.LineCount); YYAbort(); } #line default break; case 11: // instruction -> exp, Semicolon #line 62 "D:\MINICompiler\kompilator.y" { ExpressionNode node = ValueStack[ValueStack.Depth - 2] as ExpressionNode; node.ShouldReturnValue = false; } #line default break; case 15: // instruction -> Semicolon #line 70 "D:\MINICompiler\kompilator.y" { syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line); } #line default break; case 16: // instruction -> error #line 74 "D:\MINICompiler\kompilator.y" { syntaxErrorLines.Add(ValueStack[ValueStack.Depth - 1].Line); } #line default break; case 17: // write -> Write, String #line 80 "D:\MINICompiler\kompilator.y" { WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1]; CurrentSemanticValue = node; } #line default break; case 18: // write -> Write, exp #line 86 "D:\MINICompiler\kompilator.y" { WriteNode node = new WriteNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 19: // read -> Read, Variable #line 93 "D:\MINICompiler\kompilator.y" { ReadNode node = new ReadNode(ValueStack[ValueStack.Depth - 2].Line); node.target = ValueStack[ValueStack.Depth - 1] as VariableNode; CurrentSemanticValue = node; } #line default break; case 20: // init -> Int, Variable #line 100 "D:\MINICompiler\kompilator.y" { InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line); node.variable = ValueStack[ValueStack.Depth - 1] as VariableNode; node.variable.ValType = ValType.Int; CurrentSemanticValue = node; } #line default break; case 21: // init -> Double, Variable #line 108 "D:\MINICompiler\kompilator.y" { InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line); node.variable = ValueStack[ValueStack.Depth - 1] as VariableNode; node.variable.ValType = ValType.Double; CurrentSemanticValue = node; } #line default break; case 22: // init -> Bool, Variable #line 115 "D:\MINICompiler\kompilator.y" { InitNode node = new InitNode(ValueStack[ValueStack.Depth - 2].Line); node.variable = ValueStack[ValueStack.Depth - 1] as VariableNode; node.variable.ValType = ValType.Bool; CurrentSemanticValue = node; } #line default break; case 23: // assign -> Variable, Assign, exp #line 123 "D:\MINICompiler\kompilator.y" { AssignNode node = new AssignNode(ValueStack[ValueStack.Depth - 3].Line); node.left = ValueStack[ValueStack.Depth - 3] as VariableNode; node.right = ValueStack[ValueStack.Depth - 1]; node.ShouldReturnValue = true; CurrentSemanticValue = node; } #line default break; case 24: // exp -> OpenPar, exp, ClosePar #line 133 "D:\MINICompiler\kompilator.y" { ParenthesisNode node = new ParenthesisNode(ValueStack[ValueStack.Depth - 3].Line); node.content = ValueStack[ValueStack.Depth - 2] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 25: // exp -> exp, Add, exp #line 139 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 26: // exp -> exp, Sub, exp #line 144 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 27: // exp -> exp, Mult, exp #line 149 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 28: // exp -> exp, Div, exp #line 154 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 29: // exp -> exp, BitAnd, exp #line 159 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 30: // exp -> exp, BitOr, exp #line 164 "D:\MINICompiler\kompilator.y" { BinaryOpNode node = ValueStack[ValueStack.Depth - 2] as BinaryOpNode; CurrentSemanticValue = AssignToBinaryOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 32: // exp -> IntCast, exp #line 170 "D:\MINICompiler\kompilator.y" { IntCastNode node = new IntCastNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 33: // exp -> DoubleCast, exp #line 176 "D:\MINICompiler\kompilator.y" { DoubleCastNode node = new DoubleCastNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 37: // exp -> Not, exp #line 185 "D:\MINICompiler\kompilator.y" { NotNode node = new NotNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 38: // exp -> Tilde, exp #line 191 "D:\MINICompiler\kompilator.y" { NegNode node = new NegNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 39: // exp -> Sub, exp #line 197 "D:\MINICompiler\kompilator.y" { MinusNode node = new MinusNode(ValueStack[ValueStack.Depth - 2].Line); node.content = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 40: // exp -> exp, And, exp #line 203 "D:\MINICompiler\kompilator.y" { LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode; node.left = ValueStack[ValueStack.Depth - 3] as ExpressionNode; node.right = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 41: // exp -> exp, Or, exp #line 210 "D:\MINICompiler\kompilator.y" { LogicOpNode node = ValueStack[ValueStack.Depth - 2] as LogicOpNode; node.left = ValueStack[ValueStack.Depth - 3] as ExpressionNode; node.right = ValueStack[ValueStack.Depth - 1] as ExpressionNode; CurrentSemanticValue = node; } #line default break; case 42: // exp -> exp, Comparison, exp #line 217 "D:\MINICompiler\kompilator.y" { ComparisonNode node = ValueStack[ValueStack.Depth - 2] as ComparisonNode; CurrentSemanticValue = AssignToComparisonOp(node, ValueStack[ValueStack.Depth - 3] as ExpressionNode, ValueStack[ValueStack.Depth - 1] as ExpressionNode); } #line default break; case 44: // if -> If, OpenPar, exp, ClosePar, instruction #line 225 "D:\MINICompiler\kompilator.y" { IfNode node = new IfNode(ValueStack[ValueStack.Depth - 5].Line); node.check = ValueStack[ValueStack.Depth - 3] as ExpressionNode; node.ifBlock = ValueStack[ValueStack.Depth - 1]; CurrentSemanticValue = node; } #line default break; case 45: // if -> If, OpenPar, exp, ClosePar, instruction, Else, instruction #line 232 "D:\MINICompiler\kompilator.y" { IfNode node = new IfNode(ValueStack[ValueStack.Depth - 7].Line); node.check = ValueStack[ValueStack.Depth - 5] as ExpressionNode; node.elseBlock = ValueStack[ValueStack.Depth - 1]; node.ifBlock = ValueStack[ValueStack.Depth - 3]; CurrentSemanticValue = node; } #line default break; case 46: // while -> While, OpenPar, exp, ClosePar, instruction #line 241 "D:\MINICompiler\kompilator.y" { WhileNode node = new WhileNode(ValueStack[ValueStack.Depth - 5].Line); node.check = ValueStack[ValueStack.Depth - 3] as ExpressionNode; node.block = ValueStack[ValueStack.Depth - 1]; CurrentSemanticValue = node; } #line default break; } #pragma warning restore 162, 1522 }