Download The Compiler Generator Coco/R
Transcript
2 Contents 1. Overview ..............................................................................................................................................3 1.1 Sample Production.........................................................................................................................3 1.2 Sample Parsing Method .................................................................................................................4 1.3 Summary of Features .....................................................................................................................4 2. Input Language.....................................................................................................................................5 2.1 Vocabulary.....................................................................................................................................5 2.2 Overall Structure............................................................................................................................6 2.3 Scanner Specification ....................................................................................................................7 2.3.1 Character sets .........................................................................................................................7 2.3.2 Tokens....................................................................................................................................8 2.3.3 Pragmas..................................................................................................................................9 2.3.4 Comments ............................................................................................................................ 10 2.3.5 White space .......................................................................................................................... 10 2.3.6 Case sensitivity .................................................................................................................... 10 2.3.7 Named tokens....................................................................................................................... 10 2.4 Parser Specification ..................................................................................................................... 11 2.4.1 Productions .......................................................................................................................... 12 2.4.2 Semantic Actions ................................................................................................................. 12 2.4.3 Attributes ............................................................................................................................. 12 2.4.4 The Symbol ANY ................................................................................................................ 14 2.4.5 LL(1) Conflicts .................................................................................................................... 14 2.4.6 LL(1) Conflict Resolvers ..................................................................................................... 17 2.4.7 Syntax Error Handling ......................................................................................................... 20 2.4.8 Frame Files........................................................................................................................... 23 3. User Guide.......................................................................................................................................... 23 3.1 Installation ................................................................................................................................... 23 3.2 Invocation .................................................................................................................................... 23 3.3 Interfaces of the Generated Classes ............................................................................................. 25 3.3.1 Scanner................................................................................................................................. 25 3.3.2 Token ................................................................................................................................... 25 3.3.3 Buffer ................................................................................................................................... 26 3.3.4 Parser ................................................................................................................................... 26 3.3.5 Errors ................................................................................................................................... 26 3.4 Main Class of the Compiler ......................................................................................................... 27 3.5 Grammar Tests............................................................................................................................. 28 4. A Sample Compiler ............................................................................................................................ 29 5. Applications of Coco/R ...................................................................................................................... 31 6. Acknowledgements ............................................................................................................................ 32 A. Syntax of Cocol/R ............................................................................................................................. 33 B. Sources of the Sample Compiler........................................................................................................ 34 B.1 Taste.ATG................................................................................................................................... 34 B.2 TL.cs (symbol table) ................................................................................................................... 37 B.3 TC.cs (code generator) ................................................................................................................ 39 B.4 Taste.cs (main program).............................................................................................................. 41