OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
TreeParser.cpp
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$
6 */
7
8#include "antlr/TreeParser.hpp"
9#include "antlr/ASTNULLType.hpp"
10
11#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
12namespace antlr {
13#endif
14
15/** The AST Null object; the parsing cursor is set to this when
16 * it is found to be null. This way, we can test the
17 * token type of a node without having to have tests for null
18 * everywhere.
19 */
20RefAST TreeParser::ASTNULL(new ASTNULLType);
21
22/** Parser error-reporting function can be overridden in subclass */
24{
25 ANTLR_USE_NAMESPACE(std)cerr << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
26}
27
28/** Parser error-reporting function can be overridden in subclass */
29void TreeParser::reportError(const ANTLR_USE_NAMESPACE(std)string& s)
30{
31 ANTLR_USE_NAMESPACE(std)cerr << "error: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
32}
33
34/** Parser warning-reporting function can be overridden in subclass */
35void TreeParser::reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
36{
37 ANTLR_USE_NAMESPACE(std)cerr << "warning: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
38}
39
40/** Procedure to write out an indent for traceIn and traceOut */
42{
43 for( int i = 0; i < traceDepth; i++ )
44 ANTLR_USE_NAMESPACE(std)cout << " ";
45}
46
47void TreeParser::traceIn(const char* rname, RefAST t)
48{
49 traceDepth++;
51
52 ANTLR_USE_NAMESPACE(std)cout << "> " << rname
53 << "(" << (t ? t->toString().c_str() : "null") << ")"
54 << ((inputState->guessing>0)?" [guessing]":"")
55 << ANTLR_USE_NAMESPACE(std)endl;
56}
57
58void TreeParser::traceOut(const char* rname, RefAST t)
59{
61
62 ANTLR_USE_NAMESPACE(std)cout << "< " << rname
63 << "(" << (t ? t->toString().c_str() : "null") << ")"
64 << ((inputState->guessing>0)?" [guessing]":"")
65 << ANTLR_USE_NAMESPACE(std)endl;
66
67 traceDepth--;
68}
69
70#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
71}
72#endif
virtual std::string toString() const =0
Return this AST node as a string.
virtual std::string toString() const
Return complete error message with line/column number info (if present)
int traceDepth
Used to keep track of indent depth with -traceTreeParser.
virtual void reportError(const RecognitionException &ex)
Parser error-reporting function can be overridden in subclass.
virtual void traceIndent()
These are used during when traceTreeParser commandline option is passed.
virtual void reportWarning(const std ::string &s)
Parser warning-reporting function can be overridden in subclass.
TreeParserSharedInputState inputState
The input state of this tree parser.
static RefAST ASTNULL
The AST Null object; the parsing cursor is set to this when it is found to be null.
int guessing
Are we guessing (guessing>0)?