资源描述:
《有穷自动机在词法分析中的应用》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、有穷自动机在词法分析中的应用郝亮1
2、北京林业大学,北京100083(heroleo@163.com)TheapplicationoffiniteautomatoninlexicalanalysisofcompilingprincipleLiangHao"1(BeijingForestryUniversity,Beijing100083)AbstractLexicalanalysisisasequenceofchiiractersinthecomputerscienceconvertwordseq
3、uenceprocess,lexicalanalysisisthefirststageofthecompilationprocess,anditstaskislefttoright,acharacter,acharacterreadintothesourcecodeordocumentationoftheconstitutioncharacterstreamsourceordocumentscanninganddecomposition,therebyidentifyingwordsandsen
4、tagranimarprogram.Lexicalanalyzeroutputbutthesystemisoftenexpressedasabinarynotationstyleforms,suchas(thewordspeciesdonot,thepropertyvalueofwordsymbols).Thefiniteautomata(FA)isdividedintoadeterministicfiniteautomaton(DFA)andnon-deterministicfiniteaut
5、omata(NFA),whichisusedtodescribeaspecifictypeofalgorithmofmathematicalmethods.Inparticular,afiniteautomatoncanbeusedasdescribedintheidentificationprocessintheinputstring,usinganalyticalmethodscanprocessmoreintuitiveunderstandingoflexicalanalysisoffin
6、iteautomata・Finitestatemachinediagramindicatesalsosimplifiesourlexicalanalysisofstatetransitionsofunderstanding.FiniteAutomataLexicalanalysisiswidelyused.KeywordsLexicalanalysis;finiteautomata;DFA;NFA;regularexpression摘要词法分析是计算机科学中将字符序列转换为单词序列的过程,词法分
7、析是编译过程的第一个阶段,它的任务是从左到右一个字符,一个字符地读入源程序或文档,对构成源程序或文档的字符流进行扫描和分解,从而识别出一个个单词并发送给语法程序。词法分析器所输出的但系符号常常表示成二元式的形式,如(单词种别,单词符号的属性值)。而有穷自动机(FA)分为确定型有穷自动机(DFA)和非确定型有穷自动机(NFA),它是用来描述特定类型算法的数学方法。特别地,有穷自动机可用作描述在输入串中识别的过程,用有穷自动机的分析方法可以更加直观的理解词法分析的过程。有穷状态机图的表示也可以简化我
8、们对词法分析中的状态转换的理解。有穷自动机在词法分析中的应用非常广泛。关键词词法分析;有穷自动机;DFA;NFAo中图法分类号TP391阶类号伍号1.词法分析与有穷自动机词法分析(英语:lexicalanalysis)是计算机科学中将字符序列转换为单词(Token)序列的过程。进行词法分析的程序或者两数叫作词法分析(Lexicalanalyzer,简称Lexer),也叫扫描器1.1词法分析概念(Scanner)o词法分析器一般以函数的形式存在,供语法分析器调用。完成词法分析任务的程序称为词法分析
9、程序或词法分析器扫描器。从编译的允度来看词法分析是编译过程的第一个阶段,它的任务是从左到右一个字符,一个字符地读入或文档,对构成源程序或文档的字符流进行扫描和分解,从而识别出一个个单词并发送给语法程序。词法分析任务:(1)分析和识别单词及属性,包括识别语言的关键字、标识符、常数、运算符等;(2)跳过各种分隔符,如空格,回车,制表符等;(3)删除注释;(4)进行词法检杏,报告所发现的错课;(5)建立符号表。词法分析器所输出的但系符号常常表示成二元式的形式,如(单词种别,单词符号的属性值)。词法分析