Beispiel #1
0
        public FunctionDeclarationTree ParseFunctionDeclaration()
        {
            FunctionDeclarationTree function = new FunctionDeclarationTree();

            Match(TokenType.Let);
            function.Token = Match(TokenType.Identifier);
            Match(TokenType.OpenParenthesis);
            function.Parameters = ParseParameterList();
            Match(TokenType.CloseParenthesis);
            Match(TokenType.Assignment);
            function.Expression = ParseExpression();
            Match(TokenType.SemiColon);
            return(function);
        }
Beispiel #2
0
        public virtual List <CodeErrorException> TypeCheckFunctionDeclaration(FunctionDeclarationTree tree)
        {
            List <CodeErrorException> errors = new List <CodeErrorException>();

            if (tree.Parameters.Count != 1)
            {
                errors.Add(
                    new CodeErrorException(
                        tree.Token.Line,
                        tree.Token.StartPosition,
                        tree.Token.EndPosition,
                        string.Format(
                            "Function declaration '{0}' must be single variable.",
                            tree.Token.Value
                            )
                        )
                    );
            }
            FunctionParameterName = tree.Parameters[0].Value;
            errors.AddRange(TypeCheckExpression(tree.Expression));
            return(errors);
        }