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); }
// Parse statements public AST ParseSay() { AST result = null; if (Input.IsEnd(3)) { return(result); } Token Speaker = Input.Read(), Colon = Input.Read(), Conversation = Input.Read(); if (Colon.TokenType == Token.Classification.Punctuation && Colon.Content == ":" && Conversation.TokenType == Token.Classification.String) { result = AST.CreateSayAST(AST.CreateIdentifierAST(Speaker.Content), AST.CreateStringAST(Conversation.Content)); } return(result); }