(file) Return to parser.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Compiler

  1 bob   1.1 //BEGIN_LICENSE
  2           //
  3           // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
  4           //
  5           // Permission is hereby granted, free of charge, to any person obtaining a
  6           // copy of this software and associated documentation files (the "Software"),
  7           // to deal in the Software without restriction, including without limitation
  8           // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9           // and/or sell copies of the Software, and to permit persons to whom the
 10           // Software is furnished to do so, subject to the following conditions:
 11           //
 12           // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 13           // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 14           // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 15           // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 16           // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 17           // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 18           // DEALINGS IN THE SOFTWARE.
 19           //
 20           //END_LICENSE
 21           //BEGIN_HISTORY
 22 bob   1.1 //
 23           // Author: Bob Blair (bblair@bmc.com)
 24           //
 25 bob   1.2 // $Log: parser.cpp,v $
 26           // Revision 1.1  2001/02/16 23:59:09  bob
 27           // Initial checkin
 28           //
 29 bob   1.1 //
 30           //END_HISTORY
 31           //
 32           // implementation of valueFactory 
 33           //
 34           //
 35           //
 36           // implementation of those methods  of class parser which are not pure
 37           // virtual
 38           //
 39           
 40           #include "parser.h"
 41 bob   1.2 //#include <sstream>
 42           #include "parserExceptions.h"
 43 bob   1.1 
 44           //---------------------------------------------------------------------
 45           // Take a YY_BUFFERSTATE off the stack of saved contexts
 46           //---------------------------------------------------------------------
 47           bufstate *
 48           parser::pop_statebuff() {
 49               bufstate *v = 0;
 50               if (!_include_stack.empty()) {
 51                 v = _include_stack.top();
 52                 _include_stack.pop();
 53               }
 54               return v;
 55           }
 56           
 57           //-------------------------------------------------------------------
 58           // Create a flex input buffer from a string containing the file name
 59           //-------------------------------------------------------------------
 60           int 
 61           parser::setInputBufferFromName(const string &filename) {
 62             FILE *f = fopen(filename.c_str(),"rt");
 63             if (f) {
 64 bob   1.1     set_current_filename(filename);
 65               set_lineno(1);
 66               return setInputBuffer(f);
 67             } else {
 68               return 1;
 69             }
 70           }
 71           
 72           //-----------------------------------------------------------------
 73           // Handle the end of an input buffer.  Either there is saved context
 74           // or there isn't.  If there is, restore the saved particulars
 75           // of that context so we can keep on parsing
 76           //-----------------------------------------------------------------
 77           int
 78           parser::wrap() {
 79             bufstate *v = pop_statebuff();
 80             if (v) {
 81               setInputBuffer(v->buffer_state);
 82               set_current_filename(v->filename);
 83               set_lineno(v->lineno);
 84               delete v;
 85 bob   1.1     return 0;  // more data available
 86             } else {
 87               return 1;  // end of it all
 88             }
 89           }
 90           
 91 bob   1.2 using namespace ParserExceptions;
 92           
 93 bob   1.1 //----------------------------------------------------------------
 94           // Log where an error occured.  This is pretty lame, so it needs a
 95           // FIXME
 96           //----------------------------------------------------------------
 97           void
 98           parser::log_parse_error(char *token, char *errmsg) const {
 99 bob   1.2   char buf[40];
100             sprintf(buf, "%d", _lineno);
101             string s = _current_filename + ":" + buf + ": " + errmsg + " before `" 
102               + token + "'\n";
103             throw ParserLexException(s.c_str());
104 bob   1.1 }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2