⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ss1

📁 UNIX v6源代码 这几乎是最经典的unix版本 unix操作系统设计和莱昂氏unix源代码分析都是用的该版
💻
字号:
.SHSection 1: Basic Specifications.PPAs we noted above, names refer to either tokens or nonterminal symbols.Yacc requires those names which will beused as token names to be declared as such.In addition, for reasons which will be discussed in Section 3, it is usually desirableto include the lexical analyzer as part of the specification file;it may be useful to include other programs as well.Thus, every specification file consists of three sections:the.uldeclarations,.ul(grammar) rules,and.ulprograms.The sections are separated by double percent ``%%'' marks.(The per-cent ``%'' is generally used in Yacc specifications as an escape character.).PPIn other words, a full specification file looks like.DSdeclarations%%rules%%programs.DE.PPThe declaration section may be empty.Moreover, if the programs section is omitted, the second %% mark may be omitted also;thus, the smallest legal Yacc specification is.DS%%rules.DE.PPBlanks, tabs, and newlines are ignored exceptthat they may not appear in names or multi-character reserved symbols.Comments may appear wherever a name or operator is legal; they are enclosedin /* . . . */, as in C and PL/I..PPThe rules section is made up of one or more grammar rules.A grammar rule has the form:.DSA  :  BODY  ;.DEA represents a nonterminal name, and BODY represents a sequence of zero or more names and literals.Notice that the colon and the semicolon are Yacc punctuation..PPNames may be of arbitrary length, and may be made up of letters, dot ``.'', underscore ``\_'', andnon-initial digits.Notice that Yacc considers that upper and lower case letters are distinct.The names used in the body of a grammar rule may represent tokens or nonterminal symbols..PPA literal consists of a character enclosed in single quotes ``\'''.As in C, the backslash ``\e'' is an escape character within literals, and all the C escapesare recognized.Thus.DS\'\en\'	represents newline\'\er\'	represents return\'\e\'\'	represents single quote ``\'''\'\e\e\'	represents backslash ``\e''\'\et\'	represents tab\'\eb\'	represents backspace\'\exxx\' represents ``xxx'' in octal.DEFor a number of technical reasons, the nul character (\'\e0\' or 000) should neverbe used in grammar rules..PPIf there are several grammar rules with the same left hand side, the vertical bar ``|''can be used to avoid rewriting the left hand side.In addition,the semicolon at the end of a rule can be dropped before a vertical bar.Thus the grammar rules.DSA : B C D   ;A : E F   ;A : G   ;.DEcan be given to Yacc as.DSA :	B C D |	E F |	G ;.DEIt is not necessary that all grammar rules with the same left side appear together in the grammar rules section,although it makes the input much more readable, and easy to change..PPIf a nonterminal symbol matches the empty string, this can be indicated in the obvious way:.DSempty :   ;.DE.PPAs we mentioned above, names which representtokens must be declared as such.The simplest way of doing this is to write.DS%token   name1 name2 . . ..DEin the declarations section.(See Sections 3 and 4 for much more discussion).Every name not defined in the declarations section is assumed to represent a nonterminal symbol.If, by the end of the rules section, some nonterminal symbol has not appeared on the leftof any rule, then an error message is produced and Yacc halts..PPThe left hand side of the.Ifirst.Rgrammar rule in the grammar rules section has special importance; it is taken to be thecontrolling nonterminal symbol for the entire input process;in technical language it is called the.Istart symbol..RIn effect, the parser is designed to recognize the start symbol; thus,this symbol generally represents the largest,most general structure described by the grammar rules..PPThe end of the input is signaled by a special token, called the.ulendmarker.If the tokens up to, but not including, the endmarker form a structurewhich matches the start symbol, the parser subroutine returns to its callerwhen the endmarker is seen; we say that it.ulacceptsthe input.If the endmarker is seen in any other context, it is an error..PPIt is the job of the user supplied lexical analyzerto return the endmarker when appropriate; see section 3, below.Frequently, the endmarker token represents some reasonably obvious I/O status, such as ``end-of-file'' or ``end-of-record''.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -