public virtual bool Walk(WhileNode node) { return true; }
private void ParseWhile(Node subtree) { WhileNode whileNode = new WhileNode(subtree); tokens.ConsumeToken(TokenType.While); int currentPos = tokens.CurrTokID; while (true) { if (tokens.CurrentToken == TokenType.Colon) { tokens.List.Insert(tokens.CurrTokID, new Token(TokenType.Delim, null, tokens.CurrentToken.LineNo)); break; } else if(tokens.CurrentToken == TokenType.EOF) { ErrorHandler.RaiseError(new UnexpectedTokenError(TokenType.EOF, "colon", tokens.List[tokens.CurrTokID].LineNo)); } tokens.Next(); } tokens.Move(currentPos); ParseExpression(whileNode); tokens.ConsumeToken(TokenType.Colon); ParseBlock(whileNode); }
public void VisitWhile(WhileNode node) { VisitWhileHandler(node); }
private AstNode Statement(LexemeSet stopSet) { AstNode res = null; logger.LogDebug($"Statement: {currentLexeme} [{stopSet}]"); if (CheckOrSkip(stopSet + startBlock, stopSet)) { switch (currentLexeme.Type) { case LexemeType.Identifier: string identifier = currentLexeme.Value.ToString(); // check id exists in the symbol table in the semantic analysis pass NextLexeme(); if (CheckOrSkip(LexemeType.Assign, stopSet + startExpression)) { NextLexeme(); res = new AssignmentNode() { Identifier = new IdentifierNode(identifier), Expression = Expression(stopSet), }; } break; case LexemeType.If: NextLexeme(); IfNode ifNode = new IfNode(); ifNode.Comparison = Comparison(stopSet + LexemeType.Then + startBlock - LexemeType.Identifier); if (CheckOrSkip(LexemeType.Then, stopSet + startBlock)) { NextLexeme(); } Block(stopSet, ifNode.Statements); res = ifNode; break; case LexemeType.While: NextLexeme(); WhileNode whileNode = new WhileNode(); whileNode.Comparison = Comparison(stopSet + LexemeType.Do + startBlock - LexemeType.Identifier); if (CheckOrSkip(LexemeType.Do, stopSet + startBlock)) { NextLexeme(); } Block(stopSet, whileNode.Statements); res = whileNode; break; case LexemeType.Write: NextLexeme(); if (CheckOrSkip(LexemeType.LBracket, stopSet + LexemeType.RBracket + startExpression)) { NextLexeme(); } WriteNode writeNode = new WriteNode(); writeNode.Expression = Expression(stopSet + LexemeType.RBracket); if (CheckOrSkip(LexemeType.RBracket, stopSet)) { NextLexeme(); } res = writeNode; break; } } return(res); }
public override void VisitWhileNode(WhileNode node) { StartCheckDeepInnerCycle(node.Stat); }
public override void VisitWhileNode(WhileNode node) { CheckIsInnerCycle(node.Stat); }
public override void Visit(WhileNode node) { OnEnter(node); base.Visit(node); OnExit(node); }
public ITreeNode Program() { ITreeNode programNode = new ErrorNode(); switch (curTokenType) { case TokenType.BEGINBL: Match(ref matchToken, TokenType.BEGINBL); ITreeNode someStatement = Program(); BlockNode block = new BlockNode(); block.addStatement(someStatement); while (curTokenType != TokenType.ENDBL) { someStatement = Program(); block.addStatement(someStatement); } Match(ref matchToken, TokenType.ENDBL); programNode = block; break; case TokenType.LABEL: Match(ref matchToken, TokenType.LABEL); LabelNode labeledBlock = new LabelNode(matchToken.getValue()); ITreeNode labeledStatement; do { labeledStatement = Program(); labeledBlock.addStatement(labeledStatement); } while (curTokenType != TokenType.EOF); programNode = labeledBlock; break; case TokenType.INTDEC: Match(ref matchToken, TokenType.INTDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.INT, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.BOOLDEC: Match(ref matchToken, TokenType.BOOLDEC); Match(ref matchToken, TokenType.ID); programNode = new IdentifierDeclarationNode(IdentifierType.BOOL, matchToken.getValue()); Match(ref matchToken, TokenType.EOS); break; case TokenType.FOR: Match(ref matchToken, TokenType.FOR); Match(ref matchToken, TokenType.LPAREN); AssignmentNode init = (AssignmentNode)Program(); AssignmentNode step = (AssignmentNode)Program(); BooleanExpressionNode condition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode forBody = (BlockNode)Program(); programNode = new ForNode(init, step, condition, forBody); break; /*case TokenType.FUN: Match(ref matchToken, TokenType.FUN); IdentifierNode id = (IdentifierNode)Factor(); programNode = new FunctionNode(id); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.GOTO: Match(ref matchToken, TokenType.GOTO); Match(ref matchToken, TokenType.ID); IdentifierNode gotoLabel = new IdentifierNode(matchToken.getValue(), IdentifierType.LABEL); programNode = new GotoNode(gotoLabel); Match(ref matchToken, TokenType.EOS); break; case TokenType.ID: Match(ref matchToken, TokenType.ID); IdentifierNode assignId = new IdentifierNode(matchToken.getValue(), IdentifierType.UNKNOWN); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode assignValue = (BooleanExpressionNode)BooleanExpression(); programNode = new AssignmentNode(assignId, assignValue); Match(ref matchToken, TokenType.EOS); break; case TokenType.IF: Match(ref matchToken, TokenType.IF); ITreeNode thenBranch; ITreeNode elseBranch; Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode ifCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); Match(ref matchToken, TokenType.THEN); thenBranch = (BlockNode)Program(); if (curTokenType == TokenType.ELSE) { Match(ref matchToken, TokenType.ELSE); elseBranch = (BlockNode)Program(); } else { elseBranch = new BlankNode(); } programNode = new IfNode(ifCondition, thenBranch, elseBranch); break; /*case TokenType.LET: Match(ref matchToken, TokenType.LET); IdentifierNode shortId = (IdentifierNode)Factor(); Match(ref matchToken, TokenType.ASSIGN); BooleanExpressionNode subst = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.IN); BooleanExpressionNode target = (BooleanExpressionNode)BooleanExpression(); programNode = new LetNode(shortId, subst, target); Match(ref matchToken, TokenType.EOS); break;*/ case TokenType.PRINT: Match(ref matchToken, TokenType.PRINT); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode printArgument = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); programNode = new PrintNode(printArgument); Match(ref matchToken, TokenType.EOS); break; case TokenType.WHILE: Match(ref matchToken, TokenType.WHILE); Match(ref matchToken, TokenType.LPAREN); BooleanExpressionNode whileCondition = (BooleanExpressionNode)BooleanExpression(); Match(ref matchToken, TokenType.RPAREN); BlockNode whileBody = (BlockNode)Program(); programNode = new WhileNode(whileCondition, whileBody); break; case TokenType.EOF: programNode = new BlankNode(); break; default: Expect(TokenType.UNKNOWN, lookAheadToken); break; } return programNode; }
public abstract void Visit(WhileNode node);
public void Visit(WhileNode node) { node.Condition.Accept(this); node.AcceptChildren(this); }
public void Visit(WhileNode node) { throw new NotImplementedException(); }
static Node ParseCommand() { Node node; switch (tokens.Current.Type) { case TokenTypes.IDEN: { node = new Identifier(tokens.Current.Value); tokens.SelectNext(); if (tokens.Current.Type != TokenTypes.EQUAL) { throw new RaulException($"Expected '=' after Identifier at {tokens.Position}"); } tokens.SelectNext(); node = new Assignment(node, ParseRelExpression()); break; } case TokenTypes.KEYWORD: { switch (tokens.Current.Value) { case Keywords.ECHO: { tokens.SelectNext(); node = new Echo(ParseRelExpression()); break; } case Keywords.WHILE: { tokens.SelectNext(); if (tokens.Current.Type != TokenTypes.LPAR) { throw new RaulException($"Expected '(' after WHILE stmnt at {tokens.Position}"); } tokens.SelectNext(); Node condition = ParseRelExpression(); if (tokens.Current.Type != TokenTypes.RPAR) { throw new RaulException($"Expected ')' after WHILE stmnt at {tokens.Position}"); } tokens.SelectNext(); node = new WhileNode(condition, ParseCommand()); return(node); } case Keywords.IF: { tokens.SelectNext(); if (tokens.Current.Type != TokenTypes.LPAR) { throw new RaulException($"Expected '(' after IF stmnt at {tokens.Position}"); } tokens.SelectNext(); Node condition = ParseRelExpression(); if (tokens.Current.Type != TokenTypes.RPAR) { throw new RaulException($"Expected ')' after IF stmnt at {tokens.Position}"); } tokens.SelectNext(); Node cond_true = ParseCommand(); if (tokens.Current.Type == TokenTypes.KEYWORD && tokens.Current.Value == Keywords.ELSE) { tokens.SelectNext(); node = new IfNode(condition, cond_true, ParseCommand()); } else { node = new IfNode(condition, cond_true); } return(node); } default: { throw new RaulException($"Hum... Nao era pra esse erro ser possivel..."); } } break; } case TokenTypes.LBRACE: { node = ParseBlock(); return(node); } default: { throw new RaulException($"Unexpected symbol at {tokens.Position}"); } } if (tokens.Current.Type == TokenTypes.SEMI) { tokens.SelectNext(); return(node); } else { throw new RaulException($"Expected ';' at {tokens.Position}"); } }
public override void Visit(WhileNode node) { node.Condition.Visit(this); node.Stat.Visit(this); }
public override void VisitWhileNode(WhileNode w) { w.Expr.Visit(this); w.Stat.Visit(this); }
public override void VisitWhileNode(WhileNode c) { c.Assign.Visit(this); c.Expr.Visit(this); c.Stat.Visit(this); }
internal abstract void Visit(WhileNode node);
public void VisitWhile(WhileNode node) { node.Condition = _processor.ProcessReplacement(node.Condition); node.Body = _processor.ProcessReplacement(node.Body); }
public virtual void PostWalk(WhileNode node) { }
public void Visit(WhileNode node) { visitor.OnVisit((n, v) => Result = IsSameChildren(n, node)); reference.Visit(visitor); }
private void addBlockNodes(XmlNodeList list, BaseNode lastNode, BaseNode parentNode) { foreach (XmlNode node in list) { BaseNode newNode = null; if (node.Name.Equals("End")) { newNode = endNode; } else if (node.Name.Equals("Start")) { newNode = startNode; } else if (node.Name.Equals("Assign")) { newNode = new AssignNode(); } else if (node.Name.Equals("Declare")) { newNode = new DeclareNode(); } else if (node.Name.Equals("Input")) { newNode = new InputNode(); } else if (node.Name.Equals("Output")) { newNode = new OutputNode(); } else if (node.Name.Equals("If")) { newNode = new IfNode(); setAttributes(node, newNode); addBlockNodes(node.FirstChild.ChildNodes, ((DecisionNode)newNode).TrueNode, newNode); } else if (node.Name.Equals("IfElse")) { newNode = new IfElseNode(); setAttributes(node, newNode); addBlockNodes(node.FirstChild.ChildNodes, ((IfElseNode)newNode).TrueNode, newNode); addBlockNodes(node.LastChild.ChildNodes, ((IfElseNode)newNode).FalseNode, newNode); } else if (node.Name.Equals("While")) { newNode = new WhileNode(); setAttributes(node, newNode); addBlockNodes(node.FirstChild.ChildNodes, ((DecisionNode)newNode).TrueNode, newNode); } else if (node.Name.Equals("DoWhile")) { newNode = new DoNode(); setAttributes(node, newNode); addBlockNodes(node.FirstChild.ChildNodes, ((DecisionNode)newNode).TrueNode, newNode); } else if (node.Name.Equals("For")) { newNode = new ForNode(); setAttributes(node, newNode); addBlockNodes(node.FirstChild.ChildNodes, ((DecisionNode)newNode).TrueNode, newNode); } else { showErrorMessage("Error not valid file"); } if (!(node.Name.Equals("Start") || node.Name.Equals("End"))) { BaseNode oldNode = lastNode.OutConnector.EndNode; lastNode.OutConnector.EndNode = newNode; newNode.OutConnector.EndNode = oldNode; newNode.addToModel(); newNode.ParentNode = parentNode; } lastNode = newNode; blockNodes.Add(new Pair(node, newNode)); setAttributes(node, newNode); } }
public override void Visit(WhileNode node) { if (node.Condition is BoolValNode bv && bv.Val == false) { ReplaceStatement(node, new EmptyStatement()); }
public virtual void VisitWhileNode(WhileNode w) { }
/// <summary> /// This visits a while node /// </summary> /// <param name="whileNode">The visited node</param> /// <returns></returns> public abstract object Visit(WhileNode whileNode);
public override bool Walk(WhileNode node) { AddNode(node); return(true); }
public object Process(Parser parser, SortedDictionary <string, object> parameters) { if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); return(null); } else if (parser.CurrenToken.Type == TokenType.KwIf) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftParent) { parser.NextToken(); var _evaluation = (ExpressionNode) new AssignmentExpression().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightParent) { parser.NextToken(); var _ifCode = (List <StatementNode>) new Statementp().Process(parser, parameters); var _ifNotCode = (ElseNode) new IfNot().Process(parser, parameters); var _if = new IfNode { EvaluationNode = _evaluation, IfCode = _ifCode, IfNotCode = _ifNotCode }; return(_if); } else { throw new ParserException("This was expected ) Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ( Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwWhile) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftParent) { parser.NextToken(); var _evaluation = (ExpressionNode) new AssignmentExpression().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightParent) { parser.NextToken(); var _whileCode = (List <StatementNode>) new Statementp().Process(parser, parameters); var _while = new WhileNode { EvaluationNode = _evaluation, CodeNode = _whileCode }; return(_while); } else { throw new ParserException("This was expected ) Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ( Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwFor) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftParent) { parser.NextToken(); var _for = (ForNode) new ForConditions().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightParent) { parser.NextToken(); var _forCode = (List <StatementNode>) new Statementp().Process(parser, parameters); _for.CodeNode = _forCode; return(_for); } else { throw new ParserException("This was expected ) Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ( Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwBreak) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); return(new BreakNode()); } else { throw new ParserException("This was expected ; Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwContinue) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); return(new ContinueNode()); } else { throw new ParserException("This was expected ; Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwThrow) { var _throw = new ThrowStatement().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); return(_throw); } else { throw new ParserException("This was expected ; Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwSwitch) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftParent) { parser.NextToken(); var _evaluation = (ExpressionNode) new AssignmentExpression().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightParent) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftCurlyBracket) { parser.NextToken(); var _caseBlock = (BaseCaseNode) new CaseBlock().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightCurlyBracket) { parser.NextToken(); var _switch = new SwitchNode { EvaluationNode = _evaluation, CaseBlockNode = _caseBlock }; return(_switch); } else { throw new ParserException("This was expected } Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected { Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ) Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ( Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwDo) { parser.NextToken(); var _doWhileCode = (List <StatementNode>) new Statementp().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.KwWhile) { parser.NextToken(); if (parser.CurrenToken.Type == TokenType.PmLeftParent) { parser.NextToken(); var _evaluation = (ExpressionNode) new AssignmentExpression().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmRightParent) { parser.NextToken(); var _doWhile = new DoWhileNode { EvaluationNode = _evaluation, CodeNode = _doWhileCode }; return(_doWhile); } else { throw new ParserException("This was expected ) Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected ( Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else { throw new ParserException("This was expected the token: while, Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwReturn) { parser.NextToken(); var _returnEp = (List <ExpressionNode>) new ExpressionOpt().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); var _return = new ReturnNode { ReturnExpressionNode = _returnEp }; return(_return); } else { throw new ParserException("This was expected ; Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } else if (parser.CurrenToken.Type == TokenType.KwTry) { parser.NextToken(); var _tryCode = (List <StatementNode>) new CompoundStatement().Process(parser, parameters); var _try = (TryNode) new CatchBlock().Process(parser, parameters); var _finally = (FinallyNode) new FinallyBlock().Process(parser, parameters); _try.FinallyCode = _finally; _try.TryCode = _tryCode; return(_try); } else { var _varEp = new VariablesOrExpression().Process(parser, parameters); if (parser.CurrenToken.Type == TokenType.PmSemicolon) { parser.NextToken(); return(_varEp); } else { throw new ParserException("This was expected ; Received: [" + parser.CurrenToken.LexemeVal + "], Row: " + parser.CurrenToken.Row + ", Column: " + parser.CurrenToken.Column); } } }
public virtual void PostWalk(WhileNode node) { }
public override void VisitWhileNode(WhileNode w) { Count += 1; base.VisitWhileNode(w); }
public override void VisitWhileNode(WhileNode w) { WithinCycle = true; base.VisitWhileNode(w); WithinCycle = false; }
public virtual void VisitWhileNode(WhileNode while_node) { }
public virtual void VisitWhile(WhileNode node) { VisitDefaultStatement(node); }
private static string getBlockCode(BaseNode startBlockNode, BaseNode endBlockNode) { StringBuilder sb = new StringBuilder(); sb.Append(" \r\n"); sb.Append(' ', indentation); sb.Append("{"); sb.Append(" \r\n"); indentation += 4; BaseNode node = startBlockNode; while (node != endBlockNode) { if (!(node is HolderNode || node is TerminalNode)) { sb.Append(' ', indentation); } if (node is HolderNode || node is TerminalNode) { ; } else if (node is IfElseNode) { IfElseNode ifNode = (IfElseNode)node; sb.Append(getExpression(NodeType.IFELSE, ifNode)); sb.Append(getBlockCode(ifNode.TrueNode, ifNode.BackNode)); sb.Append(' ', indentation); sb.Append("else"); sb.Append(getBlockCode(ifNode.FalseNode, ifNode.BackfalseNode)); } else if (node is IfNode) { IfNode ifNode = (IfNode)node; sb.Append(getExpression(NodeType.IF, ifNode)); sb.Append(getBlockCode(ifNode.TrueNode, ifNode.BackNode)); } else if (node is DoNode) { DecisionNode loopNode = (DecisionNode)node; sb.Append("Do"); sb.Append(getBlockCode(loopNode.TrueNode, loopNode.BackNode)); sb.Append(getExpression(NodeType.DOWHILE, node)); sb.Append(Environment.NewLine); } else if (node is ForNode) { ForNode loopNode = (ForNode)node; sb.Append(getExpression(NodeType.FOR, loopNode)); sb.Append(getBlockCode(loopNode.TrueNode, loopNode.BackNode)); } else if (node is WhileNode) { WhileNode loopNode = (WhileNode)node; sb.Append(getExpression(NodeType.WHILE, loopNode)); sb.Append(getBlockCode(loopNode.TrueNode, loopNode.BackNode)); } else if (node is InputNode) { sb.Append(getExpression(NodeType.INPUT, node)); } else if (node is OutputNode) { sb.Append(getExpression(NodeType.OUTPUT, node)); } else if (node is AssignNode) { sb.Append(getExpression(NodeType.ASSIGN, node)); } else if (node is DeclareNode) { sb.Append(getExpression(NodeType.DECLARE, node)); } sb.Append(Environment.NewLine); node = node.OutConnector.EndNode; } indentation -= 4; sb.Append(' ', indentation); sb.Append("}\r\n"); return(sb.ToString()); }
public void VisitWhile(WhileNode node) { WhileVisitor?.Visit(node); }
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 }
public virtual void Visit(WhileNode node) { if (node != null) { AcceptChildren(node); } }
public WhileOr(Func <bool> check, WhileNode otherNode) : base(check) { this.otherNode = otherNode; }
private static void GenerateWhile(WhileNode node, DataContext data) { StartLine(data, "while ("); GenerateExpression(node.EvaluateExpression, data); EndLine(data, ") {{"); data.CodeBlock.Padding++; GenerateStatementBlock(node.BodyStatementBlock, data); data.CodeBlock.Padding--; WriteLine(data, "}}"); }
public virtual void Visit(WhileNode node) { if (node != null) { if (node.Condition != null) { node.Condition.Accept(this); } if (node.Body != null) { node.Body.Accept(this); } } }