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

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

?? tply.tex

?? 編譯原理基礎
?? TEX
?? 第 1 頁 / 共 5 頁
字號:
      A terminal identifier introduced in a precedence definition may, but
      need not, appear in a \verb"%token" definition as well.
   \item
      type definitions: Any (terminal or nonterminal) grammar symbol may be
      associated with a type identifier which is used in the processing of
      semantic values. Type tags of the form \verb"<name>" may be used in
      token and precedence definitions to declare the type of a terminal
      symbol, e.g.:
      \begin{quote}\begin{verbatim}
   %token <Real>  NUM
   %left  <AddOp> '+' '-'
      \end{verbatim}\end{quote}

      To declare the type of a nonterminal symbol, use a type definition of
      the form:
      \begin{quote}\begin{verbatim}
   %type <name> symbol ...
      \end{verbatim}\end{quote}
      e.g.:
      \begin{quote}\begin{verbatim}
   %type <Real> expr
      \end{verbatim}\end{quote}

      In a \verb"%type" definition, you may also omit the nonterminals, i.e.
      you may write:
      \begin{quote}\begin{verbatim}
   %type <name>
      \end{verbatim}\end{quote}

      This is useful when a given type is only used with type casts (see
      Section {\em Grammar Rules and Actions\/}), and is not associated with
      a specific nonterminal.
   \item
      Turbo Pascal declarations: You may also include arbitrary Turbo Pascal
      code in the definitions section, enclosed in \verb"%{ %}". This code
      will be inserted as global declarations into the output file, unchanged.
\end{itemize}

\subsection*{Grammar Rules and Actions}

The second part of a TP Yacc grammar contains the grammar rules for the
target language. Grammar rules have the format

\begin{quote}\begin{verbatim}
   name : symbol ... ;
\end{verbatim}\end{quote}

The left-hand side of a rule must be an identifier (which denotes a
nonterminal symbol). The right-hand side may be an arbitrary (possibly
empty) sequence of nonterminal and terminal symbols (including literals
enclosed in single quotes). The terminating semicolon may also be omitted.
Different rules for the same left-hand side symbols may be written using
the \verb"|" character to separate the different alternatives:

\begin{quote}\begin{verbatim}
   name : symbol ...
        | symbol ...
        ...
        ;
\end{verbatim}\end{quote}

For instance, to specify a simple grammar for arithmetic expressions, you
may write:

\begin{quote}\begin{verbatim}
%left '+' '-'
%left '*' '/'
%token NUM
%%
expr : expr '+' expr
     | expr '-' expr
     | expr '*' expr
     | expr '/' expr
     | '(' expr ')'
     | NUM
     ;
\end{verbatim}\end{quote}

(The \verb"%left" definitions at the beginning of the grammar are needed to
specify the precedence and associativity of the operator symbols. This will be
discussed in more detail in Section {\em Ambigious Grammars\/}.)

Grammar rules may contain actions -- Turbo Pascal statements enclosed in
\verb"{ }" -- to be executed as the corresponding rules are recognized.
Furthermore, rules may return values, and access values returned by other
rules. These ``semantic'' values are written as \verb"$$" (value of the
left-hand side nonterminal) and \verb"$i" (value of the $i$th right-hand
side symbol). They are kept on a special value stack which is maintained
automatically by the parser.

Values associated with terminal symbols must be set by the lexical analyzer
(more about this in Section {\em Lexical Analysis\/}). Actions of the form
\verb"$$ := $1" can frequently be omitted, since it is the default action
assumed by TP Yacc for any rule that does not have an explicit action.

By default, the semantic value type provided by Yacc is \verb"Integer". You
can also put a declaration like
\begin{quote}\begin{verbatim}
   %{
   type YYSType = Real;
   %}
\end{verbatim}\end{quote}
into the definitions section of your Yacc grammar to change the default value
type. However, if you have different value types, the preferred method is to
use type definitions as discussed in Section {\em Definitions\/}. When such
type definitions are given, TP Yacc handles all the necessary details of the
\verb"YYSType" definition and also provides a fair amount of type checking
which makes it easier to find type errors in the grammar.

