ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/antlr/TreeParser.cpp
Revision: 2469
Committed: Fri Dec 2 15:38:03 2005 UTC (18 years, 7 months ago) by tim
File size: 2086 byte(s)
Log Message:
End of the Link --> List
Return of the Oject-Oriented
replace yacc/lex parser with antlr parser

File Contents

# User Rev Content
1 tim 2469 /* 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: TreeParser.cpp,v 1.1 2005-12-02 15:38:02 tim Exp $
6     */
7    
8     #include <iostream>
9    
10     #include "antlr/TreeParser.hpp"
11     #include "antlr/ASTNULLType.hpp"
12    
13     #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
14     namespace antlr {
15     #endif
16    
17     /** The AST Null object; the parsing cursor is set to this when
18     * it is found to be null. This way, we can test the
19     * token type of a node without having to have tests for null
20     * everywhere.
21     */
22     RefAST TreeParser::ASTNULL(new ASTNULLType);
23    
24     /** Parser error-reporting function can be overridden in subclass */
25     void TreeParser::reportError(const RecognitionException& ex)
26     {
27     ANTLR_USE_NAMESPACE(std)cerr << ex.toString().c_str() << ANTLR_USE_NAMESPACE(std)endl;
28     }
29    
30     /** Parser error-reporting function can be overridden in subclass */
31     void TreeParser::reportError(const ANTLR_USE_NAMESPACE(std)string& s)
32     {
33     ANTLR_USE_NAMESPACE(std)cerr << "error: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
34     }
35    
36     /** Parser warning-reporting function can be overridden in subclass */
37     void TreeParser::reportWarning(const ANTLR_USE_NAMESPACE(std)string& s)
38     {
39     ANTLR_USE_NAMESPACE(std)cerr << "warning: " << s.c_str() << ANTLR_USE_NAMESPACE(std)endl;
40     }
41    
42     /** Procedure to write out an indent for traceIn and traceOut */
43     void TreeParser::traceIndent()
44     {
45     for( int i = 0; i < traceDepth; i++ )
46     ANTLR_USE_NAMESPACE(std)cout << " ";
47     }
48    
49     void TreeParser::traceIn(const char* rname, RefAST t)
50     {
51     traceDepth++;
52     traceIndent();
53    
54     ANTLR_USE_NAMESPACE(std)cout << "> " << rname
55     << "(" << (t ? t->toString().c_str() : "null") << ")"
56     << ((inputState->guessing>0)?" [guessing]":"")
57     << ANTLR_USE_NAMESPACE(std)endl;
58     }
59    
60     void TreeParser::traceOut(const char* rname, RefAST t)
61     {
62     traceIndent();
63    
64     ANTLR_USE_NAMESPACE(std)cout << "< " << rname
65     << "(" << (t ? t->toString().c_str() : "null") << ")"
66     << ((inputState->guessing>0)?" [guessing]":"")
67     << ANTLR_USE_NAMESPACE(std)endl;
68    
69     traceDepth--;
70     }
71    
72     #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
73     }
74     #endif