Example #1
0
        private ClassAST GenerateClassAST(ClassPrototypeAST prototype)
        {
            var classAst = new ClassAST {
                prototype = prototype
            };

            // 関数系をパース
            var functions = new List <FunctionAST>();

            while (this.LastToken.TokenType != TokenType.BlockEnd)
            {
                functions.Add(_functionAstGenerator.GenerateFunctionAST());
            }
            classAst.Functions = functions;

            return(classAst);
        }
Example #2
0
        public bool CompileName(ClassAST classAst, int index, bool isStatic)
        {
            this.ClassAST             = classAst;
            this.ClassContext         = classAst.ClassContext;
            this.ClassName            = classAst.ClassName;
            MethodContext             = new MethodContext(this.ClassContext, FnName.ToCode());
            MethodContext.MethodIndex = index;
            bool b = FnName.Analy(this, isStatic);

            if (b)
            {
                GenerateName(isStatic);
            }
            else
            {
                return(false);
            }
            return(true);
        }
Example #3
0
            public TypeAST Parse()
            {
                string baseType = "普通类型";

                if (ExtendsSection != null && ExtendsSection.BaseTypeToken != null)
                {
                    baseType = ExtendsSection.BaseTypeToken.Text;
                }

                if (baseType == "约定类型")
                {
                    EnumAST enumAST = new EnumAST(fileAST, NameSection, ExtendsSection, PropertiesSection);
                    return(enumAST);
                }
                else if (baseType == "声明类型")
                {
                    DimAST dimAST = new DimAST(fileAST, NameSection, ExtendsSection, PropertiesSection);
                    return(dimAST);
                }
                else
                {
                    ClassAST classAST = new ClassAST(fileAST, NameSection, ExtendsSection, PropertiesSection);
                    foreach (var item in Proces)
                    {
                        if (item.IsConstructor)
                        {
                            classAST.Constructors.Add(new ProcConstructor(classAST, item));
                        }
                        else
                        {
                            classAST.Methods.Add(new ProcMethod(classAST, item));
                        }
                    }
                    return(classAST);
                }
            }
Example #4
0
        public IEnumerable <ASTBase> Parse()
        {
            var asts = new List <ASTBase>();

            while (_tokenReader.HasNext)
            {
                this.ProceedToken();

                switch (this.LastToken.TokenType)
                {
                case TokenType.Using:
                    this.ProceedToken();     // using をスキップ
                    _usings.Add(this.LastToken.Value);
                    continue;

                case TokenType.Namespace:
                    this.ProceedToken();     // namespace をスキップ
                    _currentNamespace = this.LastToken.Value;
                    this.ProceedToken();     // : を消費すように一個ずらす
                    continue;
                }

                GenericModifier   modifier  = _modifierGenerator.GenerateModifier();
                ClassPrototypeAST prototype = this.GenerateClassPrototype(modifier);
                ClassAST          classAst  = this.GenerateClassAST(prototype);

                asts.Add(classAst);

                if (this.LastToken.TokenType == TokenType.BlockEnd)
                {
                    break;
                }
            }

            return(asts);
        }