Exemple #1
0
        //done
        private void ParseFunction(Node subtree)
        {
            FunctionNode func = new FunctionNode(subtree);
            //we already checked we had a Define
            tokens.Next();
            SymbolTable.EnterScope();
            //Define Return Name(params):
            tokens.ConsumeToken(TokenType.Type);
            func.ReturnType = tokens.LastToken.Value;

            tokens.ConsumeToken(TokenType.Ident);
            func.Ident = tokens.LastToken.Value;

            tokens.ConsumeToken(TokenType.LeftParen);
            if (tokens.CurrentToken != TokenType.RightParen)
            {
                ParseFunctionParamList(func);
            }
            tokens.ConsumeToken(TokenType.RightParen).ConsumeToken(TokenType.Colon); //and close
            FunctionTable.Add(func.CreateSignature(), func);
            ParseBlock(func);
            if (func.ReturnType == "Void")
            {
                func.Children[1].AddChild(new ReturnNode(func.Children[1]));
            }
            SymbolTable.ExitScope();
        }