예제 #1
0
        private Node HandlePositiveFactor()
        {
            double numberValue;

            if (_tokenizer.MatchDouble(out numberValue))
            {
                return(new ConstantNode(numberValue));
            }
            string identifier;

            if (_tokenizer.MatchIdentifier(out identifier))
            {
                return(new VariableNode(identifier));
            }
            if (_tokenizer.Match(TokenType.OpenPar))
            {
                var e = HandleSuperExpression();
                if (!_tokenizer.Match(TokenType.ClosePar))
                {
                    return(new ErrorNode("Expected )."));
                }
                return(e);
            }
            return(new ErrorNode("Expected number or (expression)."));
        }
예제 #2
0
        FunctionNode IsFunction()
        {
            if (!_tokenizer.MatchIdentifier("function"))
            {
                return(null);
            }

            string        name;
            string        returnType;
            List <string> parameters = new List <string>();

            // Si ensuite on a les autres infos et une ouverture de parenthèse
            if (_tokenizer.IsIdentifier(out returnType) &&
                _tokenizer.IsIdentifier(out name) &&
                _tokenizer.Match(TokenType.OpenPar))
            {
                // On prend tout les params
                while (!_tokenizer.Match(TokenType.ClosedPar))
                {
                    string parameterType;
                    string osef;
                    if (_tokenizer.IsIdentifier(out parameterType) && _tokenizer.IsIdentifier(out osef))
                    {
                        parameters.Add(parameterType);
                    }
                    else
                    {
                        AddError("PB !");
                        return(null);
                    }
                    _tokenizer.Match(TokenType.Comma);
                }
                if (_tokenizer.Match(TokenType.OpenCurly))
                {
                    FunctionNode fct = new FunctionNode(name, returnType, ParseFunctionBody(), parameters);
                    return(fct);
                }
                else
                {
                    AddError("Cannot begin function... :(");
                }
            }
            else
            {
                AddError("Error on Function creation...");
            }
            return(null);
        }