亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tply.doc

?? YACC和LEX的資料書籍 以及一些源碼 很有幫助
?? DOC
?? 第 1 頁 / 共 4 頁
字號:


Lexical Analysis
----------------

For any TP Yacc-generated parser, the programmer must supply a lexical
analyzer routine named yylex which performs the lexical analysis for
the parser. This routine must be declared as

   function yylex : Integer;

The yylex routine may either be prepared by hand, or by using the lexical
analyzer generator TP Lex (see Section `TP Lex').

The lexical analyzer must be included in your main program behind the
parser subroutine (the yyparse code template includes a forward
definition of the yylex routine such that the parser can access the
lexical analyzer). For instance, you may put the lexical analyzer
routine into the auxiliary procedures section of your TP Yacc grammar,
either directly, or by using the the Turbo Pascal include directive
($I).

The parser repeatedly calls the yylex routine to tokenize the input
stream and obtain the individual lexical items in the input. For any
literal character, the yylex routine has to return the corresponding
character code. For the other, symbolic, terminals of the input language,
the lexical analyzer must return corresponding Integer codes. These are
assigned automatically by TP Yacc in the order in which token definitions
appear in the definitions section of the source grammar. The lexical
analyzer can access these values through corresponding Integer constants
which are declared by TP Yacc in the output file.

For instance, if

   %token NUM

is the first definition in the Yacc grammar, then TP Yacc will create
a corresponding constant declaration

   const NUM = 257;

in the output file (TP Yacc automatically assigns symbolic token numbers
starting at 257; 1 thru 255 are reserved for character literals, 0 denotes
end-of-file, and 256 is reserved for the special error token which will be
discussed in Section `Error Handling'). This definition may then be used,
e.g., in a corresponding TP Lex program as follows:

   [0-9]+   return(NUM);

You can also explicitly assign token numbers in the grammar. For this
purpose, the first occurrence of a token identifier in the definitions
section may be followed by an unsigned integer. E.g. you may write:

   %token NUM 299

Besides the return value of yylex, the lexical analyzer routine may also
return an additional semantic value for the recognized token. This value
is assigned to a variable named "yylval" and may then be accessed in actions
through the $i notation (see above, Section `Grammar Rules and Actions').
The yylval variable is of type YYSType (the semantic value type, Integer
by default); its declaration may be found in the YYPARSE.COD file.

For instance, to assign an Integer value to a NUM token in the above
example, we may write:

   [0-9]+   begin
              val(yytext, yylval, code);
              return(NUM);
            end;

This assigns yylval the value of the NUM token (using the Turbo Pascal
standard procedure val).

If a parser uses tokens of different types (via a %token <name> definition),
then the yylval variable will not be of type Integer, but instead of a
corresponding variant record type which is capable of holding all the
different value types declared in the TP Yacc grammar. In this case, the
lexical analyzer must assign a semantic value to the corresponding record
component which is named yy<name> (where <name> stands for the corresponding
type identifier).

E.g., if token NUM is declared Real:

   %token <Real> NUM

then the value for token NUM must be assigned to yylval.yyReal.


How The Parser Works
--------------------

TP Yacc uses the LALR(1) technique developed by Donald E. Knuth and F.
DeRemer to construct a simple, efficient, non-backtracking bottom-up
parser for the source grammar. The LALR parsing technique is described
in detail in Aho/Sethi/Ullman (1986). It is quite instructive to take a
look at the parser description TP Yacc generates from a small sample
grammar, to get an idea of how the LALR parsing algorithm works. We
consider the following simplified version of the arithmetic expression
grammar:

%token NUM
%left '+'
%left '*'
%%
expr : expr '+' expr
     | expr '*' expr
     | '(' expr ')'
     | NUM
     ;

When run with the /v option on the above grammar, TP Yacc generates the
parser description listed below.

state 0:

	$accept : _ expr $end

	'('	shift 2
	NUM	shift 3
	.	error

	expr	goto 1

state 1:

	$accept : expr _ $end
	expr : expr _ '+' expr
	expr : expr _ '*' expr

	$end	accept
	'*'	shift 4
	'+'	shift 5
	.	error

state 2:

	expr : '(' _ expr ')'

	'('	shift 2
	NUM	shift 3
	.	error

	expr	goto 6

state 3:

	expr : NUM _	(4)

	.	reduce 4

state 4:

	expr : expr '*' _ expr

	'('	shift 2
	NUM	shift 3
	.	error

	expr	goto 7

state 5:

	expr : expr '+' _ expr

	'('	shift 2
	NUM	shift 3
	.	error

	expr	goto 8

state 6:

	expr : '(' expr _ ')'
	expr : expr _ '+' expr
	expr : expr _ '*' expr

	')'	shift 9
	'*'	shift 4
	'+'	shift 5
	.	error

state 7:

	expr : expr '*' expr _	(2)
	expr : expr _ '+' expr
	expr : expr _ '*' expr

	.	reduce 2

state 8:

	expr : expr '+' expr _	(1)
	expr : expr _ '+' expr
	expr : expr _ '*' expr

	'*'	shift 4
	$end	reduce 1
	')'	reduce 1
	'+'	reduce 1
	.	error

state 9:

	expr : '(' expr ')' _	(3)

	.	reduce 3


Each state of the parser corresponds to a certain prefix of the input
which has already been seen. The parser description lists the grammar
rules wich are parsed in each state, and indicates the portion of each
rule which has already been parsed by an underscore. In state 0, the
start state of the parser, the parsed rule is

	$accept : expr $end

This is not an actual grammar rule, but a starting rule automatically
added by TP Yacc. In general, it has the format

	$accept : X $end

where X is the start nonterminal of the grammar, and $end is a pseudo
token denoting end-of-input (the $end symbol is used by the parser to
determine when it has successfully parsed the input).

The description of the start rule in state 0,

	$accept : _ expr $end

with the underscore positioned before the expr symbol, indicates that
we are at the beginning of the parse and are ready to parse an expression
(nonterminal expr).

The parser maintains a stack to keep track of states visited during the
parse. There are two basic kinds of actions in each state: "shift", which
reads an input symbol and pushes the corresponding next state on top of
the stack, and "reduce" which pops a number of states from the stack
(corresponding to the number of right-hand side symbols of the rule used
in the reduction) and consults the "goto" entries of the uncovered state
to find the transition corresponding to the left-hand side symbol of the
reduced rule.

In each step of the parse, the parser is in a given state (the state on
top of its stack) and may consult the current "lookahead symbol", the
next symbol in the input, to determine the parse action - shift or reduce -
to perform. The parser terminates as soon as it reaches state 1 and reads
in the endmarker, indicated by the "accept" action on $end in state 1.

Sometimes the parser may also carry out an action without inspecting the
current lookahead token. This is the case, e.g., in state 3 where the
only action is reduction by rule 4:

	.	reduce 4

The default action in a state can also be "error" indicating that any
other input represents a syntax error. (In case of such an error the
parser will start syntactic error recovery, as described in Section
`Error Handling'.)

Now let us see how the parser responds to a given input. We consider the
input string 2+5*3 which is presented to the parser as the token sequence:

   NUM + NUM * NUM

The following table traces the corresponding actions of the parser. We also
show the current state in each move, and the remaining states on the stack.

State  Stack         Lookahead  Action
-----  ------------  ---------  --------------------------------------------

0                    NUM        shift state 3

3      0                        reduce rule 4 (pop 1 state, uncovering state
                                0, then goto state 1 on symbol expr)

1      0             +          shift state 5

5      1 0           NUM        shift state 3

3      5 1 0                    reduce rule 4 (pop 1 state, uncovering state
                                5, then goto state 8 on symbol expr)

8      5 1 0         *          shift 4

4      8 5 1 0       NUM        shift 3

3      4 8 5 1 0                reduce rule 4 (pop 1 state, uncovering state
                                4, then goto state 7 on symbol expr)

7      4 8 5 1 0                reduce rule 2 (pop 3 states, uncovering state
                                5, then goto state 8 on symbol expr)

8      5 1 0         $end       reduce rule 1 (pop 3 states, uncovering state
                                0, then goto state 1 on symbol expr)

1      0             $end       accept

It is also instructive to see how the parser responds to illegal inputs.
E.g., you may try to figure out what the parser does when confronted with:

   NUM + )

or:

   ( NUM * NUM

You will find that the parser, sooner or later, will always run into an
error action when confronted with errorneous inputs. An LALR parser will
never shift an invalid symbol and thus will always find syntax errors as
soon as it is possible during a left-to-right scan of the input.

TP Yacc provides a debugging option (/d) that may be used to trace the
actions performed by the parser. When a grammar is compiled with the
/d option, the generated parser will print out the actions as it parses
its input.


Ambigious Grammars
------------------

There are situations in which TP Yacc will not produce a valid parser for
a given input language. LALR(1) parsers are restricted to one-symbol
lookahead on which they have to base their parsing decisions. If a
grammar is ambigious, or cannot be parsed unambigiously using one-symbol
lookahead, TP Yacc will generate parsing conflicts when constructing the
parse table. There are two types of such conflicts: shift/reduce conflicts
(when there is both a shift and a reduce action for a given input symbol
in a given state), and reduce/reduce conflicts (if there is more than
one reduce action for a given input symbol in a given state). Note that
there never will be a shift/shift conflict.

When a grammar generates parsing conflicts, TP Yacc prints out the number
of shift/reduce and reduce/reduce conflicts it encountered when constructing
the parse table. However, TP Yacc will still generate the output code for the
parser. To resolve parsing conflicts, TP Yacc uses the following built-in
disambiguating rules:

- in a shift/reduce conflict, TP Yacc chooses the shift action.

- in a reduce/reduce conflict, TP Yacc chooses reduction of the first
  grammar rule.

The shift/reduce disambiguating rule correctly resolves a type of
ambiguity known as the "dangling-else ambiguity" which arises in the
syntax of conditional statements of many programming languages (as in
Pascal):

%token IF THEN ELSE
%%
stmt : IF expr THEN stmt
     | IF expr THEN stmt ELSE stmt
     ;

This grammar is ambigious, because a nested construct like

   IF expr-1 THEN IF expr-2 THEN stmt-1 ELSE stmt-2

can be parsed two ways, either as:

   IF expr-1 THEN ( IF expr-2 THEN stmt-1 ELSE stmt-2 )

or as:

   IF expr-1 THEN ( IF expr-2 THEN stmt-1 ) ELSE stmt-2

The first interpretation makes an ELSE belong to the last unmatched
IF which also is the interpretation chosen in most programming languages.
This is also the way that a TP Yacc-generated parser will parse the construct
since the shift/reduce disambiguating rule has the effect of neglecting the
reduction of IF expr-2 THEN stmt-1; instead, the parser will shift the ELSE
symbol which eventually leads to the reduction of IF expr-2 THEN stmt-1 ELSE
stmt-2.

The reduce/reduce disambiguating rule is used to resolve conflicts that
arise when there is more than one grammar rule matching a given construct.
Such ambiguities are often caused by "special case constructs" which may be
given priority by simply listing the more specific rules ahead of the more
general ones.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲最色的网站| 91亚洲精品一区二区乱码| 国产精品成人午夜| 精品国产伦一区二区三区观看体验| 日本韩国欧美一区| 在线视频综合导航| 欧美日本韩国一区二区三区视频| 不卡一区二区三区四区| 99国产欧美久久久精品| 97久久精品人人爽人人爽蜜臀| 成人免费av网站| 91在线视频免费观看| 在线看国产一区| 在线播放日韩导航| 久久综合色一综合色88| 一区二区三区日韩欧美精品| 亚洲午夜精品一区二区三区他趣| 亚洲国产视频在线| 亚洲444eee在线观看| 天堂久久久久va久久久久| 日韩av中文在线观看| 久久国产精品99久久人人澡| 国产激情91久久精品导航| av在线播放一区二区三区| 在线亚洲高清视频| 欧美mv和日韩mv国产网站| 国产精品久久国产精麻豆99网站| 亚洲欧美激情在线| 蜜臀久久99精品久久久画质超高清| 国产精品一品视频| 91搞黄在线观看| 久久久久久久久一| 亚洲一区欧美一区| 国产成人在线免费观看| 欧美午夜不卡视频| 欧美激情综合五月色丁香小说| 亚洲国产精品久久久久秋霞影院| 久久9热精品视频| 色综合久久久久久久| 精品国产伦一区二区三区免费| 亚洲欧美日韩精品久久久久| 久草在线在线精品观看| 色综合久久久久网| 国产欧美精品一区二区三区四区| 一区二区三区欧美激情| 国产乱码字幕精品高清av | 欧美亚洲国产一区在线观看网站 | 国产精品国产三级国产a| 首页亚洲欧美制服丝腿| 99视频精品在线| 久久亚洲免费视频| 日本午夜精品一区二区三区电影| 成人激情免费网站| 日韩一级二级三级精品视频| 亚洲国产日韩a在线播放性色| 国产精品一区免费视频| 日韩写真欧美这视频| 一区二区三区在线影院| 成人av免费在线观看| 欧美精品一区二区三区很污很色的| 一区二区三区色| 91啪在线观看| 中文字幕一区二区视频| 国产精品18久久久久久久久久久久| 3atv在线一区二区三区| 亚洲一区二区精品视频| 色婷婷亚洲精品| 亚洲精品欧美专区| 91片黄在线观看| 日韩美女视频一区二区| 成+人+亚洲+综合天堂| 国产精品免费久久久久| 高清成人在线观看| 国产精品美女久久久久久久 | 欧美视频一区二区在线观看| 亚洲青青青在线视频| www..com久久爱| 中文字幕一区二区日韩精品绯色| 成人动漫在线一区| 国产精品久久久久久久久动漫| 国产不卡免费视频| 成人欧美一区二区三区| 色悠悠亚洲一区二区| 亚洲一区二区三区四区的| 在线成人免费观看| 狠狠色2019综合网| 国产精品久久久久久久久搜平片 | 99久久精品99国产精品| 综合精品久久久| 91免费在线视频观看| 亚洲国产精品久久人人爱蜜臀| 欧美精品第1页| 精品一区二区三区日韩| 国产日产欧美一区| 91蜜桃在线免费视频| 五月天欧美精品| 久久久三级国产网站| 91亚洲男人天堂| 日韩国产精品久久久久久亚洲| 精品乱人伦小说| 岛国精品在线播放| 亚洲成人综合视频| 精品久久久影院| 91国产精品成人| 久草精品在线观看| 一区二区欧美国产| 久久久三级国产网站| 欧美视频自拍偷拍| 成人午夜视频网站| 婷婷国产v国产偷v亚洲高清| 精品国产免费人成在线观看| 91在线视频免费91| 韩国av一区二区三区四区 | 日韩精品高清不卡| 国产人成一区二区三区影院| 色94色欧美sute亚洲线路一久| 老司机精品视频一区二区三区| 国产精品美女久久久久久2018| 欧美一区二区视频观看视频| www.一区二区| 久久99国内精品| 亚州成人在线电影| 1区2区3区欧美| 国产欧美一区二区三区网站| 欧美精品日韩一本| 色综合夜色一区| 国产成人在线影院 | 国产精品毛片大码女人| 日韩午夜激情免费电影| 在线免费观看不卡av| 成人午夜精品在线| 久久精品久久久精品美女| 亚洲免费观看高清完整版在线 | 亚洲第一在线综合网站| 综合分类小说区另类春色亚洲小说欧美 | 欧美日韩小视频| 97se亚洲国产综合自在线| 国产自产v一区二区三区c| 天堂午夜影视日韩欧美一区二区| 亚洲蜜桃精久久久久久久| 中文字幕第一页久久| 国产女人aaa级久久久级| www国产精品av| 欧美xxx久久| 精品日产卡一卡二卡麻豆| 日韩午夜中文字幕| 欧美电视剧免费观看| 日韩欧美自拍偷拍| 欧美成人精品1314www| 欧美一卡二卡三卡四卡| 欧美一区二区啪啪| 91精品欧美久久久久久动漫| 欧美日韩免费一区二区三区| 欧美特级限制片免费在线观看| 欧美少妇一区二区| 在线观看一区日韩| 在线观看91av| 日韩欧美高清在线| 久久午夜老司机| 国产婷婷色一区二区三区在线| 国产欧美综合在线| 国产精品久久网站| 亚洲乱码国产乱码精品精的特点| 亚洲精品午夜久久久| 性做久久久久久久免费看| 日韩高清不卡一区二区| 麻豆91在线播放免费| 国产麻豆精品在线| 成人18视频在线播放| 91福利国产成人精品照片| 欧美精品久久一区| 精品粉嫩aⅴ一区二区三区四区| 久久久五月婷婷| 亚洲精品v日韩精品| 日韩高清不卡在线| 懂色av中文字幕一区二区三区| 99久久国产综合色|国产精品| 欧美日韩在线直播| 欧美电影免费观看高清完整版| 国产精品麻豆网站| 亚洲狠狠爱一区二区三区| 久久精品国产精品亚洲综合| 高清日韩电视剧大全免费| 欧洲亚洲国产日韩| 久久影院午夜论| 亚洲一区在线观看网站| 国产一区在线精品| 欧美熟乱第一页| 国产亚洲综合在线| 亚瑟在线精品视频| 成人成人成人在线视频| 91 com成人网| 国产精品网站导航| 久久91精品国产91久久小草| 99re在线精品| 久久综合狠狠综合久久综合88| 自拍偷拍国产精品| 精品一区二区在线视频| 在线观看日韩毛片| 国产精品系列在线|