1using(3)                            ANTLR3C                           using(3)
2
3
4

NAME

6       using - .TH "using" 3 "Wed Oct 13 2010" "Version 3.1.2" "ANTLR3C"
7

NAME

9       using - .SH "Introduction"
10
11       Using the ANTLR target involves gaining knowledge of a number of
12       elements:
13
14       1.  Writing ANTLR grammars (not covered in this manual);
15
16       2.  How ANTLR works (not covered in this manual);
17
18       3.  How to use the @sections with the C target
19
20       4.  Interoperation with the runtime within rule actions;
21
22       5.  Implementing custom versions of the standard library methods;
23
24       If you are as yet unfamiliar with how ANTLR works in general, then it
25       is suggested that you read the various wiki pages concerned with
26       getting started. However there are a few things that you should note:
27
28       · The lexer is independent of the parser. You cannot control the lexer
29         from within the parser;
30
31       · The tree parser is independent of the parser. You cannot control the
32         parser from within the tree parser(s);
33
34       · Each tree parser is independent of other tree parsers.
35
36       This means that your lexer runs first and consumes all the input stream
37       until you stop it programmatically, or it reaches the end of the input
38       stream. It produces a complete stream of tokens, which the parser then
39       consumes.
40

@sections in a C Targeted Grammar

42       Within a grammar file there are a number of special sections you can
43       add that cause the code within them to be placed at strategic points in
44       the generated code such as before or after the include statements in
45       the .c file, within the generated header file or within the constructor
46       for the recognizer.
47
48       Many of the @sections used within a Java targeted grammar have some
49       equivalent function within a C targeted grammar, but their use may well
50       be subtly different. There are also additional sections that have
51       meaning only within a grammar targeted for the C runtime.
52
53       Detailed documentation of these sections is given here: Using Sections
54       Within Grammar Files
55

Interacting with the Generated Code

57       Rule actions have a limited number of elements they can access by name,
58       independently of the target language generated. These are elements such
59       as $line, $pos, $text and so on. Where the $xxx returns a basic type
60       such as int, then you can use these in C as you would in the Java
61       target, but where a reference returns a string, you will get a pointer
62       to the C runtime string implementation pANTLR3_STRING. This will give
63       you access to things like token text but also provides some convenience
64       methods such as pANTLR3_STRING->substring() and
65       pANTLR3_STRING->toUTF8().
66
67       The generated code provides a number of C MACROs, which make it easier
68       to access runtime components. Always use these macros when available,
69       to protect your action code from changes to the underlying
70       implementation.
71
72       Detailed documentation of macros and rule action interoperation is
73       given here: Interacting with the Generated Code
74

Implementing Customized Methods

76       Unless you wish to create your own tree structures using the built in
77       ANTLR AST rewriting notation, you will rarely need to override the
78       default implementation of runtime methods. The exception to this will
79       be the syntax err reporting method, which is essentially a stub
80       function that you will usually want to provide your own implementation
81       for. You should consider the built in function
82       displayRecognitionError() as an example of where to start as there can
83       be no really useful generic error message display.
84
85
86
87Version 3.1.2                   Wed Oct 13 2010                       using(3)
Impressum