您好,欢迎访问三七文档
ThedesignandimplementationoftheFIREengine:AC++toolkitforFIniteautomataandRegularExpressionsBruceW.WatsonFacultyofMathematicsandComputingScienceEindhovenUniversityofTechnologyP.O.Box5135600MBEindhovenTheNetherlandsemail:watson@win.tue.nlMay17,1994AbstractThispaperdescribesthedesignandimplementationofversion1.1oftheFIREengine.TheFIREengineisaC++classlibraryimplementing niteautomataandregularexpressionalgorithms.Thealgorithmsimplementedinthetoolkitarealmostallofthosepresentedinthetaxonomiesof niteautomataalgorithms[Wat93a,Wat93b].ThereaderisassumedtobefamiliarwiththetwotaxonomiesandwithadvancedC++programmingtechniques.Thetoolkitisimplementedlargelyinanobject-orientedstyle,with niteautomataandregularexpressionsbeingde nedasclasses.Alloftheclassesandfunctionsinthetoolkitarepresentedinthesameformat.Foreachclass(orfunction)theformatincludesashortdescriptionofitsbehaviour,detailsofitsimplementation,andtechniquesforimprovingitsperformance.CONTENTSContents1Introduction31.1Codingconventionsandperformanceissues::::::::::::::::::::::31.1.1Performancetuning:::::::::::::::::::::::::::::::41.2Presentationconventions:::::::::::::::::::::::::::::::::4IFoundationclasses52Characterranges53Bitvectors154Statesandrelatedclasses245Transitionsandrelatedclasses356Relations47IIRegularexpressionsand -algebras677Regularexpressions677.1SimilarityofREs:::::::::::::::::::::::::::::::::::::757.2Derivatives::::::::::::::::::::::::::::::::::::::::838The -algebra848.1The -termalgebraRegRE:::::::::::::::::::::::::::::86IIIAutomataandtheircomponents899Abstract niteautomata8910DeterministicFAs9111ConstructingaDFA9811.1Abstractstatesandthesubsetconstruction::::::::::::::::::::::9811.2Derivativesofregularexpressions::::::::::::::::::::::::::::10311.3Itemsets:::::::::::::::::::::::::::::::::::::::::10712Finiteautomata12112.1The -algebraRegFA::::::::::::::::::::::::::::::::12813Reduced niteautomata13313.1The -algebraRegRFA::::::::::::::::::::::::::::::::14414Left-biased niteautomata14715Right-biased niteautomata15416Automataconstructions161IVMinimizingDFAs165CONTENTS17Helperfunctions16618Aho,Sethi,andUllman’salgorithm16819HopcroftandUllman’salgorithm17020Hopcroft’salgorithm17321Anewminimizationalgorithm175References17831IntroductionTheFIREengineisaclasslibraryimplementing niteautomataandregularexpressionalgo-rithms.Thealgorithmsimplementedareallofthealgorithmspresentedinthetaxonomiesof niteautomataalgorithms[Wat93a,Wat93b].Thispaperoutlinesthedesignandimplementationoftheclasslibrary,whichconsistsof9000linesofC++code.Anumberofothertoolkits(mostlyservingdi erentpurposes)areavailable;theyaredetailedin[Wat94],whichalsocontainsanintroductiontotheFIREengine.InordertounderstandtheimplementationoftheFIREengine,thereaderisassumedtobefamiliarwiththetaxonomies[Wat93a,Wat93b],andwithC++terminologyandprogrammingtechniques.AnintroductiontotheC++languagecanbefoundin[Lip91,Str91](thelanguagereferenceappearsin[Str91,SE90]),whileanintroductiontoC++programmingtechniquescanbefoundin[Bud94].AdvancedC++programmingtechniquesarepresentedin[Cop92,MeS92,Mur93].Object-orientedprogramming,ingeneral,isdiscussedin[Boo94,Bud91,MeB88].Themoste ectivewaytounderstandtheimplementationoftheclasslibraryistoreadthecodeandthecommentsembeddedwithinthecode.Theexplanationsgiveninthispaperareintendedasanoutline,toassistinunderstandingthecode.Thispaperisstructuredasfollows: PartIprovidesdescriptionsofallofthefoundationsclasses|thoseclassesusedintheimplementationsofotherclasses. PartIIgivesdescriptionsofallclassesrelatedtoregularexpressionsand -algebras. PartIIIgivesdescriptionsofallclassesimplementing niteautomata. PartIVpresentsthefunctionsimplementingdeterministic niteautomataminimizationalgorithms.Acknowledgements:Iwouldliketothankthefollowingpeoplefortheirassistanceinthepreparationofthispaper:Pieter’tHoen(forimplementingtwoofthealgorithmsfrom[Wat93b]),andKeesHemerik,ErikPoll,NanetteSaes,andGerardZwaan(forprovidingstylesuggestionsonthispaper).1.1CodingconventionsandperformanceissuesThetoolkitiscodedinastylewhichmakesheavyuseoftheassertfunction.Forallexceptthesimplestclasses,amemberfunctioncalledclassinvariantisde ned;thismemberreturns1iftheobjectisstructurallysound,and0otherwise.Allmemberfunctionswhicharevisibletoclientsshouldonlybeinvokedonstructurallysoundobjectsandmustleavetheobjectinastructurallysoundcondition.Thefunctioncallassert(classinvariant())isexplicitlyinvokedatthebeginingandendofallsuchmemberfunctions(except,ofcourse,thefunctionclassinvariant).Thede nitionoftheclassinvariantisausefulstartingpointforunderstandingthestructureandimplementationofaparticularclass.Additionalassertionsareusedinplaceswheretheincorrectvaluesofvariables(orrelationsbetweenvariables)willcausecatastrophicresults(i.e.themachineislikelytocrash).Assertionsarealsousedinplaceswheretheymaybeofuseinunderstandingthesurroundingcode.Asmentionedbelow,assertcanbedisabledbycompilingwiththemacroNDEBUGde ned|meaningthatthereisnoassertionoverheadinaproductionversionoftheFIREengine.Almostalloftheclasseshaveanostreami
本文标题:The design and implementation of the FIRE engine A
链接地址:https://www.777doc.com/doc-6446047 .html