JFLEX--词法分析器用户手册

来源:互联网 发布:数据统计html 编辑:程序博客网 时间:2024/05/22 15:51

The FastLexical Analyser Generator

Copyrightc 1998–2009 by GerwinKlein

JFlexUser’s Manual

Version1.4.3, January 31, 2009

翻译了1-5章节 又需要可以在这里下载

Contents

1Introduction 3

1.1 Designgoals . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Aboutthis manual . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 3

2Installing and Running JFlex 4

2.1Installing JFlex . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.1.1 Windows. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . 4

2.1.2 Unixwith tar archive . . . . . .. . . . . . . . . . . . . . . . . . . . . . 4

2.1.3 Linuxwith RPM . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 5

2.2 Running JFlex. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . 5

3 Asimple Example: How to work with JFlex 6

3.1 Code toinclude . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.2 Optionsand Macros . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 9

3.3 Rules andActions . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 11

3.4 How toget it going . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 12

4Lexical Specifications 12

4.1 User code. . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . 13

4.2 Optionsand declarations . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 13

4.2.1 Classoptions and user class code .. . . . . . . . . . . . . . . . . . . . . 13

4.2.2Scanning method . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 15

4.2.3 The endof file . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 16

4.2.4Standalone scanners . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 17

4.2.5 CUPcompatibility . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 18

4.2.6 BYacc/Jcompatibility . . . . . . . . .. . . . . . . . . . . . . . . . . . . 18

4.2.7 Codegeneration . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 19

4.2.8Character sets . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . 20

4.2.9 Line,character and column counting .. . . . . . . . . . . . . . . . . . . 20

1

4.2.10Obsolete JLex options .. . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.2.11 Statedeclarations . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 21

4.2.12 Macrodefinitions . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . 22

4.3 Lexicalrules . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.3.1 Syntax . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . 22

4.3.2Semantics . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . 24

4.3.3 How theinput is matched . . . . . .. . . . . . . . . . . . . . . . . . . . 27

4.3.4 Thegenerated class . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 28

4.3.5 Scannermethods and fields accessible in actions (API) . . . . . . . . . . 29

5Encodings, Platforms, and Unicode 31

5.1 TheProblem . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

5.2 Scanningtext files . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 31

5.3 Scanningbinaries . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . 32

6 A fewwords on performance 33

6.1Comparison of JLex and JFlex .. . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.2 How towrite a faster specification .. . . . . . . . . . . . . . . . . . . . . . . . 35

7Porting Issues 37

7.1 Portingfrom JLex . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 37

7.2 Portingfrom lex/flex . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 38

7.2.1 Basicstructure . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . 38

7.2.2 Macrosand Regular Expression Syntax .. . . . . . . . . . . . . . . . . 38

7.2.3 LexicalRules . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . 39

8Working together 39

8.1 JFlex andCUP . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . 39

8.1.1 CUPversion 0.10j and above .. . . . . . . . . . . . . . . . . . . . . . . 39

8.1.2 Customsymbol interface . . . . . .. . . . . . . . . . . . . . . . . . . . . 40

8.1.3 Usingexisting JFlex/CUP specifications with CUP 0.10j . . . . . . . . . 40

8.1.4 Usingolder versions of CUP .. . . . . . . . . . . . . . . . . . . . . . . . 41

8.2 JFlex andBYacc/J . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . 43

9 Bugsand Deficiencies 45

9.1Deficiencies . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

9.2 Bugs . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . 46

10Copying and License 46

 


 

原创粉丝点击