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
Returns - Inline::C configuration validation code
See Inline
build($self)
Generate the lexer and calls Inline::C to compile it.
Arguments
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
$self - the Inline object
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:
AnnoCPAN: Annotated CPAN documentation
RT: CPAN's request tracker
Please report any bugs or feature requests to L <bug-inline-flex@rt.cpan.org>.
We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
Search CPAN
SEE ALSO
flex (1).
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 112:
'=item' outside of any '=over'
- Around line 133:
You forgot a '=back' before '=head1'