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


/*
 *  File:       cppcc_driver.cc
 *              $Id: cppcc_driver.cc,v 1.10 2002/07/09 03:04:58 alec Exp $
 *
 *  Author:     Alec Panoviciu (alecu@email.com)
 * 
 *  Comments:
 *
 *  Revision history:
 *
 *  $Log: cppcc_driver.cc,v $
 *  Revision 1.10  2002/07/09 03:04:58  alec
 *  OWN_STRINGS bu*beep*it finally vanished
 *  gcc 3.1&mingw - related cleanups
 *
 *  Revision 1.9  2002/05/22 01:24:33  alec
 *  case sensitivity support
 *
 *  Revision 1.8  2002/05/16 21:33:05  alec
 *  parser generation done
 *
 *  Revision 1.7  2002/05/10 07:15:10  alec
 *  parser parse tree ok
 *
 *  Revision 1.6  2002/05/08 18:16:24  alec
 *  *** empty log message ***
 *
 *  Revision 1.5  2002/05/04 17:39:22  alec
 *  the scanner works (slightly tested)
 *
 *  Revision 1.4  2002/04/30 16:24:38  alec
 *  tested the scanner ptree & vBitVector implementation -> ok
 *
 *  Revision 1.3  2002/04/29 09:34:10  alec
 *  scanner ptree building compiles
 *
 */

/*
  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 "debug.h"
#include "prop_registry.hh"
#include "cppcc_driver.hh"
#include "lex_yacc_parser.hh"
#include "token_spec.hh"
#include "scanner_spec.hh"
#include "parser_spec.hh"
#include "dfa_generator.hh"
#include "scanner_dfa_spec.hh"
#include "scanner_dfa_writer.hh"
#include "token_writer.hh"
#include "lanalyzer.hh"
#include "la_parser_writer.hh"

bool CppCcDriver::run (PropRegistry ®istry)
{
  ASSERT(registry.contains("input_file"), "no input file ???");

  TokenSpec tSpec;
  ScannerSpec sSpec(tSpec, registry);
  ParserSpec pSpec(registry, tSpec);
  LexYaccParser parser;

  if (!parser.parse(registry, tSpec, sSpec, pSpec))
    return false;

  DfaGenerator dfaGen;
  ScannerDfaSpec dfa = dfaGen.createScannerDfa(registry, sSpec, tSpec);

  LAnalyzer lan(registry);
  try {
    lan.makeLa(pSpec);
  } catch (ParseException &pex)
  {
    die(formatError(pex));
  }
  
  TokenWriter tkw(registry);
  tkw.writeTokenClass(tSpec, dfa.className);
  ScannerDfaWriter dfaw(tSpec, registry);
  dfaw.writeScanner(dfa);

  LaParserWriter pw(registry);
  pw.writeParser(pSpec, tSpec, sSpec.className);

  return true;
}