flex/bison vs switch
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > flex/bison vs switch




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    flex/bison vs switch  
Billy N. Patton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-04 12:48 PM

I have an old flex/bison version of a parser and I have a version where
i read c char at a time and enter a LARGE switch (in c) that has nested
switch statements.

I wrote the bison several years ago and don't remember why I quit using it.

Your opinion of pro's and cons for flex/bison would be appreciated.

I know the switch I can step into 2 years from now and understand.
The flex/bison is like learning to speak a new language each time.

What are the benefits of lex/yacc?

--
___  _ ____       ___       __  __
/ _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
/ _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com





[ Post a follow-up to this message ]



    Re: flex/bison vs switch  
Jens.Toerring@physik.fu-berlin.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-19-04 10:58 PM

Billy N. Patton <b-patton@ti.com> wrote:
> I have an old flex/bison version of a parser and I have a version where
> i read c char at a time and enter a LARGE switch (in c) that has nested
> switch statements.

> I wrote the bison several years ago and don't remember why I quit using it.[/vbcol
]
[vbcol=seagreen]
> Your opinion of pro's and cons for flex/bison would be appreciated.

> I know the switch I can step into 2 years from now and understand.
> The flex/bison is like learning to speak a new language each time.

> What are the benefits of lex/yacc?

Because, at least in complex situations, it's a lot easier to write.
When you just have e.g. single chars where each triggers a different
action it's probably easier to use just a switch or something else,
but of you tokenize and parse something more complex like a language
then lex/yacc are probably going to save you a lot of time and
headache. If you have e.g. a syntax were after TOKEN_A either
TOKEN_B, TOKEN_C or TOKEN_D, followed by a comma and then TOKEN_E
is allowed and in each case you would have different actions to
execute, keeping that straight (especially if the requirements
change) with lots and lots of state variables would probably
become a nightmare to maintain in a rather short time when you
try to write that in C only. yacc/bison will do all the work for
you of remembering previously read tokens (and the associated
values), which state you're currently in etc. while you just have
to specify the syntax and the associated actions. And I would guess
that it's also a lot easier to write (and understand later) when
you have e.g.

INT         [0-9]+
EXPO        [Ee][+-]?{INT}
FLOAT       ((({INT}"."[0-9]*)|([0-9]*"."{INT})){EXPO
}?)|({INT}{EXPO})

{INT}       do_something_with_an_int( yytext );
{FLOAT}     do_something_with_a_float( yytext );

than having to determine if something is really an number and if
it's a float, where it ends etc. manually with some C functions
(ok, in that case you could use strtod() and strtol(), but you
still would have to distinguish between an int and a float).

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.toerring.de





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:34 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register