Inline::Flex - Inline module to use flex generated lexers
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" ; } }
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.
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
Inline::flex
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.
Register this module as an Inline language support module . This is called by Inline.
Arguments - None
Returns - See Inline::C
Exceptions - None
Sets default command line or uses user defined command line.
Arguments
Returns - Inline::C configuration validation code
See Inline
Generate the lexer and calls Inline::C to compile it.
Returns - Inline::C build result
Creates the C code Inline::C will compile by preprocessing the Inline::Flex input code with flex.
$self - the Inline object
Returns - Nothing
Exceptions - flex command failures
None so far.
Nadim ibn hamouda el Khemir CPAN ID: NH mailto: nadim@cpan.org
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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
http://annocpan.org/dist/Inline-Flex
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
http://search.cpan.org/dist/Inline-Flex
flex (1).
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Inline::Flex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Inline::Flex
CPAN shell
perl -MCPAN -e shell install Inline::Flex
For more information on module installation, please visit the detailed CPAN module installation guide.