1 | /* -*- C++ -*- */ |
---|
2 | #include "ParseNode.h" |
---|
3 | using namespace std; |
---|
4 | |
---|
5 | // Builder |
---|
6 | int ParseNode::indent_by = 4; |
---|
7 | |
---|
8 | ParseNode::ParseNode(void): next( 0 ) {}; |
---|
9 | ParseNode::ParseNode (string _name) : name(_name), next( 0 ) {} |
---|
10 | |
---|
11 | ParseNode *ParseNode::set_name (string _name) { |
---|
12 | name = _name; |
---|
13 | |
---|
14 | return this; |
---|
15 | } |
---|
16 | |
---|
17 | ParseNode *ParseNode::set_name (string *_name) { |
---|
18 | name = *_name; // deep copy |
---|
19 | delete _name; |
---|
20 | |
---|
21 | return this; |
---|
22 | } |
---|
23 | |
---|
24 | ParseNode::~ParseNode(void){ |
---|
25 | delete next; |
---|
26 | }; |
---|
27 | |
---|
28 | string ParseNode::get_name(void) { |
---|
29 | return name; |
---|
30 | } |
---|
31 | |
---|
32 | ParseNode *ParseNode::get_link(void) const { |
---|
33 | return next; |
---|
34 | } |
---|
35 | |
---|
36 | ParseNode *ParseNode::get_last(void) { |
---|
37 | ParseNode * current = this; |
---|
38 | |
---|
39 | while(current->get_link() != 0) |
---|
40 | current = current->get_link(); |
---|
41 | |
---|
42 | return current; |
---|
43 | } |
---|
44 | |
---|
45 | ParseNode *ParseNode::set_link(ParseNode *_next){ |
---|
46 | ParseNode *follow; |
---|
47 | |
---|
48 | if(_next == 0) return this; |
---|
49 | |
---|
50 | for(follow = this; follow->next != 0; follow = follow->next); |
---|
51 | follow->next = _next; |
---|
52 | |
---|
53 | return this; |
---|
54 | } |
---|
55 | |
---|
56 | const string ParseNode::get_name(void) const { |
---|
57 | return name; |
---|
58 | } |
---|
59 | |
---|
60 | void ParseNode::print(std::ostream &os, int indent) const |
---|
61 | { |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void ParseNode::printList(std::ostream &os, int indent) const |
---|
66 | { |
---|
67 | print( os, indent ); |
---|
68 | |
---|
69 | if( next ) { |
---|
70 | next->printList( os, indent ); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | ParseNode &ParseNode::operator,(ParseNode &p){ |
---|
75 | set_link(&p); |
---|
76 | |
---|
77 | return *this; |
---|
78 | } |
---|
79 | |
---|
80 | ParseNode *mkList(ParseNode &pn){ |
---|
81 | /* it just relies on `operator,' to take care of the "arguments" and provides |
---|
82 | a nice interface to an awful-looking address-of, rendering, for example |
---|
83 | (StatementNode *)(&(*$5 + *$7)) into (StatementNode *)mkList(($5, $7)) |
---|
84 | (although "nice" is probably not the word) |
---|
85 | */ |
---|
86 | |
---|
87 | return &pn; |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | // Local Variables: // |
---|
92 | // mode: C++ // |
---|
93 | // compile-command: "gmake" // |
---|
94 | // End: // |
---|