نديم ابن ﺤﻣﻮﺪﺓ الخمير - Nadim Khemir > Inline-Flex > Inline::Flex

Download:
Inline-Flex-0.01_01.2.tar.gz

Dependencies

Annotate this POD

Module Version: 0.01_01   Source  

NAME ^

Inline::Flex - Inline module to use flex generated lexers

SYNOPSIS ^

  use Inline Flex =><<'END_FLEX' ;
  %option noyywrap
  %option prefix="Default"
  
  %{
  #undef YY_MAIN
  #define INTEGER 1
  #define IDENTIFIER 2
  #define UNEXPECTED 3
  %}
  
  %{
  // replacement macros
  %}
  exp           (([eE][0-9]+)?)
  fltsuf   (([lL]|[fF])?)
  intsuf   (([lL]?[uU]?)|([uU]?[lL]?))
  
  %%
  
  %{
  // regexes and action code
  %}
  [1-9][0-9]*{intsuf} { return(INTEGER) ; }
  
  [a-z_A-Z][a-z_A-Z0-9]+ { return(IDENTIFIER) ; } 
  
  \ + // ignore
  [\n\t ]+ ; // ignore
  
  [^a-z_A-Z0-9 ]+ { return(UNEXPECTED) ; } 
  
  %{
  // comment section
  %}
  
  %%
  END_FLEX
  
  print <<'EOT' ;
  Type an integer or an identfier and end your input with a '\n'.
  End the program with ctl+c
  
  EOT
  
  my %type = ( 1 => 'INTEGER',  2 => 'IDENTIFIER', 3 => 'UNEXPECTED') ;
  
  while(0 != (my $lexem = yylex()))
        {
        if(exists $type{$lexem})
                {
                print  "$type{$lexem} [$lexem] .\n" ;
                }
        else
                {
                print "Can't find type [$lexem] !\n" ;
                }
        }

DESCRIPTION ^

Inline::Flex Allows you to define a lexer with the help of flex and to use it in perl. Inline::Flex inherits from Inline::C. All the option available in Inline::C are also available in Inline::Flex.

As of version 0.02 all C functions declared in the lexer are made available to perl.

A 'yylex' sub is exported to perl space by this module.

Limitation

You can't write your lexer after the __END__ tag. You must write it inline where you declare your Inline::Flex section. If your lexer is so big that you need to separate it from the rest of your code, considermoving it to another package.

Inline::Flex aliases:

Inline::FLEX

Inline::flex

Options

Inline::Flex supports the following options:

FLEX_COMMAND_LINE:

This is the command line used to generate the lexer. It defaults to 'flex -f -8 -oOUTPUT_FILE INPUT_FILE' where OUTPUT_FILE and INPUT_FILE are automatically replaced by Inline::Flex. This option allows to tweak the generated lexers. Look at the flex man page for more information.

SUBROUTINES/METHODS ^

register()

Register this module as an Inline language support module . This is called by Inline.

Arguments - None

Returns - See Inline::C

Exceptions - None

validate($self, %configuration)

Sets default command line or uses user defined command line.

Arguments

$self - inline object.
%configuration - options

Returns - Inline::C configuration validation code

See Inline

build($self)

Generate the lexer and calls Inline::C to compile it.

Arguments

$self - Inline object

Returns - Inline::C build result

Exceptions - None

GenerateLexer($self)

Creates the C code Inline::C will compile by preprocessing the Inline::Flex input code with flex.

Arguments

Returns - Nothing

Exceptions - flex command failures

BUGS AND LIMITATIONS ^

None so far.

AUTHOR ^

        Nadim ibn hamouda el Khemir
        CPAN ID: NH
        mailto: nadim@cpan.org

LICENSE AND COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Inline::Flex

You can also look for information at:

SEE ALSO ^

flex (1).

syntax highlighting: