|
NAMEParse::Flex - The Fastest Lexer in the WestSYNOPSIS# First, you must create your custom lexer: $ makelexer.pl -n Flex01 grammar.l # Then, interface with the lexer you just created: use Flex01; my $w= gen_walker( 'data.text'); print $w->(); print $w->(); or, use Flex01; walkthrough( 'data.txt' ); DESCRIPTIONParse::Flex works similar to Parse::Lex, but it uses XS for faster performance.This module allows you to construct a lexer analyzer with your custom rules. Parse::Flex is not intended to be used directly; instead, use the script makelexer.pl to submit your grammar file. The output of the script is a custom shared library and a custom .pm module which, among other things, will transparently load the library and provide interface to your (custom) lexer. In other words, you supply a grammar.l file to makelexer.pl and you receive Flex01.pm and Flex02.so . Then, use only the Flex01.pm - since Flex01.pm will automatically load Flex01.so. The grammar.l file requires the same syntax as flex(1); that is, the actions are written in C . See the flex(1) documentation to learn the syntax, or fetch the sample t/grammar.l file inside this package. Interfacing with ParsersAlmost all Perl parsers expect that your lexer provides either a list of two values ( token type and token value), or a reference to such list. Parse::Flex can provides the right response since it consults wantarray context.In the particular case when interfacing with Parse::Yapp, you could also this interface (if you already have a custom parser) : my $p = yapp_new 'MyParser' ; print $p->yapp_parse( 'data.txt' ) ; Loading the Custom LibraryAs mentioned earlier, your custom Flex01.pm will use bootstrap to automatically load Flex01.so. Keep the .so where bootstrap can find it; the current directory is always a good option.METHODSAll the following methods are defined inside the shared library for every custom lexer. Most methods take arguments that are not shown bellow. They are identical to the equivalent flex(1) functions. For now, consult the source code at lib/Parse/Flex/Generate.pm (the $xs_content variable).
Internal Methods
EXPORTtypemeAUTHORIoannis Tambouras, <ioannis@earthlink.net>SEE ALSOflex(1), Parse::Lex
Visit the GSP FreeBSD Man Page Interface. |