private static Ast.Node ParseTerm( TokenStream Stream, ParseContext Context) { if (IsEndOfStatement(Stream)) throw new CompileError("[012] Expected argument", Stream); Ast.Node r = null; if (Stream.Next().Type == TokenType.OpenParen) { Stream.Advance(); r = ParseExpression(Stream, Context, TokenType.CloseParen); Stream.Advance(); //Skip close paren } else if (Stream.Next().Type == TokenType.OpenBracket) { var parameters = ParseStaticInvokation(Stream, Context); r = new Ast.StaticInvokation(parameters[0].Source, parameters); } else if (Stream.Next().Type == TokenType.Identifier || Stream.Next().Type == TokenType.Number || Stream.Next().Type == TokenType.String) { r = new Ast.Identifier(Stream.Next()); Stream.Advance(); } else if (Stream.Next().Type == TokenType.Operator) { r = new Ast.Identifier(Stream.Next()); Stream.Advance(); } else if (Stream.Next().Type == TokenType.Dollar) { return ParseComplexString(Stream, Context); } else if (Stream.Next().Type == TokenType.OpenBrace) { var start = Stream.Next(); Stream.Advance(); var list = new List<Ast.Node>(); while (Stream.Next().Type != TokenType.CloseBrace) list.Add(ParseTerm(Stream, Context)); Stream.Advance(); return new Ast.AssembleList(start, list); } else throw new CompileError("[014] Illegal token in argument list", Stream.Next()); r = ParseOptionalDot(Stream, r, Context); return r; }
private static Ast.Statement ParseStatement( TokenStream Stream, ParseContext Context) { Ast.Statement r = null; var firstToken = Stream.Next().Value.ToUpper(); if (firstToken == "LET") { r = ParseLetStatement(Stream, Context); } else if (firstToken == "IF") { r = ParseIfStatement(Stream, Context); } else if (firstToken == "RETURN") { r = ParseReturnStatement(Stream, Context); } else if (firstToken == "VAR" || firstToken == "VARIABLE") { r = ParseLocalDeclaration(Stream, Context); } else { //If it's not any special statement, it must be a function call. var parameters = ParseStaticInvokationStatement(Stream, Context); var control = Context.FindControl(parameters); if (control != null) { Ast.Node childBlock = null; if (control.BlockType == ControlBlockType.RequiredBlock) { if (Stream.Next().Type == TokenType.OpenBrace) childBlock = ParseBlock(Stream, Context); else throw new CompileError("[00C] Expected {", Stream); } else { if (Stream.Next().Type != TokenType.Semicolon) throw new CompileError("[00D] Expected ;", Stream); Stream.Advance(); } r = new Ast.ControlInvokation(parameters[0].Source, control, parameters, childBlock); } else { r = new Ast.StaticInvokation(parameters[0].Source, parameters); if (Stream.Next().Type != TokenType.Semicolon) throw new CompileError("[00E] Expected ;", Stream); Stream.Advance(); } } return r; }