Enter your search terms
GNU-Darwin
Web
Submit search form
"http://www.w3.org/TR/html4/loose.dtd">
>
Toy Parser Generator
or
How to easily write parsers in Python
Christophe
Delord
christophe.delord@free.fr
http://christophe.delord.free.fr/en/tpg/
August 22, 2002
Contents
List of Figures
I
Introduction and tutorial
1
Introduction
1.1
Introduction
1.2
License
1.3
Structure of the document
2
Installation
2.1
Getting TPG
2.2
Requirements
2.3
TPG for Linux and other Unix like
2.4
TPG for M$ Windows
2.5
TPG for other operating systems
3
Tutorial
3.1
Introduction
3.2
Defining the grammar
3.3
Reading the input and returning values
3.4
Embeding the parser in a script
3.5
Conclusion
II
TPG reference
4
Usage
4.1
Package content
4.2
Command line usage
5
Grammar structure
5.1
TPG grammar structure
5.2
Comments
5.3
Options
5.4
Python code
5.5
TPG parsers
6
Lexer
6.1
Regular expression syntax
6.2
Token definition
6.3
Token matching
7
Parser
7.1
Declaration
7.2
Base classes of TPG parsers
7.3
Grammar rules
7.4
Parsing terminal symbols
7.5
Parsing non terminal symbols
7.6
Sequences
7.7
Cut
7.8
Alternatives
7.9
Repetitions
7.10
Precedence and grouping
7.11
Actions
8
Context sensitive lexer
8.1
Introduction
8.2
Grammar structure
8.3
CSL lexers
8.4
CSL parsers
III
Some examples to illustrate TPG
9
Complete interactive calculator
9.1
Introduction
9.2
New functions
9.3
Source code
10
Infix/Prefix/Postfix notation converter
10.1
Introduction
10.2
Abstract syntax trees
10.3
Grammar
10.4
Source code
IV
Internal structure of TPG for the curious
11
Structure of the package
11.1
General structure of the package
12
Lexer
12.1
Token matching
13
Parser
13.1
Interface with the lexer
13.2
Sequences of subexpressions
13.3
Alternatives between subexpressions
13.4
Repetitions
14
Code generation
14.1
Inheritance
14.2
Lexer
14.3
Parser