private IEnumerable <BaseAst> ConvertFor(ForAst node) { List <BaseAst> block = new List <BaseAst>(); internalLabelIdx++; int idx = internalLabelIdx; block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$ForBegin{0}", idx) }); IEnumerable <BaseAst> st = ConvertStatement(node.Init); block.AddRange(st); node.ConvertInit = st.First(); block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$ForCondition{0}", idx) }); ConditionAst cond = ConvertTo <ConditionAst>(node, AstNodeTypes.Condition); cond.Condition = NegateCondition(node.Condition); block.Add(cond); node.ConvertCondition = cond; GotoAst gt = new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$ForEnd{0}", idx) }; block.Add(gt); node.ConvertForEndBody = gt; block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$ForTrue{0}", idx) }); block.AddRange(ConvertStatement(node.ForBody)); st = ConvertStatement(node.Close); block.AddRange(st); node.ConvertClose = st.First(); block.Add(new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$ForCondition{0}", idx) }); block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$ForEnd{0}", idx) }); return(block); }
private BaseAst GetGotoAST(GotoAst cmd) { if (cmd == null) { return(BaseAst.GetErrorAstNode("Chybne volana funkce 'GetGotoAST(GotoAst cmd)', parametr 'cmd' je null")); } ReadNextAst(); if (actualNode.Token != TokenTypes.Identifier) { return(BaseAst.GetErrorAstNode(string.Format("Je ocekavano navesti, radek {0}, sloupec {1}", actualNode.TokenStartLine, actualNode.TokenStartColumn))); } cmd.Label = actualNode.TokenText; return(cmd); }
private IEnumerable <BaseAst> ConvertIf(IfAst node) { List <BaseAst> block = new List <BaseAst>(); internalLabelIdx++; int idx = internalLabelIdx; block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$IfBegin{0}", idx) }); ConditionAst cond = ConvertTo <ConditionAst>(node, AstNodeTypes.Condition); cond.Condition = NegateCondition(node.Condition); block.Add(cond); node.ConvertCondition = cond; if (node.ElseBody != null) { block.Add(new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$IfFalse{0}", idx) }); } else { block.Add(new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$IfEnd{0}", idx) }); } block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$IfTrue{0}", idx) }); block.AddRange(ConvertStatement(node.IfBody)); GotoAst gt = new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$IfEnd{0}", idx) }; block.Add(gt); node.ConvertIfEndBody = gt; if (node.ElseBody != null) { block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$IfFalse{0}", idx) }); block.AddRange(ConvertStatement(node.ElseBody)); gt = new GotoAst { Token = TokenTypes.GotoRW, AstType = AstNodeTypes.Goto, TokenText = "goto", Label = string.Format("$IfEnd{0}", idx) }; block.Add(gt); node.ConvertElseEndBody = gt; } block.Add(new BaseAst { Token = TokenTypes.Identifier, AstType = AstNodeTypes.Label, TokenText = string.Format("$IfEnd{0}", idx) }); return(block); }
private void PrintSAGoto(GotoAst gotoc) { Console.WriteLine(" goto {0};", gotoc.Label); }
private void WriteGoto(GotoAst ast, List<string> vars, string p, bool writeLE) { file.WriteLine("{0}goto {1};", p, ast.Label); if (writeLE) WriteLinearEquations(ast.Node, vars, p); }