[Plib-cvs] plib/src/psl pslFileIO.cxx,NONE,1.1 pslFileIO.h,NONE,1.1 Makefile.am,1.10,1.11 pslCompile
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-10 04:37:42
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv15285/plib/src/psl Modified Files: Makefile.am pslCompiler.cxx pslCompiler.h pslError.cxx pslLocal.h pslToken.cxx Added Files: pslFileIO.cxx pslFileIO.h Log Message: Added #include processing. --- NEW FILE: pslFileIO.cxx --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA [...130 lines suppressed...] if ( c < 0 ) /* EOF */ { if ( fileStackPointer > 1 ) { popDefaultFile () ; return getChar () ; } return -1 ; } return c ; } void unGetChar ( int c ) { defaultFileStack [ fileStackPointer-1 ] -> unGetChar ( c ) ; } --- NEW FILE: pslFileIO.h --- /* PLIB - A Suite of Portable Game Libraries Copyright (C) 1998,2002 Steve Baker This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information visit http://plib.sourceforge.net $Id: pslFileIO.h,v 1.1 2002/09/10 04:37:39 sjbaker Exp $ */ char *getFname () ; int getLineNo () ; void popDefaultFile () ; void pushDefaultFile ( FILE *fd, const char *fname ) ; void pushDefaultFile ( const char *fname ) ; void unGetChar ( int c ) ; int getChar () ; Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/psl/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 8 Sep 2002 19:49:17 -0000 1.10 +++ Makefile.am 10 Sep 2002 04:37:39 -0000 1.11 @@ -5,11 +5,12 @@ include_HEADERS = psl.h -libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslCompiler.cxx pslCompiler.h \ - pslContext.cxx pslContext.h pslDump.cxx pslError.cxx \ - pslExpression.cxx pslLocal.h pslOpcodes.h \ - pslProgram.cxx pslSymbol.h pslSymbols.cxx \ - pslToken.cxx +libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslContext.cxx \ + pslCompiler.cxx pslSymbols.cxx pslToken.cxx \ + pslExpression.cxx pslProgram.cxx pslDump.cxx \ + pslError.cxx pslFileIO.cxx pslCompiler.h \ + pslContext.h pslFileIO.h pslLocal.h \ + pslOpcodes.h pslSymbol.h psl.h INCLUDES = -I$(top_srcdir)/src/util Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- pslCompiler.cxx 8 Sep 2002 22:17:32 -0000 1.14 +++ pslCompiler.cxx 10 Sep 2002 04:37:39 -0000 1.15 @@ -38,28 +38,26 @@ return FALSE ; } - int res = compile ( fd ) ; - fclose ( fd ) ; - return res ; + return compile ( fd, fname ) ; } -int pslCompiler::compile ( FILE *fd ) +int pslCompiler::compile ( FILE *fd, const char *fname ) { init () ; - setDefaultFile ( fd ) ; - pushProgram () ; + pushDefaultFile ( fd, (fname == NULL) ? progName : fname ) ; + pushProgram () ; + popDefaultFile () ; if ( num_errors != 0 || num_warnings != 0 ) - fprintf ( stderr, "PSL: Compiled with %d Warnings, %d Fatal Errors\n", - num_warnings, num_errors ) ; + fprintf ( stderr, "PSL: '%s' Compiled with %d Warnings, %d Fatal Errors\n", + progName, num_warnings, num_errors ) ; /* If there are errors, prevent the program from running. */ if ( num_errors != 0 ) { -dump () ; next_code = 0 ; pushCodeByte ( OPCODE_HALT ) ; } Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pslCompiler.h 8 Sep 2002 22:17:32 -0000 1.10 +++ pslCompiler.h 10 Sep 2002 04:37:39 -0000 1.11 @@ -46,21 +46,22 @@ class pslCompiler { - int line_no ; + /* File I/O and preprocessor */ - int getLineNo () const { return line_no ; } + int getChar () ; + void doIncludeStatement () ; + int doPreProcessorCommand () ; + void getToken ( char *s ) ; [...165 lines suppressed...] pslCompiler ( pslOpcode *_code, pslExtension *_extn, const char *_progName ) @@ -253,8 +266,6 @@ { int i ; - line_no = 1 ; - for ( i = 0 ; i < MAX_CODE ; i++ ) code [ i ] = OPCODE_HALT ; for ( i = 0 ; i < MAX_SYMBOL ; i++ ) @@ -280,7 +291,7 @@ void dump () const ; int compile ( const char *fname ) ; - int compile ( FILE *fd ) ; + int compile ( FILE *fd, const char *fname = NULL ) ; } ; Index: pslError.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslError.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslError.cxx 8 Sep 2002 18:56:29 -0000 1.2 +++ pslError.cxx 10 Sep 2002 04:37:39 -0000 1.3 @@ -47,11 +47,11 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( PSL_COMPILETIME_WARNING, getProgName(), getLineNo(), + (*_pslErrorCB)( PSL_COMPILETIME_WARNING, getFname(), getLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: WARNING - %s\n", - getProgName(),getLineNo(), + getFname(),getLineNo(), _pslErrorBuffer ) ; bumpWarnings () ; @@ -68,11 +68,11 @@ va_end ( argp ) ; if ( _pslErrorCB != NULL ) - (*_pslErrorCB)( PSL_COMPILETIME_ERROR, getProgName(), getLineNo(), + (*_pslErrorCB)( PSL_COMPILETIME_ERROR, getFname(), getLineNo(), _pslErrorBuffer ) ; else fprintf ( stderr, "PSL: \"%s\" line %3d: *ERROR* - %s\n", - getProgName(),getLineNo(), + getFname(),getLineNo(), _pslErrorBuffer ) ; bumpErrors () ; Index: pslLocal.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslLocal.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- pslLocal.h 8 Sep 2002 04:51:39 -0000 1.14 +++ pslLocal.h 10 Sep 2002 04:37:39 -0000 1.15 @@ -37,20 +37,23 @@ /* Limits */ -#define MAX_ARGS 64 -#define MAX_VARIABLE 256 -#define MAX_LABEL 256 -#define MAX_TOKEN 1024 -#define MAX_CODE 512 -#define MAX_STACK 256 -#define MAX_NESTING 32 -#define MAX_UNGET 64 +#define MAX_ARGS 64 +#define MAX_VARIABLE 256 +#define MAX_LABEL 256 +#define MAX_TOKEN 1024 +#define MAX_CODE 512 +#define MAX_STACK 256 +#define MAX_NESTING 32 +#define MAX_UNGET 64 +#define MAX_UNGET_CHAR 1024 #define MAX_SYMBOL (MAX_VARIABLE + MAX_LABEL) +#define MAX_INCLUDE_DEPTH 8 typedef unsigned short pslAddress ; extern int _pslInitialised ; +#include "pslFileIO.h" #include "pslOpcodes.h" #include "pslSymbol.h" #include "pslCompiler.h" Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pslToken.cxx 8 Sep 2002 18:56:29 -0000 1.11 +++ pslToken.cxx 10 Sep 2002 04:37:39 -0000 1.12 @@ -24,52 +24,136 @@ #include "pslLocal.h" -static FILE *defaultFile ; static char ungotten_token [ MAX_UNGET ][ MAX_TOKEN ] ; -static int unget_stack_depth = 0 ; - +static int unget_token_stack_depth = 0 ; -void pslCompiler::setDefaultFile ( FILE *fd ) +int pslCompiler::getChar () [...210 lines suppressed...] + unGetChar ( c ) ; res [ tp ] = '\0' ; } else @@ -203,13 +288,13 @@ void pslCompiler::ungetToken ( const char *s ) { - if ( unget_stack_depth >= MAX_UNGET-1 ) + if ( unget_token_stack_depth >= MAX_UNGET-1 ) { error ( "Too many ungetTokens! This must be an *UGLY* PSL program!" ) ; exit ( -1 ) ; } - strcpy ( ungotten_token[unget_stack_depth++], s ) ; + strcpy ( ungotten_token[unget_token_stack_depth++], s ) ; } |