public List <SectionRaw> Parse(IEnumerable <LineTokenCollection> lineTokens, ContextFile fileContext) { this.fileContext = fileContext; Sections.Clear(); List <LineTokenCollection> tokens = new List <LineTokenCollection>(lineTokens); tape = new ArrayTape <LineTokenCollection>(tokens.ToArray()); while (tape.HasCurrent) { if (IsSectionHead(tape.Current)) { SectionRaw section = ParseSection(); if (section != null) { Sections.Add(section); } } else { if (tape.Current.Count > 0) { error(tape.Current.FirstToken, "错误的段头"); } tape.MoveNext(); } } return(Sections); }
private TempTypeBody ParseTempTypeBody() { var tempTypeBody = new TempTypeBody(fileAST); while (tape.HasCurrent) { SectionRaw section = tape.Current; if (section is SectionNameRaw) { if (tempTypeBody.NameSection == null) { tempTypeBody.NameSection = (section as SectionNameRaw); tape.MoveNext(); } else { TypeAST tast = tempTypeBody.Parse(); fileAST.AddTypeAST(tast); break; } } //else if ((section is SectionExtendsRaw) || (section is SectionPropertiesRaw) || (section is SectionProcRaw)) //{ // ParseTypeSection(); //} else if (section is SectionExtendsRaw) { tempTypeBody.ExtendsSection = (section as SectionExtendsRaw); tape.MoveNext(); } else if (section is SectionPropertiesRaw) { tempTypeBody.PropertiesSection = (section as SectionPropertiesRaw); tape.MoveNext(); } else if (section is SectionProcRaw) { tempTypeBody.Proces.Add(section as SectionProcRaw); tape.MoveNext(); } else { throw new CCException(); } } return(tempTypeBody); }
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); }