Download ANTLR Reference Manual

Transcript
What's ANTLR........................................................................................................... 5
ANTLR 2.7.2 Release Notes .................................................................................. 6
Enhancements ........................................................................................................... 6
Java Code Generation ............................................................................................... 7
C++ Code Generation ............................................................................................... 9
C# Code Generation................................................................................................ 10
Bug Fixes ................................................................................................................ 11
ANTLR Installation ................................................................................................ 12
ANTLR Meta-Language ........................................................................................ 14
Meta-Language Vocabulary ................................................................................... 14
Header Section ........................................................................................................ 17
Parser Class Definitions.......................................................................................... 17
Lexical Analyzer Class Definitions ........................................................................ 18
Tree-parser Class Definitions ................................................................................. 18
Options Section....................................................................................................... 18
Tokens Section........................................................................................................ 18
Grammar Inheritance .............................................................................................. 20
Rule Definitions ...................................................................................................... 20
Atomic Production elements................................................................................... 22
Simple Production elements ................................................................................... 23
Production Element Operators................................................................................ 24
Token Classes ......................................................................................................... 25
Predicates ................................................................................................................ 25
Element Labels ....................................................................................................... 26
EBNF Rule Elements.............................................................................................. 26
Interpretation Of Semantic Actions ........................................................................ 27
Semantic Predicates ................................................................................................ 27
Syntactic Predicates ................................................................................................ 28
ANTLR Meta-Language Grammar......................................................................... 30
Lexical Analysis with ANTLR.............................................................................. 31
Lexical Rules .......................................................................................................... 31
Predicated-LL(k) Lexing ........................................................................................ 33
Keywords and literals ............................................................................................. 36
Common prefixes.................................................................................................... 36
Token definition files.............................................................................................. 36
Character classes..................................................................................................... 36
Token Attributes ..................................................................................................... 37
Lexical lookahead and the end-of-token symbol .................................................... 37
Scanning Binary Files ............................................................................................. 41
Scanning Unicode Characters ................................................................................. 43
Manipulating Token Text and Objects ................................................................... 44
Filtering Input Streams ........................................................................................... 47
Lexical States .......................................................................................................... 54
The End Of File Condition ..................................................................................... 55
Case sensitivity ....................................................................................................... 56
Ignoring whitespace in the lexer ............................................................................. 56
Tracking Line Information...................................................................................... 57
2