delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/08/19:25:40

Date: Tue, 8 Jun 1999 19:25:20 -0400
Message-Id: <199906082325.TAA25150@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp AT delorie DOT com
In-reply-to: <375DB01B.839CC62A@hotmail.com> (message from Denis Lamarche on
Tue, 08 Jun 1999 21:11:49 GMT)
Subject: Re: Bison Vs. Flex?
References: <375DB01B DOT 839CC62A AT hotmail DOT com>
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> What is the difference between Bison And Flex?

A flex-built parser is a lexical analyzer.  Basically, it reads a text
file and converts it to "tokens" or words.  It sends those tokens to
the bison-built parser, which recognizes the syntax of those tokens
and takes actions based on them.

For example, a flex-built parser would see "if (x) exit" and convert
it into the following token stream:

	T_IF
	'('
	T_IDENTIFIER (name="x")
	')'
	T_IDENTIFIER (name="exit")

The bison-generated portion, for example, would match it against a
pattern like this (real parsers can be *very* complicated):

statements : IF '(' expression ')' statement { foo($3, $5); }
           | WHILE '(' expression ')' statement { bar($3, $5); }
           | statement
           ;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019