public override CSResult BuildToCS(BuildEnvironment Env) { if (ToSay is VariableParseNode) { VariableParseNode vpn = ToSay as VariableParseNode; if (Env.CurrentContext.VariableExists(vpn.Name)) { BuildVariable variable = Env.CurrentContext.GetVariable(vpn.Name); return(new CSResult() { GeneratedCS = new CSLineList() { new CSLine("Console.Write(" + variable.Name + ");", T.LineNumber) } }); } return(new CSResult() { GeneratedCS = new CSLineList() { new CSLine("Console.Write(\"mysterious\");", T.LineNumber) } }); } else { throw new NotImplementedException(); } }
public override CSResult BuildToCS(BuildEnvironment Env) { CSLineList cs = new CSLineList(); if (Env.CurrentContext.VariableExists(Variable.Name)) { BuildVariable existingVar = Env.CurrentContext.GetVariable(Variable.Name); if (existingVar.Type != BuildVariableType.String) { existingVar.Type = BuildVariableType.String; existingVar.CodeCount++; cs.Add(existingVar.CSType + " " + existingVar.CodeName + " = Console.ReadLine();", T.LineNumber); } else { cs.Add(existingVar.CodeName + " = Console.ReadLine();", T.LineNumber); } } else { BuildVariable newVar = new BuildVariable(BuildVariableType.String, Variable.Name); Env.CurrentContext.AddVariable(newVar); cs.Add(newVar.CSType + " " + newVar.CodeName + " = Console.ReadLine();", T.LineNumber); } return(new CSResult() { GeneratedCS = cs }); }
public override CSResult BuildToCS(BuildEnvironment Env) { BuildVariableType typeOfAssignment = BuildVariableType.Undefined; string value = "null"; if (Value is BooleanParseNode) { typeOfAssignment = BuildVariableType.Boolean; value = (Value as BooleanParseNode).Value ? "true" : "false"; } else if (Value is NullParseNode) { typeOfAssignment = BuildVariableType.Null; value = "null"; } else if (Value is ParseNodeList) { typeOfAssignment = BuildVariableType.Numeric; value = ""; List <ParseNode> wordNodes = (Value as ParseNodeList).GetNodes(); wordNodes.ForEach(pn => value += (pn as WordParseNode).Text.Length % 10); } else if (Value is StringParseNode) { typeOfAssignment = BuildVariableType.String; value = (Value as StringParseNode).Value; } CSLineList cs = new CSLineList(); if (Env.CurrentContext.VariableExists(Variable.Name)) { BuildVariable existingVar = Env.CurrentContext.GetVariable(Variable.Name); if (existingVar.Type != typeOfAssignment) { existingVar.CodeCount++; existingVar.Type = typeOfAssignment; cs.Add(existingVar.CSType + " " + existingVar.CodeName + " = " + value + ";", T.LineNumber); } else { cs.Add(existingVar.CodeName + " = " + value + ";", T.LineNumber); } } else { BuildVariable newVariable = new BuildVariable(typeOfAssignment, Variable.Name); Env.CurrentContext.AddVariable(newVariable); cs.Add(newVariable.CSType + " " + newVariable.CodeName + " = " + value + ";", T.LineNumber); } return(new CSResult() { GeneratedCS = cs, ReturnType = null }); }