Bison and Yacc are the the compiler programming language that help to parse the source code.  Bison and Yacc use the bottom-up parsing algorithm.  For more detail about the algorithm/concept of Bison/Yacc, please refer to the Tutorial 5.

     The structures of Bison/Yacc are as following:

%{
   C declarations
   Include all the required header file
%}
 
Yacc/Bison declarations
    - similar to Flex, defined all the rules
 
%%
 
Grammar rules
     - similar to Flex, write out all the grammar follow by the
       C code.  (Action commnd)

 

%%
 
Additional C code / main

         For more information, please type -man bison or go to the link provide on left hand side.
 

Bison/Yacc

Objective:
Sample Code:
Compile Instruction:
bash$ flex calc.l  

 


bash$
bison -d calc.y
   


bash$
gcc –o calc *.c –ll –lm

 


bash$ calc

 
 
ç compile flex
- use "flex" instead of "lex" will fix   yylex( ) so that it has no type problems
generate the lex.yy.c file.


ç generate calc.tab.h and calc.tab.c files.
    without -d, then only calc.tab.c file will
    be generated.

ç create "calc" object, which will be the
    executable for the calculator.  Note that
    the -ll and -lm sometimes -ld are just
    some of the linking commnad.

ç run the calculator