Ejemplo n.º 1
0
        public Attribution ParseAttribution(TokenIdentifier functionIdentifier)
        {
            if (Peek() != functionIdentifier)
            {
                throw new ParseFatalException($"The current node ({Peek().ToString()}) is not the same as the required ({functionIdentifier.ToString()}). The parser is about to possibly parse an attribution to a variable, but it cannot determine the variable name.", this);
            }

            var next = ReadNext();

            if (next is TokenAttribution) //good chances it's an attribution
            {
                next = ReadNext();
                var expr = ParseExpression(false);

                var tok = Peek();
                if (tok is TokenNewLine || tok is TokenEOF)
                {
                    return(new Attribution(functionIdentifier, expr));
                }
                else
                {
                    throw new ParseException("Expected a newline or end of file, got " + tok.ToString(), this);
                }
            }
            else
            {
                return(null); //it's not an attribution. What is the parser expecting? Return null and let the caller decide
            }
        }
Ejemplo n.º 2
0
        public Call ParseFunctionCall(TokenIdentifier functionIdentifier)
        {
            if (Peek() != functionIdentifier)
            {
                throw new ParseFatalException($"The current node ({Peek().ToString()}) is not the same as the required ({functionIdentifier.ToString()}). The parser is about to possibly parse a function call, but it cannot determine the function name.", this);
            }

            var next = ReadNext();

            if (next is TokenOpenParen)
            {
                //good chance it will be a function call
                //then, the next it's either a close paren or an expression
                next = ReadNext();
                if (next is TokenCloseParen) //a close paren creates a function call without arguments
                {
                    return(new Call(functionIdentifier.Identifier));
                }
                else
                {
                    var exprList = ParseExpressionList(true);
                    return(new Call(functionIdentifier.Identifier, exprList));
                }
            }
            else
            {
                return(null); //it's not a function call. What is the parser expecting? Return null and let the caller decide
            }
        }