[COLUG] Lets talk about FLEX

Rob Funk rfunk at funknet.net
Wed Apr 18 17:29:19 EDT 2007


Tom Hanlon wrote:
> I know I can look this up but I figured some pithy insight from the
> group might be useful.
>
> What is flex, what is lex ?

Flex is the GNU version of lex, which is the classic Unix tool for 
generating "lexers", which do lexicographic analysis to split text into 
tokens.

> Also it seems that when i need Lex, I use FLEX  and also sometimes,
> YACC or BISON end up in the mix.

Bison is the GNU version of yacc, which is the classic Unix tool for 
getting meaning out of tokens.  Yacc stands for "yet another 
compiler-compiler".

On a GNU system, flex is used with bison.  On a classic Unix system, lex 
is used with yacc.

> Are these all code generators of some sort ?

Yes.

> I also recall though my memory may be faulty that sometimes FLEX or
> BISON are required to deliver error output from soome programs.

Not really.

> Meaning I *think* that i have sometimes seen a failing program make a
> call to one of them and then the error becomes the lack of flex ?

That's probably just in the configuration stage, pre-compilation.

> I just needed Lex for my config of a source PHP install. And then i
> got to thinking.

The classic book on the subject:
  http://www.oreilly.com/catalog/lex/

A website on the subject:
  http://dinosaur.compilertools.net/

| A compiler or interptreter for a programming language is often
| decomposed into two parts:
| 1. Read the source program and discover its structure.
| 2. Process this structure, e.g. to generate the target program.
|
| Lex and Yacc can generate program fragments that solve the first task.
|
| The task of discovering the source structure again is decomposed into
| subtasks:  
| 1. Split the source file into tokens (Lex).
| 2. Find the hierarchical structure of the program (Yacc).

-- 
==============================|   "A microscope locked in on one point
 Rob Funk <rfunk at funknet.net> |Never sees what kind of room that it's in"
 http://www.funknet.net/rfunk |    -- Chris Mars, "Stuck in Rewind"


More information about the colug432 mailing list