← 返回命令列表

Linux command

yacc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate a parser

yacc [grammar.y]

Generate parser with header file

yacc -d [grammar.y]

Use a custom file prefix

yacc -b [prefix] [grammar.y]

Use a custom symbol prefix

yacc -p [prefix] [grammar.y]

Generate verbose output

yacc -v [grammar.y]

Enable debugging

yacc -t [grammar.y]

Generate separate files

yacc -r [grammar.y]

说明

yacc (Yet Another Compiler Compiler) is an LALR(1) parser generator that reads grammar specifications and generates C code for a parser. The grammar file defines tokens, syntax rules, and semantic actions. yacc produces y.tab.c containing parsing tables and a driver routine. When used with -d, it also generates y.tab.h with token definitions for use with lex/flex lexers. On most Linux systems, yacc is actually bison (GNU parser generator) or byacc (Berkeley Yacc), both compatible with traditional AT&T yacc.

参数

-b _prefix_
Use prefix for output filenames instead of y.
-d
Generate header file y.tab.h with token definitions.
-g
Generate graphviz format file y.dot for visualization.
-i
Generate supplementary header file y.tab.i.
-l
Do not insert #line directives in generated code.
-p _prefix_
Use prefix for yacc-generated symbols instead of yy.
-P
Create a reentrant (pure) parser.
-r
Generate separate files for code (y.code.c) and tables (y.tab.c).
-t
Enable debugging statements in compiled code.
-v
Generate verbose description file y.output.
-V
Print version information.

FAQ

What is the yacc command used for?

yacc (Yet Another Compiler Compiler) is an LALR(1) parser generator that reads grammar specifications and generates C code for a parser. The grammar file defines tokens, syntax rules, and semantic actions. yacc produces y.tab.c containing parsing tables and a driver routine. When used with -d, it also generates y.tab.h with token definitions for use with lex/flex lexers. On most Linux systems, yacc is actually bison (GNU parser generator) or byacc (Berkeley Yacc), both compatible with traditional AT&T yacc.

How do I run a basic yacc example?

Run `yacc [grammar.y]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -b _prefix_ do in yacc?

Use prefix for output filenames instead of y.