Flex
Flex - Fast LEXical analyzer generator.(GNU version of lex)
flex is a tool for generation scanners. Convert text to takens?
Flow diagram:
1. lex input file( *.lex / *.l ) --->[ Flex/Lex ]--> lex.yy.c
2. lex.yy.c -->[ cc(gcc) ]--> your scanner
Usage:
# flex [input file name]
Flex will output a C source file named 'lex.yy.c'.
Complie lex.yy.c:
#gcc -lfl lex.yy.c -o sannertoy
This produces the lex.yy.c file, which can be compiled using a C
compiler. It can also be used with a parser to produce an executable,
or you can include the Lex library in the link step with the option
–ll.
Here are some of Lex's flags:
-c Indicates C actions and is the default.
-t Causes the lex.yy.c program to be written instead to standard output.
-v Provides a two-line summary of statistics.-n Will not print out the -v summary.
Format of the input file:
The flex input file consists of 3 sections, separated by a line with just `%%' in it:
definitions
%%
rules
%%
user code
The definitions section have the form:
name definition
Sample:
DIGIT [0-9]
'definition' can be a regular expression.
Foramt of the rules section:
pattern {action}
Sample:
while {return WHILE}
The user code section is simply copied to `lex.yy.c' verbatim.
Lexer will gen a default 'main' funtion if leave 'user code' blank.
tips:
In the definitions and rules sections, any indented text or text enclosed in `%{' and `%}' is copied verbatim to the output (with the `%{}''s removed). The `%{}''s must appear unindented on lines by themselves.
In the rules section, any indented or %{} text appearing before the first rule may be used to declare variables which are local to the scanning routine and (after the declarations) code which is to be executed whenever the scanning routine is entered. Other indented or %{} text in the rule section is still copied to the output, but its meaning is not well-defined and it may well cause compile-time errors (this feature is present for POSIX compliance; see below for other such features).
In the definitions section (but not in the rules section), an unindented comment (i.e., a line beginning with "/*") is also copied verbatim to the output up to the next "*/".
Biaon
Yacc - yet another complier - complier.
A paser generator.
Gnu version called Bison.