Resources for Flex and Yacc

Only available on StudyMode
  • Download(s) : 68
  • Published : April 29, 2013
Open Document
Text Preview
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"

"market" printf("school");
int main(int argc,char *argv[])
yyin = fopen(argv[1],"r");
return 0;
tracking img