For instance, we may declare the symbols \verb"NUM" and \verb"expr" in the
example above to be of type \verb"Real", and then use these values to
evaluate an expression as it is parsed.

\begin{quote}\begin{verbatim}
%left '+' '-'
%left '*' '/'
%token <Real> NUM
%type  <Real> expr
%%
expr : expr '+' expr   { $$ := $1+$3; }
     | expr '-' expr   { $$ := $1-$3; }
     | expr '*' expr   { $$ := $1*$3; }
     | expr '/' expr   { $$ := $1/$3; }
     | '(' expr ')'    { $$ := $2;    }
     | NUM
     ;
\end{verbatim}\end{quote}

(Note that we omitted the action of the last rule. The ``copy action''
\verb"$$ := $1" required by this rule is automatically added by TP Yacc.)

Actions may not only appear at the end, but also in the middle of a rule
which is useful to perform some processing before a rule is fully parsed.
Such actions inside a rule are treated as special nonterminals which are
associated with an empty right-hand side. Thus, a rule like
\begin{quote}\begin{verbatim}
   x : y { action; } z
\end{verbatim}\end{quote}
will be treated as:
\begin{quote}\begin{verbatim}
  x : y $act z
  $act : { action; }
\end{verbatim}\end{quote}

Actions inside a rule may also access values to the left of the action,
and may return values by assigning to the \verb"$$" value. The value returned
by such an action can then be accessed by other actions using the usual
\verb"$i" notation. E.g., we may write:
\begin{quote}\begin{verbatim}
   x : y { $$ := 2*$1; } z { $$ := $2+$3; }
\end{verbatim}\end{quote}
which has the effect of setting the value of \verb"x" to
\begin{quote}\begin{verbatim}
   2*(the value of y)+(the value of z).
\end{verbatim}\end{quote}

Sometimes it is desirable to access values in enclosing rules. This can be
done using the notation \verb"$i" with $i\leq 0$. \verb"$0" refers to the
first value ``to the left'' of the current rule, \verb"$-1" to the second,
and so on. Note that in this case the referenced value depends on the actual
contents of the parse stack, so you have to make sure that the requested
values are always where you expect them.

There are some situations in which TP Yacc cannot easily determine the
type of values (when a typed parser is used). This is true, in particular,
for values in enclosing rules and for the \verb"$$" value in an action inside
a rule. In such cases you may use a type cast to explicitly specify the type
of a value. The format for such type casts is \verb"$<name>$" (for left-hand
side values) and \verb"$<name>i" (for right-hand side values) where
\verb"name" is a type identifier (which must occur in a \verb"%token",
precedence or \verb"%type" definition).

\subsection*{Auxiliary Procedures}

The third section of a TP Yacc program is optional. If it is present, it
may contain any Turbo Pascal code (such as supporting routines or a main
program) which is tacked on to the end of the output file.

\subsection*{Lexical Analysis}

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

\begin{quote}\begin{verbatim}
   function yylex : Integer;
\end{verbatim}\end{quote}

The \verb"yylex" routine may either be prepared by hand, or by using the
lexical analyzer generator TP Lex (see Section {\em TP Lex\/}).

The lexical analyzer must be included in your main program behind the
parser subroutine (the \verb"yyparse" code template includes a forward
definition of the \verb"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
(\verb"$I").

The parser repeatedly calls the \verb"yylex" routine to tokenize the input
stream and obtain the individual lexical items in the input. For any
literal character, the \verb"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
\begin{quote}\begin{verbatim}
   %token NUM
\end{verbatim}\end{quote}
is the first definition in the Yacc grammar, then TP Yacc will create
a corresponding constant declaration
\begin{quote}\begin{verbatim}
   const NUM = 257;
\end{verbatim}\end{quote}
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 {\em Error Handling\/}). This definition may then be
used, e.g., in a corresponding TP Lex program as follows:
\begin{quote}\begin{verbatim}
   [0-9]+   return(NUM);
