internal override Syntax_Node ParseLex(Lex.Data data) { switch (data.token) { case Token.Keyword: { var keyword = (Keyword)data.number.i_32; switch (keyword) { case Keyword.Interface: return(AddChild(Syntax_Node.Create <Syntax_Interface>(data, this))); case Keyword.Class: return(AddChild(Syntax_Node.Create <Syntax_Class>(data, this))); default: { var exception = new SyntaxException(Syntax.Error.InvalidKeyword); exception.content = keyword.ToString(); throw exception; } } } case Token.Identify: return(AddChild(Syntax_Node.Create <Syntax_Function>(data, this))); default: { var exception = new SyntaxException(Syntax.Error.InvalidToken); exception.content = data.token.ToString(); throw exception; } } }
public static void ParseStream(StreamReader reader, string path = null) { var root = Syntax_Node.Create <Syntax_File>(); root.path = path; var context = new Context(root); Lex.ParseStream(reader, LexDataReceiver, context); if (!(context.node is Syntax_File)) { var exception = new SyntaxException(Error.NotComplete); exception.content = context.node.ToString(); throw exception; } }
internal override Syntax_Node ParseLex(Lex.Data data) { switch (codePhase) { case CodePhase.Code: // TODO parse code switch (data.token) { case Token.Keyword: { var keyword = (Keyword)data.number.i_32; switch (keyword) { case Keyword.If: return(AddChild(Syntax_Node.Create <Syntax_If>(data, this))); case Keyword.Loop: return(AddChild(Syntax_Node.Create <Syntax_Loop>(data, this))); case Keyword.Block: return(AddChild(Syntax_Node.Create <Syntax_Block>(data, this))); case Keyword.Return: codePhase = CodePhase.Return; return(this); default: // { // var exception = new SyntaxException(Syntax.Error.InvalidKeyword); // exception.content = keyword.ToString(); // throw exception; // } return(this); } } default: // { // var exception = new SyntaxException(Syntax.Error.InvalidToken); // exception.content = data.token.ToString(); // throw exception; // } return(this); } case CodePhase.Return: switch (data.token) { case Token.Keyword: // TODO save if (Syntax.constantKeywordList.Contains((Keyword)data.number.i_32)) { // TODO save codePhase = CodePhase.ReturnSeparator; return(this); } else { var exception = new SyntaxException(Syntax.Error.InvalidToken); exception.content = data.token.ToString(); throw exception; } case Token.Identify: // TODO save codePhase = CodePhase.ReturnSeparator; return(this); default: if (Syntax.constantTokenList.Contains(data.token)) { // TODO save codePhase = CodePhase.ReturnSeparator; return(this); } else { var exception = new SyntaxException(Syntax.Error.InvalidToken); exception.content = data.token.ToString(); throw exception; } } case CodePhase.ReturnSeparator: if (Token.Operator == data.token) { var op = (Operator)data.number.i_32; if (Operator.Comma == op) { codePhase = CodePhase.Return; return(this); } else { var exception = new SyntaxException(Syntax.Error.InvalidOperator); exception.content = op.ToString(); throw exception; } } else { var exception = new SyntaxException(Syntax.Error.InvalidToken); exception.content = data.token.ToString(); throw exception; } } return(this); }