private EXEASTNodeComposite ConstructAssignmentCommandAST(String Command) { EXEASTNodeComposite AST = null; if (!IsAssignment(Command)) { return(AST); } String SanitizedCommand = ParseUtil.SqueezeWhiteSpace(Command); // Console.WriteLine("ConstrAssign:" + SanitizedCommand + "EOL"); int SplitIndex = SanitizedCommand.IndexOf('='); String Storage = SanitizedCommand.Substring(0, SplitIndex); String Value = SanitizedCommand.Substring(SplitIndex + 1); // Console.WriteLine("Assigning " + Value + " to " + Storage); /*String[] CommandTokens = SanitizedCommand.Split('='); * * * AST = new EXEASTNodeComposite("="); * AST.AddOperand(ConstructAST(CommandTokens[0])); * AST.AddOperand(ConstructAST(String.Join("", CommandTokens.Skip(2).ToArray())));*/ AST = new EXEASTNodeComposite("="); AST.AddOperand(ConstructAST(Storage)); AST.AddOperand(ConstructAST(Value)); // Console.WriteLine("Assigned"); return(AST); }
private EXEASTNode ConstructControlCommandAST(String Command) { throw new NotImplementedException(); EXEASTNode AST = null; if (!IsControlCommand(Command)) { return(AST); } String SanitizedCommand = ParseUtil.SqueezeWhiteSpace(Command); String[] CommandTokens = SanitizedCommand.Split(' '); if (CommandTokens[0] == "continue" || CommandTokens[0] == "break") { //AST = new EXEASTNodeLeaf(CommandTokens[0], false, false, false); } else if (CommandTokens[0] == "return") { EXEASTNodeComposite TempAST = new EXEASTNodeComposite(CommandTokens[0]); TempAST.AddOperand(ConstructAST(CommandTokens[1])); } return(AST); }
public EXEASTNode ConstructExprASTAlt(String Expression) { //Console.WriteLine("ConsASTAlt:" + Expression + "EOL"); String ModifiedExpression = ParseUtil.SqueezeWhiteSpace(Expression); (String, int)TopLevelOperator = IdentifyFirstTopLevelOperator(ModifiedExpression); Boolean ExprContainsOperator = ContainsOperator(ModifiedExpression); while (TopLevelOperator.Item2 == -1 && ExprContainsOperator) { ModifiedExpression = ModifiedExpression.Substring(1, ModifiedExpression.Length - 2); if (ModifiedExpression.Length == 0) { break; } TopLevelOperator = IdentifyFirstTopLevelOperator(ModifiedExpression); ExprContainsOperator = ContainsOperator(ModifiedExpression); } //Console.WriteLine("ConsASTAlt,unbracketed:" + ModifiedExpression + "EOL"); EXEASTNodeComposite AST = new EXEASTNodeComposite(TopLevelOperator.Item1); if (TopLevelOperator.Item2 != 0) { AST.AddOperand(ConstructAST(ModifiedExpression.Substring(0, TopLevelOperator.Item2))); } AST.AddOperand(ConstructAST(ModifiedExpression.Substring( TopLevelOperator.Item2 + TopLevelOperator.Item1.Length ))); return(AST); }