\end{verbatim}\end{quote}

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:
\begin{quote}\begin{verbatim}
   %token NUM 299
\end{verbatim}\end{quote}

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

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

\begin{quote}\begin{verbatim}
   [0-9]+   begin
              val(yytext, yylval, code);
              return(NUM);
            end;
\end{verbatim}\end{quote}

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

If a parser uses tokens of different types (via a \verb"%token <name>"
definition), then the \verb"yylval" variable will not be of type
\verb"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 \verb"yy"{\em name\/}
(where {\em name\/} stands for the corresponding type identifier).

E.g., if token \verb"NUM" is declared \verb"Real":
\begin{quote}\begin{verbatim}
   %token <Real> NUM
\end{verbatim}\end{quote}
then the value for token \verb"NUM" must be assigned to \verb"yylval.yyReal".

\subsection*{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:

\begin{quote}\begin{verbatim}
%token NUM
%left '+'
%left '*'
%%
expr : expr '+' expr
     | expr '*' expr
     | '(' expr ')'
     | NUM
     ;
\end{verbatim}\end{quote}

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

\begin{quote}\begin{verbatim}
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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕不卡的av| 精品少妇一区二区三区在线播放| 精品欧美一区二区在线观看| 亚洲精品v日韩精品| 国产精品99久久久| 91.com视频| 亚洲精选视频免费看| 精品一区二区影视| 欧美性色欧美a在线播放| 欧美国产在线观看| 蜜臀久久99精品久久久久宅男| 91麻豆自制传媒国产之光| 久久久久久久久久看片| 天堂久久一区二区三区| 欧日韩精品视频| 国产精品全国免费观看高清| 精品一区二区在线看| 欧美一区二区三区免费观看视频 | 色天使色偷偷av一区二区| 欧美精品一区二区久久婷婷| 五月天激情小说综合| 欧美在线观看视频一区二区| 国产精品不卡在线观看| 国产成人av电影免费在线观看| 日韩视频在线永久播放| 天天综合色天天综合色h| 色老汉一区二区三区| 国产精品久久久一本精品| 国产精品一区二区久久不卡| 欧美mv日韩mv国产| 麻豆精品视频在线观看免费 | 高清国产一区二区三区| 精品久久国产字幕高潮| 麻豆国产精品一区二区三区| 在线综合亚洲欧美在线视频| 日韩中文字幕不卡| 欧美日韩亚洲综合一区| 亚洲在线视频网站| 欧美亚洲动漫精品| 亚洲国产精品久久不卡毛片| 在线免费观看视频一区| 一区二区三区.www| 94-欧美-setu| 亚洲激情综合网| 欧美四级电影网| 天天射综合影视| 91麻豆精品久久久久蜜臀| 美女爽到高潮91| 日韩精品自拍偷拍| 经典三级视频一区| 欧美激情中文字幕一区二区| 成人丝袜18视频在线观看| 国产精品免费免费| 99国产精品国产精品久久| 亚洲黄色性网站| 欧美日韩你懂得| 免费成人在线观看| 久久综合av免费| 成人午夜视频在线观看| 日韩理论片网站| 欧美色精品在线视频| 天堂在线亚洲视频| 精品久久久久一区| 成人免费视频视频| 亚洲精品视频在线| 欧美日韩激情在线| 精品在线免费观看| 国产精品成人一区二区三区夜夜夜 | 1000精品久久久久久久久| 91农村精品一区二区在线| 亚洲一区在线看| 精品少妇一区二区三区在线播放 | 国产99久久精品| 自拍av一区二区三区| 欧美吞精做爰啪啪高潮| 久久国产精品色婷婷| 国产精品网曝门| 欧美在线免费观看视频| 久久草av在线| 国产精品久久久久久久裸模| 欧美日韩国产美女| 国产精品资源网| 亚洲午夜激情av| 精品99一区二区| 91首页免费视频| 日韩精品色哟哟| 国产精品久久久久久久久动漫| 欧美视频在线观看一区| 激情都市一区二区| 亚洲精选视频免费看| 精品国产伦一区二区三区观看体验| 不卡免费追剧大全电视剧网站| 亚洲一区二区视频| 国产三级欧美三级| 欧美性一级生活| 懂色av一区二区三区蜜臀| 一区二区免费看| 久久久精品免费网站| 欧美三级午夜理伦三级中视频| 国产在线国偷精品免费看| 亚洲精品v日韩精品| 久久久久久**毛片大全| 欧美色网站导航| 丁香天五香天堂综合| 日日夜夜免费精品视频| 国产精品成人网| 精品国产网站在线观看| 欧美在线观看视频一区二区三区| 国产精品一区二区在线观看不卡 | 国产一区二区电影| 亚洲成人一区在线| 中文字幕中文在线不卡住| 777xxx欧美| 色综合久久综合网欧美综合网| 国产一区二区免费在线| 亚洲成人动漫在线免费观看| 国产精品国产三级国产三级人妇| 欧美一区二区成人| 在线观看一区不卡| 成av人片一区二区| 国产一区二区三区香蕉| 日韩有码一区二区三区| 亚洲男同性恋视频| 中文字幕av免费专区久久| 欧美电视剧在线看免费| 欧美日韩高清一区二区不卡| 99久久99久久久精品齐齐| 国产美女娇喘av呻吟久久| 免费观看在线综合| 亚洲制服丝袜av| 亚洲乱码国产乱码精品精的特点| 国产日韩欧美一区二区三区综合| 日韩写真欧美这视频| 欧美日韩精品福利| 91福利视频久久久久| 99久久亚洲一区二区三区青草| 国产精品一二三四五| 韩国女主播一区| 美女视频免费一区| 免费不卡在线视频| 日韩av一级片| 午夜精品aaa| 亚洲妇熟xx妇色黄| 亚洲一区二区三区四区五区中文| 日韩一区在线免费观看| 日本一区二区三区免费乱视频| 久久久久久久电影| 久久免费偷拍视频| 国产亚洲制服色| 久久免费电影网| 久久久.com| 欧美激情一区不卡| 国产精品私人影院| 国产精品色在线| 国产精品亲子乱子伦xxxx裸| 欧美激情在线一区二区三区| 国产无人区一区二区三区| 国产亚洲制服色| 国产精品人妖ts系列视频| 国产精品久久久久影院老司| 中文字幕日韩一区二区| 综合色天天鬼久久鬼色| 亚洲色图另类专区| 一区二区三区小说| 亚洲国产精品欧美一二99 | 久久久久9999亚洲精品| 国产日韩欧美精品一区| 国产精品久久午夜| 亚洲三级电影网站| 亚洲精品国产精华液| 亚洲国产aⅴ天堂久久| 视频一区二区中文字幕| 秋霞午夜鲁丝一区二区老狼| 激情综合五月天| 高清成人免费视频| 91麻豆产精品久久久久久| 欧美性感一区二区三区| 91精品国产高清一区二区三区蜜臀| 日韩一区二区在线观看视频播放| 日韩精品一区在线| 国产日本亚洲高清| 亚洲人成网站在线| 午夜免费久久看| 久久成人av少妇免费| 粉嫩一区二区三区性色av| 一本色道久久综合亚洲aⅴ蜜桃 | 日韩视频免费直播| 久久亚洲综合色| 国产精品第13页| 亚洲大片在线观看| 国产一区亚洲一区| 99久久综合精品| 欧美日本一道本在线视频| 26uuu精品一区二区三区四区在线| 国产三级精品三级在线专区| 亚洲最新在线观看| 老司机免费视频一区二区| 成人午夜激情影院| 欧美三区在线视频| 久久久久久9999|