public static void ParseParametersList(Parser.State state, FunctionNode function) { if (state.GetToken().Is(TokenType.EOF)) { state.ErrorCode = (uint)ErrorCodes.T_UnexpectedEndOfFile; state.ErrorMessage = "Required <Identifier> as a function parameter"; return; } state.Save(); var token = state.GetTokenAndMoveNe(); if (!token.Is(TokenType.Identifier)) { state.Restore(); state.ErrorCode = (uint)ErrorCodes.P_IdentifierExpected; state.ErrorMessage = "Required <Identifier> as a function parameter"; return; } state.Drop(); function.Parameter = new VariableNode(token.Value); if (!state.GetToken().Is(TokenSubType.BraceSquareRight)) { state.ErrorCode = (uint)ErrorCodes.P_ClosingBraceRequired; state.ErrorMessage = "Required <BraceSquareRight> at the end of the function parameters list"; return; } state.GetNextNeToken(); }
private static ExpressionNode ParseUnit(Parser.State state, Context context) { if (state.GetToken().Is(TokenSubType.BraceSquareLeft)) { state.GetNextNeToken(); var func = new FunctionNode(); FunctionParser.ParseParametersList(state, func); if (state.IsErrorOccured()) { return(null); } var subContext = new Context(context, context.Values); func.Code = Parse(state, subContext); func.Context = subContext; if (state.IsErrorOccured()) { return(null); } return(func); } return(ParseValue(state, context)); }
private static ExpressionNode ParseValue(Parser.State state) { state.Save(); var token = state.GetTokenAndMoveNe(); if (token.Is(TokenType.Number)) { state.Drop(); return(new NumberNode( value: token.Value, isDecimal: token.Is(TokenSubType.Decimal) )); } else if (token.Is(TokenType.Identifier)) { state.Drop(); return(new VariableNode(token.Value)); } else if (token.Is(TokenType.String)) { state.Drop(); return(new StringNode(token.Value)); } else if (token.Is(TokenSubType.BraceRoundLeft)) { state.Drop(); var node = Parse(state); if (state.IsErrorOccured()) { return(node); } if (!state.GetToken().Is(TokenSubType.BraceRoundRight)) { state.ErrorCode = (uint)ErrorCodes.P_ClosingBraceRequired; state.ErrorMessage = "Expected <BraceRoundRight>, " + $"but <{state.GetToken().SubType}> was given"; return(node); } state.GetNextNeToken(); return(node); } state.Restore(); return(null); }
public static ExpressionNode Parse(Parser.State state) { if (state.IsErrorOccured() || state.GetToken().Is(TokenType.EOF)) { return(null); } var block = new BlockNode(); do { while (state.GetToken().Is(TokenSubType.Colon)) { state.GetNextNeToken(); } var unit = ParseUnit(state); FunctionCallNode fc_unit; if (unit == null || state.IsErrorOccured()) { break; } while (!state.IsErrorOccured() && !state.GetToken().Is(TokenType.EOF) && (fc_unit = ParseFunctionCall(state, unit)) != null) { unit = fc_unit; } block.Code.Add(unit); } while (state.GetToken().Is(TokenSubType.Colon)); return(block); }