public bool InterpreteNextAST() { if (Input.IsEnd()) { return(false); } try { switch (Input.Peek().ASTType) { // Valid cases... case AST.Classification.Say: InterpreteSay(); return(true); case AST.Classification.Set: InterpreteSet(); return(true); case AST.Classification.Choice: InterpreteChoice(); return(true); case AST.Classification.Label: InterpreteLabel(); return(true); case AST.Classification.Jump: InterpreteJump(); return(true); case AST.Classification.Return: InterpreteReturn(); return(true); case AST.Classification.LineBreak: break; // Some invalid cases... Not a statement. case AST.Classification.Identifier: throw new InvalidStatementPassedException("An identifier cannot be used as a statement."); case AST.Classification.String: throw new InvalidStatementPassedException("A string cannot be used as a statement."); case AST.Classification.Boolean: throw new InvalidStatementPassedException("A boolean value cannot be used as a statement."); case AST.Classification.Number: throw new InvalidStatementPassedException("A number value cannot be used as a statement."); case AST.Classification.Of: throw new InvalidStatementPassedException("Of statements cannot be used alone. They must be used with Set statements."); default: throw new InvalidStatementPassedException($"Invalid statement AST {Input.Peek().ASTType} was passed. An element such as Number cannot be a statement."); } if (Input.Peek().ASTType != AST.Classification.LineBreak) { throw new InvalidStatementPassedException("Each statements must be separated by line break."); } Input.Read(); // Remove the line break AST } catch (Exception e) { OutputManager.Exception(e); } return(true); }
public static void Main(string[] args) { bool RegisterFlag = false; foreach (string arg in args) { if (RegisterFlag) { Output.RegisterObject(new object(), arg); RegisterFlag = false; continue; } switch (arg) { case "-v": verbose = true; break; case "--token": WhatShouldIDo = "token"; break; case "--ast": WhatShouldIDo = "ast"; break; case "--interprete": WhatShouldIDo = "interprete"; break; case "--register": RegisterFlag = true; break; default: if (File.Exists(arg)) FilePath = arg; else Console.WriteLine("The given file was not found."); break; } } Console.WriteLine("DialogueShell - DialogueScript command line tester and parser"); Stream Source; if (FilePath == null) { while (true) { Console.Write(">>> "); string Expression = Console.ReadLine(); Console.WriteLine("- - - - - - - - - - - - - - -"); if (Expression.ToLower() == "exit") return; try { using (Source = Expression.ToStream()) DoEverything(Source, Output); } catch (Exception e) { Output.Exception(e); Console.WriteLine("Restarting DialogueShell... \n\n"); } } } else { try { using (Source = new FileStream(FilePath, FileMode.Open)) DoEverything(Source, Output); } catch (Exception e) { Output.Exception(e); Console.WriteLine("\nPress any key to close DialogueShell..."); Console.ReadKey(); } } }