Ejemplo n.º 1
0
        static List <ast.Identifier> parseFunctionParameters()
        {
            List <ast.Identifier> identifiers = new List <ast.Identifier>();

            if (peekTokenIs(token.RPAREN))
            {
                nextToken();
                return(identifiers);
            }

            nextToken();

            ast.Identifier ident = new ast.Identifier {
                Token = curToken, Value = curToken.Literal
            };
            identifiers.Add(ident);

            while (peekTokenIs(token.COMMA))
            {
                nextToken();
                nextToken();
                ident = new ast.Identifier {
                    Token = curToken, Value = curToken.Literal
                };
                identifiers.Add(ident);
            }

            if (!expectPeek(token.RPAREN))
            {
                return(null);
            }

            return(identifiers);
        }
Ejemplo n.º 2
0
        static Object.Object evalIdentifier(ast.Identifier node, Object.Environment env)
        {
            Object.Object val = env.Get(node.Value);
            if (val != null)
            {
                return(val);
            }

            Object.Builtin builtin;
            if (evaluator_builtins.builtins.TryGetValue(node.Value, out builtin))
            {
                return(builtin);
            }

            return(newError("identifier not found: " + node.Value));;
        }
Ejemplo n.º 3
0
        static Object.Macro isMacroCall(ast.CallExpression exp, Object.Environment env)
        {
            if (!(exp.Function is ast.Identifier))
            {
                return(null);
            }
            ast.Identifier identifier = (ast.Identifier)exp.Function;

            Object.Object obj = env.Get(identifier.Value);
            if (obj == null)
            {
                return(null);
            }

            if (!(obj is Object.Macro))
            {
                return(null);
            }
            Object.Macro macro = (Object.Macro)obj;

            return(macro);
        }