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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2