www.pudn.com > cppcc.rar > ebnf_la_node.cc


/*
 *  File:       ebnf_la_node.cc
 *              $Id: ebnf_la_node.cc,v 1.4 2002/06/13 11:36:38 alec Exp $
 *
 *  Author:     Alec Panoviciu (alecu@email.com)
 * 
 *  Comments:
 *
 *  Revision history:
 *
 *  $Log: ebnf_la_node.cc,v $
 *  Revision 1.4  2002/06/13 11:36:38  alec
 *  added #line stuff
 *
 *  Revision 1.3  2002/05/16 21:34:13  alec
 *  parser generation done
 *
 *  Revision 1.2  2002/05/10 07:15:10  alec
 *  parser parse tree ok
 *
 *  Revision 1.1  2002/05/08 18:17:06  alec
 *  *** empty log message ***
 *
 */

/*
  Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */


#include "ebnf_la_node.hh"
#include "token_spec.hh"

#ifdef DEBUG

ITokenSpec *EbnfLaNode::tokens = NULL;

int EbnfLaNode::indent_level = 0;

void EbnfLaNode::dumpAttributes (ostream &os) const
{
  os << "[";
  if (nullable) os << "n ";
  else os << "- ";
  if (tokens != NULL)
  {
    {
      os << "FIRST(";
      vBitset &v = const_cast(first);
      for (int j = 0; j < v.length(); j++)
        if (v[j].get())
          os << (*tokens)[j].name() << " ";
      os << ")";
    }
    {
      os << "FOLLOW(";
      vBitset &v = const_cast(follow);
      for (int j = 0; j < v.length(); j++)
        if (v[j].get())
          os << (*tokens)[j].name() << " ";
      os << ")";
    }
  }
  os << "]";
}

void EbnfOrNode::dump (ostream &os) const
{
  if (laSpec != NULL) laSpec->dump(os);
  if (!startCode.empty()) os << "{" << startCode.code << "}";
  os << "(";
  pre->dump(os);
  os << " | ";
  post->dump(os);
  os << ")";
  dumpAttributes(os);
  if (!endCode.empty()) os << "{" << endCode.code << "}";
}


void EbnfCatNode::dump (ostream &os) const
{
  if (laSpec != NULL) laSpec->dump(os);
  if (!startCode.empty()) os << "{" << startCode.code << "}";
  os << "(";
  pre->dump(os);
  os << " . ";
  post->dump(os);
  os << ")";
  dumpAttributes(os);
  if (!endCode.empty()) os << "{" << endCode.code << "}";
}


void EbnfStarNode::dump (ostream &os) const
{
  if (laSpec != NULL) laSpec->dump(os);
  if (!startCode.empty()) os << "{" << startCode.code << "}";
  os << "(";
  in->dump(os);
  os << ")*";
  dumpAttributes(os);
  if (!endCode.empty()) os << "{" << endCode.code << "}";
}


void EbnfNonterminalNode::dump (ostream &os) const
{
  if (laSpec != NULL) laSpec->dump(os);
  if (!startCode.empty()) os << "{" << startCode.code << "}";
  os << "(";
  if (!targetVar.empty()) os << targetVar.code << " = ";
  os << nontermName << "(" << actualArgs.code << ")";
  os << ")";
  dumpAttributes(os);
  if (!endCode.empty()) os << "{" << endCode.code << "}";
}


void EbnfTerminalNode::dump (ostream &os) const
{
  if (laSpec != NULL) laSpec->dump(os);
  if (!startCode.empty()) os << "{" << startCode.code << "}";
  os << "( ";
  os << "<" << terminal.name() << "> ";
  os << ")";
  dumpAttributes(os);
  if (!endCode.empty()) os << "{" << endCode.code << "}";
}


void EbnfLambdaNode::dump (ostream &os) const
{
  os << "nil";
  dumpAttributes(os);
}

#endif