Exemple #1
0
        private SectionBase ParseSection()
        {
            string headText = tape.Current.GetText();

            if (headText.StartsWith("导入"))
            {
                SectionImport section = ParseImport();
                return(section);
            }
            else if (headText.StartsWith("使用"))
            {
                SectionUse section = ParseUse();
                return(section);
            }
            else if (headText.StartsWith("约定"))
            {
                SectionEnum section = ParseEnum();
                return(section);
            }
            else if (headText.StartsWith("声明"))
            {
                SectionDim section = ParseDim();
                return(section);
            }
            else if (headText.EndsWith("类型"))
            {
                SectionClassName section = ParseClass();
                return(section);
            }
            else if (headText.EndsWith("属性"))
            {
                SectionProperties section = ParseProperties();
                return(section);
            }
            else
            {
                SectionProc section = ParseProc();
                if (section.NamePart.IsConstructor())
                {
                    SectionConstructor constructor = new SectionConstructor(section);
                    return(constructor);
                }
                else
                {
                    return(section);
                }
                //tape.error("错误的段落");
                //tape.MoveNext();
                //return null;
            }
        }
Exemple #2
0
        private SectionProc ParseProc()
        {
            SectionProc ast = new SectionProc();

            //TokenTape nameTape = new TokenTape(sectionRaw.Content);
            ast.NamePart = ParseProcName();
            tape.Match(TokenKind.Colon);
            ast.RetToken = ParseRetProc();
            if (ast.NamePart == null)
            {
                return(null);
            }
            ast.Body = ParseProcBody();
            return(ast);
        }
Exemple #3
0
        public FileMutilType Parse(List <Token> tokens, ContextFile fileContext)
        {
            tape               = new TokenTape(tokens, fileContext);
            fileMY             = new FileMutilType();
            fileMY.FileContext = fileContext;

            while (tape.CurrentKind != TokenKind.EOF)
            {
                TokenKind nkind = tape.Next.Kind;
                if (nkind == TokenKind.Colon && tape.CurrentKind == TokenKind.Ident)
                {
                    SectionBase section = ParseSection();
                    if (section != null)
                    {
                        fileMY.AddSection(section);
                    }
                }
                else if (tape.CurrentKind == TokenKind.NewLine)
                {
                    SkipNewLine();
                }
                else
                {
                    SectionProc section = ParseProc();
                    if (section != null)
                    {
                        if (section.NamePart.IsConstructor())
                        {
                            SectionConstructor constructor = new SectionConstructor(section);
                            fileMY.AddSection(constructor);
                        }
                        else
                        {
                            fileMY.AddSection(section);
                        }
                    }
                }
            }
            return(fileMY);
        }