命令行大全

yacc

喵喵 发表于 2020-07-02 18:22浏览次数:

在类似Unix的操作系统上,yacc命令是一个编译器,它生成一个前瞻性、从左到右、最右边的派生(LALR)解析器。它是一个编译器-编译器:一个编译器,它创建一个编译器。Yacc以一种编程语言的形式描述作为输入,它的输出是一个解析器,在编译用该语言编写的程序时,它执行特定于目标体系结构的某些操作。

查看英文版

目录:

1 yacc 运行系统环境

2 yacc 描述

3 yacc 语法

yacc 运行系统环境

Unix&Linux

yacc 描述

“yacc”是“Yet Another Compiler-Compiler”的缩写。它非常流行,曾经是所有Unix系统的标准。自那以后,它就被最近的编译器所取代,后者大多与yacc向后兼容。

The name "yacc" is an acronym for "Yet Another Compiler-Compiler." It was extremely popular and was once standard on all Unix systems. It has since been supplanted by more recent compiler-compilers, which are mostly backward compatible with yacc.

查看英文版

查看中文版

yacc 语法

yacc [-d] [-l] [-t] [-V] [-v] [ -b file_prefix ] [ -Q [y | n ] ] 
     [ -P parser ] [ -p sym_prefix ] file
-d 生成文件y.tab.h和#Defined语句,这些语句将yacc用户分配的“令牌代码”与用户声明的“令牌名称”关联起来。此关联允许y.tab.c以外的源文件访问令牌代码。
-l 指定在y.tab.c中生成的代码不包含任何#行结构。此选项只应在语法和相关操作完全调试之后使用。
-t 默认情况下编译运行时调试代码。运行时调试代码总是在条件编译控件下在y.tab.c中生成。默认情况下,编译y.tab.c时不包含此代码。无论是否使用-t选项,运行时调试代码都由预处理符号YYDEBUG控制。如果YYDEBUG有一个非零值,则包括调试代码.如果其值为0,则不包括代码。在没有运行时调试代码的情况下,生成的程序的大小和执行时间将更小,速度也更快。
-v 准备文件y.Output,其中包含解析表的描述和语法中的歧义所产生的冲突的报告。
-V 在标准错误上打印Yacc的版本信息。
-b file_prefix 使用file_前缀而不是y作为所有输出文件的前缀。代码文件y.tab.c、头文件y.tab.h(指定了-d时创建)和描述文件y.Output(指定了-v时创建)将分别更改为file_prefix.tab.c、file_prefix.tab.h和file_prefix.输出。
-Q [y|n] -qy选项将版本冲压信息放在y.tab.c中。这使您能够知道yacc的哪个版本构建了该文件。qn选项(默认)不写入版本信息。
-P parser 允许您指定自己选择的解析器,而不是/usr/ccs/bin/yaccPAR。例如,可以指定:
yacc -P ~/myparser parser.y
-b file_prefix 使用sym_前缀而不是yy作为yacc生成的所有外部名称的前缀。受影响的名称包括函数yyparse()、yylex()和yyError(),以及变量yylval、ychar和yy调试。(在本节的其余部分中,引用的六个符号使用其默认名称只是为了便于使用。)本地名称也可能受到-p选项的影响;但是-p选项不影响yacc生成的#Definition符号。
file 包含要为其创建解析器的指令的文件的路径名。


yacc [-d] [-l] [-t] [-V] [-v] [ -b file_prefix ] [ -Q [y | n ] ] 
     [ -P parser ] [ -p sym_prefix ] file
-d Generates the file y.tab.h with the #define statements that associate the yaccuser-assigned "token codes" with the user-declared "token names." This association allows source files other than y.tab.c to access the token codes.
-l Specifies that the code produced in y.tab.c will not contain any #line constructs. This option should only be used after the grammar and the associated actions are fully debugged.
-t Compiles runtime debugging code by default. Runtime debugging code is always generated in y.tab.c under conditional compilation control. By default, this code is not included when y.tab.c is compiled. Whether or not the -t option is used, the runtime debugging code is under the control of YYDEBUG, a preprocessor symbol. If YYDEBUG has a non-zero value, then the debugging code is included. If its value is 0, then the code will not be included. The size and execution time of a program produced without the runtime debugging code will be smaller and slightly faster.
-v Prepares the file y.output, which contains a description of the parsing tables and a report on conflicts generated by ambiguities in the grammar.
-V Prints on the standard error output the version information for yacc.
-b file_prefix Use file_prefix instead of y as the prefix for all output files. The code file y.tab.c, the header file y.tab.h (created when -d is specified), and the description file y.output (created when -v is specified), will be changed to file_prefix.tab.cfile_prefix.tab.h, and file_prefix.output, respectively.
-Q [y|n] The -Qy option puts the version stamping information in y.tab.c. This allows you to know what version of yacc built the file. The -Qn option (the default) writes no version information.
-P parser Allows you to specify the parser of your choice instead of /usr/ccs/bin/yaccpar. For example, you can specify:
yacc -P ~/myparser parser.y
-b file_prefix Use sym_prefix instead of yy as the prefix for all external names produced by yacc. The names affected include the functions yyparse(), yylex() and yyerror(), and the variables yylval, yychar and yydebug. (In the remainder of this section, the six symbols cited are referenced using their default names only as a notational convenience.) Local names may also be affected by the -p option; however, the -p option does not affect #define symbols generated by yacc.
file A path name of a file containing instructions for which a parser is to be created.


查看英文版

查看中文版