- user-setup command
Use the user-setup command to select misc/gnu/1.0 .
- Making a directory named ``tmp'' under your root.
- Bison input file: Create a Bison input file, e.g.,
grammar.y, which consists of three parts: definitions, rules, and auxiliary routines.
- A parser creation: Call the Bison with the following syntax:
>bison [ -b file-prefix ] [ --file-prefix=file-prefix ] [ -d
] [ --defines ] [ -k ] [ --token-table ] [ -l ] [ --no-lines
] [ -n ] [ --no-parser ] [ -o outfile ] [ --output-
file=outfile ] [ -p prefix ] [ --name-prefix=prefix ] [ -r ]
[ --raw ] [ -t ] [ --debug ] [ -v ] [ --verbose ] [ -V ] [
--version ] [ -y ] [ --yacc ] [ -h ] [ --help ] [ --fixed-
output-files ] file
For example, the input file name is grammar.y:
>bison grammar.y
Some useful Bison command-line options are
-d: Write an extra output file containing macro definitions for the token type names defined in the grammar. The header file is named filename.tab.h. This output file is essential if you wish to put the definition of yylex in a separate source file, because yylex needs to be able to refer to token type codes and the variable yylval.
-v: Produces yet another file, with the name filename.output. The file contains a textual description of the LALR(1) parsing table.
- An executable creation: The Bison generates as output a C source file,
filename.tab.c, which is used to produce an executable by gcc, a GNU project C compiler:
>gcc [ option | filename ] ...
For example, the input file name is grammar.y and the executable name is parser:
>gcc -o parser grammar.tab.c
- Interaction with Flex: In the definitions section of Flex input file, include the header file
filename.tab.h. For example, the Flex input file name is rule.l, the Bison input file name is grammar.y and the executable name is parser:
>bison -d -v grammar.y
/* including grammar.tab.h into the definition part of rule.l */
>flex rule.l
>gcc -o parser grammar.tab.c lex.yy.c
- The parer application: Apply the executable parser to a file, e.g.,
test, and send the results to a file, e.g., result:
>parser < test > result