LINUX CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>

7-DAY TOP DOWNLOAD

#
Program
Tibia 8.22
2,360
BackTrack 3.0
2,245
Yahoo Messenger
1.0.4

1,947
Wine 1.1.6
1,911
VLC 0.9.4
1,887
Mandriva Linux 2009
1,853
Enter 0.0.9
1,759
Thunderbird PST
Import plugin 1.2

1,290
Beryl 0.2.1
1,279
Linpus Linux 9.4
1,251

WEEK'S BEST

  • Softpedia Linux RS...
  • Ubuntu 8.04.1
  • Pidgin 2.5.1
  • Adobe Flash Player...
  • The Gimp 2.6.1
  • openSUSE Linux 11....
  • Linux Kernel 2.6.27
  • Super Grub Disk 0....
  • Skype 2.0.068
  • OpenOffice.org 3.0.0
  • Mozilla Firefox 3....
  • Transmission 1.34
  • DeVeDe 3.11b
  • Wine 1.1.6
  • wine-doors 0.1.2
  • Shoreline Firewall...
  • Linux Mint 5.0
  • Google Gadgets 0.1...
  • Fedora 9 / 10 Beta
  • Opera 9.60
  • Home / Linux / Programming / Interpreters

    Flex 2.5.35



    No screenshots available
    Downloads: 4,134  Add to download basket  Tell us about an update
    User Rating:
    Rated by:
    Good (3.1/5)
    20 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Vern Paxson | More programs
    GPL / FREE
    February 27th, 2008, 10:33 GMT
    ROOT / Programming / Interpreters

     Read user reviews (0)  Add a review  Refer to a friend  Subscribe

     

    Flex description

     

    Flex is a Fast Lexical Analyzer.

    Flex is a Fast Lexical Analyzer.

    Flex is a fast lexical analyzer generator. It is a tool for generating programs that perform pattern-matching on text. Flex is a non-GNU free implementation of the well known Lex program.

    Flex is a tool for generating scanners: programs which recognized lexical patterns in text. flex reads the given 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 as output a C source file, `lex.yy.c', which defines a routine `yylex()'. This file is compiled and linked with the `-lfl' library to produce an executable. When the executable is run, it analyzes its input for occurrences of the regular expressions. Whenever it finds one, it executes the corresponding C code.

    Some simple examples

    First some simple examples to get the flavor of how one uses flex. The following flex input specifies a scanner which whenever it encounters the string "username" will replace it with the user's login name:

    %%
    username printf( "%s", getlogin() );

    By default, any text not matched by a flex scanner is copied to the output, so the net effect of this scanner is to copy its input file to its output with each occurrence of "username" expanded. In this input, there is just one rule. "username" is the pattern and the "printf" is the action. The "%%" marks the beginning of the rules.

    Here's another simple example:

    int num_lines = 0, num_chars = 0;

    %%
    n ++num_lines; ++num_chars;
    . ++num_chars;

    %%
    main()
    {
    yylex();
    printf( "# of lines = %d, # of chars = %dn",
    num_lines, num_chars );
    }

    This scanner counts the number of characters and the number of lines in its input (it produces no output other than the final report on the counts). The first line declares two globals, "num_lines" and "num_chars", which are accessible both inside `yylex()' and in the `main()' routine declared after the second "%%". There are two rules, one which matches a newline ("n") and increments both the line count and the character count, and one which matches any character other than a newline (indicated by the "." regular expression).

    A somewhat more complicated example:

    /* scanner for a toy Pascal-like language */

    %{
    /* need this for the call to atof() below */
    #include < math.h >
    %}

    DIGIT [0-9]
    ID [a-z][a-z0-9]*

    %%

    {DIGIT}+ {
    printf( "An integer: %s (%d)n", yytext,
    atoi( yytext ) );
    }

    {DIGIT}+"."{DIGIT}* {
    printf( "A float: %s (%g)n", yytext,
    atof( yytext ) );
    }

    if|then|begin|end|procedure|function {
    printf( "A keyword: %sn", yytext );
    }

    {ID} printf( "An identifier: %sn", yytext );

    "+"|"-"|"*"|"/" printf( "An operator: %sn", yytext );

    "{"[^}n]*"}" /* eat up one-line comments */

    [ tn]+ /* eat up whitespace */

    . printf( "Unrecognized character: %sn", yytext );

    %%

    main( argc, argv )
    int argc;
    char **argv;
    {
    ++argv, --argc; /* skip over program name */
    if ( argc > 0 )
    yyin = fopen( argv[0], "r" );
    else
    yyin = stdin;

    yylex();
    }

    This is the beginnings of a simple scanner for a language like Pascal. It identifies different types of tokens and reports on what it has seen.

    The details of this example will be explained in the following sections.

      


    TAGS:

    Lexical Analyzer | analyzer generator | generating programs | Flex | Lexical | Analyzer

    Related downloads IT News Popular downloads New additions   Latest reviews  
    Quex 0.31.5
    Quex is a Mode Oriented Directly Coded Lexical Analyser Generator.
    Flex 2.5.35
    Flex is a Fast Lexical Analyzer.
    JetPAG 0.6.1
    JetPAG is a powerful recursive-descent parser and lexical analyzer optimizing generator.
    Fast Lexical Analyzer Generator 2.5.33
    Flex is a tool for generating scanners.


    HTML code for linking to this page:


    Go to top



    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   ENTER NEWS SITE   |   ENGLISH BOARD   |   ROMANIAN FORUM