Flex & Bison

Discuss the future of Warzone 2100 with us.
Post Reply
UrbanVoyeur
Trained
Trained
Posts: 50
Joined: 10 Mar 2007, 05:03
Location: NYC

Flex & Bison

Post by UrbanVoyeur »

Please excuse my ignorance (I'm new to C)

Is this correct:
The purpose of Flex & Bison libraries is to provide a run-time translator and compiler for the pseudo code in the data/scripts directory???

Bison generates the parser (as Regular Expressions) from a set of rules  in the format of a formal grammatical representation of the pseudo code. Flex takes this parser information and builds the translation and calling classes/functions which parse the pseudo code and make calls to the appropriate functions/methods/classes in the compiled code. Both Bison.exe and Flex.exe are run before the main compilation so their libraries are included in the build???

Is this close or a confused mess?

Ed Note: See below for Correct explanation!
Last edited by UrbanVoyeur on 06 May 2007, 03:32, edited 1 time in total.
User avatar
DevUrandom
Regular
Regular
Posts: 1690
Joined: 31 Jul 2006, 23:14

Re: Flex & Bison

Post by DevUrandom »

Seems roughly correct, even though you mixed up the roles of flex and bison.

I am not the expert in this matter, but I think it works as follows:
- Lex generates a lexical analyser (also called lexer) which analyses data (eg. a script file) and recognizes the meaning of specific tokens (eg. numbers, variablenames, keywords, ...)
- The parse, which is generated by Yacc, then turns that information into a meaning (eg. assignments, function calls, ...)
- Which the program then can react upon (eg. call a function)

For Warzone, we use the Flex implementation of Lex and let it generate C code in files with the extension .lex.c and use the Bison implementation of Yacc, which generates .tab.c files for us. The filename extensions for the generated code are not enforced by the tools and may differ between the projects which use them. The usual extension for Lex lexers is usually .l (small L) and .y for Yacc parsers.

You might want to read the wikipedia articles in your language on that matter. Interesting keywords are:
Lex, Yacc, Lexer, Parser, Parsergenerator (aka compiler-compiler), Compiler

For our german folks the sites are:
Lex, Yacc, Lexer, Parser, Parsergenerator, Compiler

Edit: Giel: add links for English wiki articles
Last edited by Giel on 06 May 2007, 22:49, edited 1 time in total.
UrbanVoyeur
Trained
Trained
Posts: 50
Joined: 10 Mar 2007, 05:03
Location: NYC

Re: Flex & Bison

Post by UrbanVoyeur »

Thanks
Post Reply