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

  1 karl  1.18 //%2005////////////////////////////////////////////////////////////////////////
  2 mike  1.9  //
  3 karl  1.17 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.16 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 mike  1.9  //
 12            // Permission is hereby granted, free of charge, to any person obtaining a copy
 13 kumpf 1.12 // of this software and associated documentation files (the "Software"), to
 14            // deal in the Software without restriction, including without limitation the
 15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16 mike  1.9  // sell copies of the Software, and to permit persons to whom the Software is
 17            // furnished to do so, subject to the following conditions:
 18            // 
 19 kumpf 1.12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20 mike  1.9  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22 kumpf 1.12 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25 mike  1.9  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27            //
 28            //==============================================================================
 29            //
 30            // Author: Bob Blair (bblair@bmc.com)
 31            //
 32            // Modified By:
 33            //
 34            //%/////////////////////////////////////////////////////////////////////////////
 35            
 36            
 37            //
 38            // implementation of valueFactory 
 39            //
 40            //
 41            //
 42            // implementation of those methods  of class parser which are not pure
 43            // virtual
 44            //
 45            
 46 mike  1.9  #include "parser.h"
 47            //#include <sstream>
 48            #include "parserExceptions.h"
 49            
 50            //---------------------------------------------------------------------
 51            // Take a YY_BUFFERSTATE off the stack of saved contexts
 52            //---------------------------------------------------------------------
 53            bufstate *
 54            parser::pop_statebuff() {
 55                bufstate *v = 0;
 56                if (!_include_stack.isEmpty()) {
 57                  v = _include_stack.top();
 58                  _include_stack.pop();
 59                }
 60                return v;
 61            }
 62            
 63            //-------------------------------------------------------------------
 64            // Create a flex input buffer from a String containing the file name
 65            //-------------------------------------------------------------------
 66            int 
 67 mike  1.9  parser::setInputBufferFromName(const String &filename) {
 68 chuck 1.13 #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 69              // 't' not supported on OS/400
 70 kumpf 1.14   FILE *f = fopen(filename.getCString(),"r");
 71 chuck 1.13 #else
 72 kumpf 1.14   FILE *f = fopen(filename.getCString(),"rt");
 73 chuck 1.13 #endif
 74 mike  1.9    if (f) {
 75                set_current_filename(filename);
 76                set_lineno(1);
 77 kumpf 1.15     return setInputBuffer(f, false);
 78 mike  1.9    } else {
 79                return 1;
 80              }
 81            }
 82            
 83            //-----------------------------------------------------------------
 84            // Handle the end of an input buffer.  Either there is saved context
 85            // or there isn't.  If there is, restore the saved particulars
 86            // of that context so we can keep on parsing
 87            //-----------------------------------------------------------------
 88            int
 89            parser::wrap() {
 90              bufstate *v = pop_statebuff();
 91              if (v) {
 92 kumpf 1.15     setInputBuffer(v->buffer_state, true);
 93 mike  1.9      set_current_filename(v->filename);
 94                set_lineno(v->lineno);
 95                delete v;
 96                return 0;  // more data available
 97              } else {
 98                return 1;  // end of it all
 99              }
100            }
101            
102            #ifdef PEGASUS_HAVE_NAMESPACES
103            using namespace ParserExceptions;
104            #endif /* PEGASUS_HAVE_NAMESPACES */
105            
106            //----------------------------------------------------------------
107 karl  1.10 // ATTN: P2 BB 2001 Log where an error occured.  This is lame, so it needs work
108            // 
109 mike  1.9  //----------------------------------------------------------------
110            void
111 kumpf 1.11 parser::log_parse_error(char *token, const char *errmsg) const {
112 mike  1.9    char buf[40];
113              sprintf(buf, "%d", _lineno);
114              String s = _current_filename + ":" + buf + ": " + errmsg + " before `" 
115                + token + "'\n";
116 kumpf 1.14   throw ParserLexException(s);
117 mike  1.9  }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2