Escolar Documentos
Profissional Documentos
Cultura Documentos
Garima kansal
CSE VII A
ROLL NO. 1506810111
→ Summer Training at CDAC, Noida from 11 June , 2018 to
12 July, 2018.
→ An amazing experience as I got to see , how makes the
compiler and working of flex and bison.
→Main objective was to learn how the compiler is build using
flex and bison software.
1. Introduction
2. Bison and how its working
3. Structure of bison
4. Process of complete compilation using flex and bison
5. Examples
Flex and Bison are tools for building programs that handle
Structured input. They were original tools for building compiler
One of the key insights was to break the job into two parts:
1. lexical analysis (also called lexing or scanning)
2. syntax analysis (or parsing).
For example, consider this snippet of C code:
alpha = beta + gamma ;
A scanner divides this into the tokens alpha, equal sign, beta, plus
sign, gamma, and semicolon. Then the parser determines that beta
+ gamma is an expression, and that the expression is assigned to
alpha.
Bison is an upgraded version of the older tool yacc, "yet another
compiler compiler" and it is probably the most common of the
LALR tools out there. Our programming projects are configured
to use the updated version bison, a close relative of the yak, but all
of the features we use are present in the original tool, so this serves
as a brief overview of both.
Bison is designed for use with C code and generates parser written
in C.The parser is configured for use in conjunction with a flex
generated scanner and relies on standard shared features (token
types, yylval) and calls the function yylex as a scanner coroutine.
%
{
C declarations
%}
Bison declarations
%%
Grammar rules
%%
Additional C code
Download latest version of flex and Bison..
1.flex-2.5.4a-1.exe
2.bison-2.4.1-setup.exe
3.download Dev-Cpp or CodeBlocks
* Dev-Cpp
* CodeBlocks
;C:\Program Files\CodeBlocks\MinGW\bin;
void main()
{
char ch;
FILE *fp; int i;
fp=fopen("sample.txt","r");
yyin=fp;
for(i=0;i<4;i++)
yyparse();
if(flag==0)
printf("\nEntered arithmetic expression
is Valid\n\n");
getch();
}
int yyerror(char *s)
{
printf("\nEntered arithmetic
expression is Invalid\n\n");
flag=1;
}
OUTPUT:
Flex and Bison are a powerful combination for parsing grammars. By using
the tips and tricks I made .y file of Bison which can parse student details for
Attendance , Authentication and record maintenance of Employees ,
Students of any organization.