Resources for Flex and Yacc

Topics: Compiler, Source code, Programming language Pages: 2 (259 words) Published: April 29, 2013
Flex (Fast Lexical Analyser) is a tool for generating scanners. A scanner, sometimes called a tokenizer, is a program which recognizes lexical patterns in text. The flex program reads user-specified input files, or its standard input if no file names are given, for a description of a scanner to generate. The description is in the form of pairs of regular expressions and C code, called rules. Flex generates a C source file named, "lex.yy.c", which defines the function yylex(). The file "lex.yy.c" can be compiled and linked to produce an executable. When the executable is run, it analyzes its input for occurrences of text matching the regular expressions for each rule. Whenever it finds a match, it executes the corresponding C code.

The computer program Yacc is a parser generator which was developed by Stephen C. Johnson at AT&T Corporation for the Unix operating system in 1970. The name is an acronym for "Yet Another Compiler Compiler". It generates a parser (the part of a compiler that tries to make syntactic sense of the source code) based on an analytic grammar written in a notation similar to BNF. Yacc used to be available as the default parser generator on most Unix systems. It has since been supplanted as the default by more recent, largely compatible, programs.

Program presented in seminar :

// Program to replace every occurance of "market" in input file by "school"

%{
#include
%}
%%
"market" printf("school");
%%
int main(int argc,char *argv[])
{
yyin = fopen(argv[1],"r");
yylex();
fclose(yyin);
return 0;
}
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Lex and Yacc Essay
  • Lex and Yacc Essay
  • Human Resources Essay
  • RESOURCES Essay
  • Human Resources Essay
  • Human Resource Essay
  • Essay about human resources
  • resources Essay

Become a StudyMode Member

Sign Up - It's Free