]>
Commit | Line | Data |
---|---|---|
427c49bc A |
1 | /* ANTLR Translator Generator |
2 | * Project led by Terence Parr at http://www.jGuru.com | |
3 | * Software rights: http://www.antlr.org/license.html | |
4 | * | |
5 | * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/TreeParser.cpp#2 $ | |
6 | */ | |
7 | ||
8 | #include "antlr/TreeParser.hpp" | |
9 | #include "antlr/ASTNULLType.hpp" | |
10 | #include <stdio.h> | |
11 | ||
12 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | |
13 | namespace antlr { | |
14 | #endif | |
15 | ||
16 | /** The AST Null object; the parsing cursor is set to this when | |
17 | * it is found to be null. This way, we can test the | |
18 | * token type of a node without having to have tests for null | |
19 | * everywhere. | |
20 | */ | |
21 | RefAST TreeParser::ASTNULL(new ASTNULLType); | |
22 | ||
23 | /** Parser error-reporting function can be overridden in subclass */ | |
24 | void TreeParser::reportError(const RecognitionException& ex) | |
25 | { | |
26 | fprintf(stderr, "%s", (ex.toString() + "\n").c_str()); | |
27 | } | |
28 | ||
29 | /** Parser error-reporting function can be overridden in subclass */ | |
30 | void TreeParser::reportError(const ANTLR_USE_NAMESPACE(std)string& s) | |
31 | { | |
32 | fprintf(stderr, "%s", ("error: " + s + "\n").c_str()); | |
33 | } | |
34 | ||
35 | /** Parser warning-reporting function can be overridden in subclass */ | |
36 | void TreeParser::reportWarning(const ANTLR_USE_NAMESPACE(std)string& s) | |
37 | { | |
38 | fprintf(stderr, "%s", ("warning: " + s + "\n").c_str()); | |
39 | } | |
40 | ||
41 | /** Procedure to write out an indent for traceIn and traceOut */ | |
42 | void TreeParser::traceIndent() | |
43 | { | |
44 | for( int i = 0; i < traceDepth; i++ ) | |
45 | printf(" "); | |
46 | } | |
47 | ||
48 | void TreeParser::traceIn(const char* rname, RefAST t) | |
49 | { | |
50 | traceDepth++; | |
51 | traceIndent(); | |
52 | ||
53 | printf("%s",((ANTLR_USE_NAMESPACE(std)string)"> " + rname | |
54 | + "(" + (t ? t->toString().c_str() : "null") + ")" | |
55 | + ((inputState->guessing>0)?" [guessing]":"") | |
56 | + "\n").c_str()); | |
57 | } | |
58 | ||
59 | void TreeParser::traceOut(const char* rname, RefAST t) | |
60 | { | |
61 | traceIndent(); | |
62 | ||
63 | printf("%s",((ANTLR_USE_NAMESPACE(std)string)"< " + rname | |
64 | + "(" + (t ? t->toString().c_str() : "null") + ")" | |
65 | + ((inputState->guessing>0)?" [guessing]":"") | |
66 | + "\n").c_str()); | |
67 | ||
68 | traceDepth--; | |
69 | } | |
70 | ||
71 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE | |
72 | } | |
73 | #endif |