Yacc Yet Another Compiler-Compiler
Yacc:YetAnotherCompiler-Compiler
StephenC.Johnson
ABSTRACT
Computerprograminputgenerallyhassomestructure;infact,everycomputerpro-gramthatdoesinputcanbethoughtofasde ningan‘‘inputlanguage’’whichitaccepts.Aninputlanguagemaybeascomplexasaprogramminglanguage,orassimpleasasequenceofnumbers.Unfortunately,usualinputfacilitiesarelimited,dif culttouse,andoftenarelaxaboutcheckingtheirinputsforvalidity.
Yaccprovidesageneraltoolfordescribingtheinputtoacomputerprogram.TheYaccuserspeci esthestructuresofhisinput,togetherwithcodetobeinvokedaseachsuchstructureisrecognized.Yaccturnssuchaspeci cationintoasubroutinethathan-dlestheinputprocess;frequently,itisconvenientandappropriatetohavemostofthe owofcontrolintheuser’sapplicationhandledbythissubroutine.
TheinputsubroutineproducedbyYacccallsauser-suppliedroutinetoreturnthenextbasicinputitem.Thus,theusercanspecifyhisinputintermsofindividualinputcharacters,orintermsofhigherlevelconstructssuchasnamesandnumbers.Theuser-suppliedroutinemayalsohandleidiomaticfeaturessuchascommentandcontinuationconventions,whichtypicallydefyeasygrammaticalspeci cation.
YacciswritteninportableC.Theclassofspeci cationsacceptedisaverygeneralone:LALR(1)grammarswithdisambiguatingrules.
InadditiontocompilersforC,APL,Pascal,RATFOR,etc.,Yacchasalsobeenusedforlessconventionallanguages,includingaphototypesetterlanguage,severaldeskcalculatorlanguages,adocumentretrievalsystem,andaFortrandebuggingsystem.
0:Introduction
Yaccprovidesageneraltoolforimposingstructureontheinputtoacomputerprogram.TheYaccuserpreparesaspeci cationoftheinputprocess;thisincludesrulesdescribingtheinputstructure,codetobeinvokedwhentheserulesarerecognized,andalow-levelroutinetodothebasicinput.Yaccthengen-eratesafunctiontocontroltheinputprocess.Thisfunction,calledaparser,callstheuser-suppliedlow-levelinputroutine(thelexicalanalyzer)topickupthebasicitems(calledtokens)fromtheinputstream.Thesetokensareorganizedaccordingtotheinputstructurerules,calledgrammarrules;whenoneoftheseruleshasbeenrecognized,thenusercodesuppliedforthisrule,anaction,isinvoked;actionshavetheabilitytoreturnvaluesandmakeuseofthevaluesofotheractions.
YacciswritteninaportabledialectofC1andtheactions,andoutputsubroutine,areinCaswell.Moreover,manyofthesyntacticconventionsofYaccfollowC.
Theheartoftheinputspeci cationisacollectionofgrammarrules.Eachruledescribesanallow-ablestructureandgivesitaname.Forexample,onegrammarrulemightbe
date:month nameday´,´year;
Here,date,month name,day,andyearrepresentstructuresofinterestintheinputprocess;presumably,month name,day,andyeararede nedelsewhere.Thecomma‘‘,’’isenclosedinsinglequotes;thisimpliesthatthecommaistoappearliterallyintheinput.Thecolonandsemicolonmerelyserveaspunc-tuationintherule,andhavenosigni canceincontrollingtheinput.Thus,withproperde nitions,the
YACC 使用方式 YACC(Yet Another Compiler-Compiler) YACC使用方式: YACC说明文件 translate.y YACC编译器 Y.tab.c %yacc Y.tab.c translate.y a.out C语言...
而 Yacc( yet another compiler-compiler)能帮助完成步骤<2>。 本文给出了一个构建 lex/yacc 解析器的简单例子,并主要讨论了 yacc 中的冲 突错误。 2. lex/...
Yacc 另一个编译器的编译器_IT/计算机_专业资料。使用Yacc可以创建一个编译器,文章主要讲述Yacc使用方法。Yacc: Yet Another Compiler-Compiler Yacc: 另一个编译...
Yacc 代表 Yet Another Compiler Compiler Compiler。 让 我们从 Lex 开始吧。 Lex Lex 是一种生成扫描器的工具 扫描器是一种识别文本中的词汇模式的程序。这 ...
Yacc使用指南_IT/计算机_专业资料。编译原理YACC(BISON)使用指南 YACC(Yet Another Compile-Compiler)是语法分析器生成工具,它生成的是 LALR 分 析器。Yacc 于上...
yacc Yacc 代表 Yet Another Compiler Compiler。 Yacc 的 GNU 版叫做 Bison。它是一种工 具,将任何一种编程语言的所有语法翻译成针对此种语言的 Yacc 语 法...
Lex 代表 Lexical Analyzar.Yacc 代表 Yet Another Compiler Compiler. 让我们从 Lex 开始吧. Lex Lex 是一种生成扫描器的工具.扫描器是一种识别文本中的词汇...
金成植 编译程序构造原理和实现技术 2000 5.Johnson S C Yacc:Yet Another Compiler-Compiler 1978 6.Schroer F W The ACCENT Compiler Compiler,Introduction and...
关键词: 关键词: YACC 语法分析 冲突文法变换 模式 引言 YACC(Yet Another Compiler Compiler)是美国贝尔实验室著名的编译程 序生成系统, 用于开发以字符流输入的...
下面我们来讨论 Yacc... Yacc Yacc 代表 Yet Another Compiler Compiler。 Yacc 的 GNU 版叫做 Bison。它 是一种工具,将任何一种编程语言的所有语法翻译成针对...
热门文档