Flex/Lex&Bison/Yacc

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值