Exemplo n.º 1
0
 public FunctionNode(IdentifierNode name, List <ParameterNode> parameters, List <StatementNode> body, ReturnNode returnNode) : base(SyntaxType.FUNCTION)
 {
     this.functionName = name;
     this.parameters   = parameters;
     this.body         = body;
     this.returnNode   = returnNode;
 }
Exemplo n.º 2
0
 public FunctionNode(IdentifierNode name, List <ParameterNode> parameters) : base(SyntaxType.FUNCTION)
 {
     this.functionName = name;
     this.parameters   = parameters;
     this.body         = null;
     this.returnNode   = null;
 }
Exemplo n.º 3
0
        private ReturnInstruction GenerateReturn(ReturnNode node)
        {
            SyntaxNode current          = node.returnValue;
            string     returnExpression = "";

            GenerateReturn(current, ref returnExpression);
            return(new ReturnInstruction(returnExpression));
        }
Exemplo n.º 4
0
        private FunctionNode ReadFunction()
        {
            IdentifierNode       functionName = ReadIdentifier();
            List <ParameterNode> parameters   = ReadParameters();

            if (tokenStream.ReadToken().type != TokenType.LEFT_BRACE)
            {
                throw new Exception("Expected Left Brace");
            }
            List <StatementNode> body       = ReadStatements();
            ReturnNode           returnNode = ReadReturn();

            if (tokenStream.ReadToken().type != TokenType.RIGHT_BRACE)
            {
                throw new Exception("Expected Right Brace");
            }
            return(new FunctionNode(functionName, parameters, body, returnNode));
        }
Exemplo n.º 5
0
        private SyntaxNode Bind(FunctionNode node, Dictionary <string, string> env)
        {
            Dictionary <string, string> localEnvironment = new Dictionary <string, string>();
            string name = "f" + GetFunctionCount();

            env.Add(node.functionName.identifier, name);
            List <ParameterNode> boundParams     = BindParameters(node.parameters, localEnvironment);
            List <StatementNode> boundStatements = new List <StatementNode>();

            foreach (StatementNode statement in node.body)
            {
                StatementNode boundStatement = Bind(statement, localEnvironment);
                boundStatements.Add(boundStatement);
            }
            ReturnNode boundReturn = null;

            if (node.returnNode != null)
            {
                boundReturn = BindReturn(node.returnNode, localEnvironment);
            }
            return(new FunctionNode(new IdentifierNode(name), boundParams, boundStatements, boundReturn));
        }
Exemplo n.º 6
0
        private ReturnNode BindReturn(ReturnNode node, Dictionary <string, string> environment)
        {
            SyntaxNode boundReturn = BindExpression(node.returnValue, environment);

            return(new ReturnNode(boundReturn));
        }