コード例 #1
0
ファイル: ZFileEngine.cs プロジェクト: pyzh/ZLanguage3
        public FileAST Parse(SourceFileModel fileModel)
        {
            ContextFile fileContext           = new ContextFile(this.projectContext, fileModel);
            List <LineTokenCollection> Tokens = Scan(fileContext, fileModel);
            //foreach (LineTokenCollection ltc in Tokens)
            //{
            //    Console.WriteLine(ltc);
            //    foreach(LexToken tok in ltc.ToList())
            //    {
            //        Console.Write(tok.Text+" ");
            //    }
            //    Console.WriteLine();
            //}
            FileRawParser parser        = new FileRawParser();
            FileRaw       fileRaw       = parser.Parse(Tokens, fileContext); //FileMutilTypeRaw
            FileASTParser fileASTParser = new FileASTParser();
            FileAST       fileAST       = fileASTParser.Parse(fileRaw, fileContext);

            //FileSource fileType = ParseSingleMutil(fileMutilType);
            //if (fileType != null)
            //{
            //    fileType.FileModel = fileModel;
            //    fileType.ProjectContext = this.projectContext;
            //}
            //return fileType;
            return(fileAST);
        }
コード例 #2
0
 public ClassAST(FileAST fileAST)
 {
     this.fileAST  = fileAST;
     ImportPackage = fileAST.ImportPackage;
     MethodList    = fileAST.MethodList;
     PropertyList  = fileAST.PropertyList;
     ClassContext  = new ClassContext(fileAST.ProjectContext, ClassName);
     SimpleUse     = fileAST.SimpleUse;
 }
コード例 #3
0
        public FileAST ParseFile()
        {
            prog = new FileAST();
            while (CurrentToken.Kind != TokenKind.EOF)
            {
                if (CurrentToken.IsKeyIdent("使用包" /*,"使用类型","简略使用"*/) && NextToken.Kind == TokenKind.Colon)
                {
                    var ast = ParseImport();
                    prog.Add(ast);
                }

                if (CurrentToken.IsKeyIdent("简略使用") && NextToken.Kind == TokenKind.Colon)
                {
                    var ast = ParseSimpleUse();
                    prog.Add(ast);
                }

                if (CurrentKind == TokenKind.Ident && CurrentText == "过程" && NextToken.Kind == TokenKind.Colon)
                {
                    MethodAST ast = ParseMethod();
                    prog.Add(ast);
                }
                else if (CurrentKind == TokenKind.Ident && CurrentText == "属性" && NextToken.Kind == TokenKind.Colon)
                {
                    parseStaticPropertyPart();
                }
                else if (CurrentToken.IsKeyIdent("属于") && NextToken.Kind == TokenKind.Colon)
                {
                    parseExtends();
                }
                else if (CurrentToken.IsKeyIdent("名称") && NextToken.Kind == TokenKind.Colon)
                {
                    parseName();
                }
                else if (CurrentToken.IsKeyIdent("约定") && NextToken.Kind == TokenKind.Colon)
                {
                    parseAgreement();
                }
                else
                {
                    error("无法识别'" + CurrentToken.GetText() + "'");
                    MoveNext();
                }
            }
            return(prog);
        }
コード例 #4
0
 public EnumAST(FileAST fileAST)
 {
     this.fileAST = fileAST;
     if (fileAST.AgreementList.Count == 0)
     {
         errorf("不存在约定值");
     }
     else if (fileAST.AgreementList.Count > 1)
     {
         errorf("一个文件只能定义一个约定");
     }
     else
     {
         ast            = fileAST.AgreementList[0];
         nameToken      = fileAST.NameToken;
         ProjectContext = fileAST.ProjectContext;
     }
 }
コード例 #5
0
        public FileAST Parse(FileRaw fileRaw, ContextFile fileContext)
        {
            fileAST = new FileAST(fileContext);
            tape    = new ArrayTape <SectionRaw>(fileRaw.Sections);

            while (tape.HasCurrent)
            {
                SectionRaw section = tape.Current;
                if (section is SectionImportRaw)
                {
                    fileAST.ImportSection = new SectionImport(fileAST, section as SectionImportRaw);
                    tape.MoveNext();
                }
                else if (section is SectionUseRaw)
                {
                    //fileAST.UseSection = (section as SectionUse);
                    //fileAST.UseSection.FileContext = fileAST.FileContext;
                    //tape.MoveNext();
                    fileAST.UseSection = new SectionUse(fileAST, section as SectionUseRaw);
                    //fileAST.ImporteSection.FileContext = fileAST.FileContext;
                    tape.MoveNext();
                }
                //else if (section is SectionNameRaw)
                //{
                //    ParseType();
                //}
                else if ((section is SectionExtendsRaw) || (section is SectionPropertiesRaw) || (section is SectionProcRaw) || section is SectionNameRaw)
                {
                    //ParseTypeSection();
                    var     tempTypeBody = ParseTempTypeBody();
                    TypeAST tast         = tempTypeBody.Parse();
                    fileAST.AddTypeAST(tast);
                }
                else
                {
                    throw new CCException();
                }
            }

            return(fileAST);
        }
コード例 #6
0
ファイル: ZProjectEngine.cs プロジェクト: pyzh/ZLanguage3
        private void CompileFiles()
        {
            ZFileEngine parser = new ZFileEngine(ProjectContext);

            foreach (var item in projectModel.SouceFileList)
            {
                FileAST fileType = parser.Parse(item);
                if (fileType != null)
                {
                    List <IZObj> zltypes = fileType.Compile();
                    foreach (var zltype in zltypes)
                    {
                        this.ProjectContext.CompiledTypes.Add(zltype);
                    }
                }
                else
                {
                    throw new CCException();
                }
            }
        }
コード例 #7
0
 public TempTypeBody(FileAST fileAST)
 {
     this.fileAST = fileAST;
 }
コード例 #8
0
 public StaticClassAST(FileAST fileAST) : base(fileAST)
 {
 }
コード例 #9
0
 public NormalClassAST(FileAST fileAST)
     : base(fileAST)
 {
 }