source: tools/prettyprinter/parse.cc @ 16c95e3

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 16c95e3 was fda8168, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

format tool for pretty printing grammar

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[fda8168]1//                              -*- Mode: C++ -*-
2//
3// Pretty Printer, Copyright (C) Richard C. Bilson and Rodolfo G. Esteves 2001
4//
5// parse.cc --
6//
7// Author           : Richard C. Bilson and Rodolfo G. Esteves
8// Created On       : Sun Dec 16 15:06:31 2001
9// Last Modified By : Peter A. Buhr
10// Last Modified On : Tue Apr  9 22:38:19 2002
11// Update Count     : 435
12//
13
14#include "parse.h"
15#include "filter.h"
16#include "yacc.tab.h"
17
18
19Token::Token( const string &text, int kind ) : text(text), kind(kind) {
20    left = down = NULL;
21} // Token::Token
22
23Token::Token( const string &text, list<string> &ws_list, int kind ) : text(text), kind(kind) {
24//    cerr << "Token3 : text \"" << text << "\"";
25//    for ( list<string>::iterator i = ws_list.begin(); i != ws_list.end(); i ++ ) {
26//      cerr << " WSt: \"" << *i << "\"";
27//    }
28//    cerr << endl;
29    left = down = NULL;
30    // O(1) transfer of the current lex whitespace list to the token's
31    // whitespace list, and clearing the lex whitespace list.
32    Token::ws_list.splice( Token::ws_list.end(), ws_list );
33} // Token::Token
34
35void Token::addLeftTail( Token *n ) {
36    Token *p = this;
37    while ( p->left != 0 ) {
38        p = p->left;
39    } // while
40    p->left = n;
41} // Token::addLeftTail
42
43void Token::addDownLeftTail( Token *n ) {
44    if ( down == 0 ) {
45        down = n;
46    } else {
47        down->addLeftTail( n );
48    } // if
49} // Token::addDownLeftTail
50
51bool Token::isTerminal() {
52    return kind < END_TERMINALS;
53} // Token::isTerminal
54
55int Token::getKind() const {
56    return kind;
57} // Token::getKind()
58
59string Token::getText() const {
60    return text;
61} // Token::getText()
62
63string Token::getWS() {
64    string ret;
65    // concatenate whitespace and comment text
66    for ( list<string>::iterator i = ws_list.begin(); i != ws_list.end(); i ++ ) {
67        ret += *i;
68    } // for
69    return ret;
70} // Token::getWS
71
72bool Token::isComment() {
73    return ws_list.size() > 1 || ( ws_list.size() == 1 && (*ws_list.begin())[0] == '/' );
74} // Token::isComment
75
76string Token::getComment() {
77    string ret;
78    // concatenate whitespace and comment text up to the last comment
79    if ( ws_list.size() > 1 ) {
80        list<string>::iterator end = -- ws_list.end();
81        if ( (*end)[0] == '/' ) end ++;
82        for ( list<string>::iterator i = ws_list.begin(); i != end; i ++ ) {
83            ret += *i;
84        } // for
85    } else if ( ws_list.size() == 1 ) {
86        if ( (*ws_list.begin())[0] == '/' ) ret = *ws_list.begin();
87    } // if
88    return ret;
89} // Token::getComment
90
91
92// Local Variables: //
93// compile-command: "gmake" //
94// End: //
Note: See TracBrowser for help on using the repository browser.