Techs Worldwide has moved to a new location with a new name and more advanced features. Click here to visit Geeks Worldwide for technology news, tutorials, videos, tools, and discussions.
Today: 02/04/2012
 

Installing Flex (The fast lexical analyzer) on Ubuntu Linux

NOTE: You have to install m4 (general purpose macro processor) before installing Flex. Click here.

This short tutorial shows you how to install Flex (The fast lexical analyzer) on Ubuntu Linux Server. The process is very simple. For this tutorial, I'll be installing flex version 2.5.33. Linux kernel is 2.6.15-26-powerpc. I have used a Mac Mini (powerpc/ppc architecture). GCC version number is 4.0.3. Your configuration may be different from mine but the installation steps below should work fine for most configurations with little or no change at all (including other Linux distributions and even unixes e.g. MacOS X).

Flex (The fast lexical analyzer):

According to flex.sourceforge.net,

"Flex 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."

Before starting, please check to see if there is a latest version available to download. Visit http://flex.sourceforge.net/ to find out about the available versions. IMPORTANT: See "Configuring Ubuntu Linux After Installation" to install the development tools required to compile and install flex from source code.

Steps to download, compile, and install are as follows. Note: Replace 2.5.33 with your version number:

  • Downloading Flex (The fast lexical analyzer):

    Run the command below,
    wget http://prdownloads.sourceforge.net/flex/flex-2.5.33.tar.gz?download
  • Extracting files from the downloaded package:

    tar -xvzf flex-2.5.33.tar.gz
    Now, enter the directory where the package is extracted.
    cd flex-2.5.33
  • Configuring flex before installation:

    If you haven't installed m4 yet then please do so. Click here to read about the installation instructions for m4. Run the commands below to include m4 in your PATH variable.

    PATH=$PATH:/usr/local/m4/bin/

    NOTE: Replace '/usr/local/m4/bin' with the location of m4 binary. Now, configure the source code before installation.

    ./configure --prefix=/usr/local/flex

    Replace "/usr/local/flex" above with the directory path where you want to copy the files and folders. Note: check for any error message.

  • Compiling flex:

    make

    Note: check for any error message.

  • Installing flex:

    As root (for privileges on destination directory), run the following.

    With sudo,
    sudo make install
    Without sudo,
    make install

    Note: check for any error messages.

That’s it. Flex has been successfully installed.

=======================================================================================

Support Geeks Worldwide:

Link to us:

You can support us by putting a link to our website on your blog or website (code is below).

<a href="http://www.techsww.com/">
Geeks Worldwide - Tutorials about Software Installation,
Configuration, Administration, Monitoring, Tools, Tips &
Tricks
</a>

OR a simple one.

<a href="http://www.techsww.com/">
Geeks Worldwide - IT related Tutorials
</a>

Feedbacks:

We appreciate feedbacks and suggestions about our tutorials and Geeks Worldwide from readers. Please contact us using the form here and let us know what you think about the tutorial and the website in general.

Bookmark Us:

We are working on new features for the website, please keep visiting or bookmark us using your favourite bookmarking service.

Subscribe to RSS:

You can subscribe to our RSS feed here.



 
Creative Commons License   Valid XHTML 1.0 Transitional Valid CSS