Thread: [Plib-cvs] plib/src/psl Makefile.am,1.8,1.9 pslCodeGen.cxx,1.12,1.13 pslCompiler.cxx,1.12,1.13 pslCo
Brought to you by:
sjbaker
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv2453/plib/src/psl Modified Files: Makefile.am pslCodeGen.cxx pslCompiler.cxx pslCompiler.h pslContext.cxx pslError.cxx pslExpression.cxx pslOpcodes.h pslToken.cxx Log Message: Fixed bug with backslashes in string constants. Added 'switch' and 'for' statements. Improved error recovery. Index: Makefile.am =================================================================== RCS file: /cvsroot/plib/plib/src/psl/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Makefile.am 7 Sep 2002 23:05:06 -0000 1.8 +++ Makefile.am 8 Sep 2002 18:56:29 -0000 1.9 @@ -3,8 +3,7 @@ lib_LIBRARIES = libplibpsl.a -include_HEADERS = psl.h pslContext.h pslLocal.h \ - pslCompiler.h pslSymbol.h pslOpcodes.h +include_HEADERS = psl.h libplibpsl_a_SOURCES = psl.cxx pslCodeGen.cxx pslContext.cxx \ pslCompiler.cxx pslSymbols.cxx pslToken.cxx \ Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslCodeGen.cxx 8 Sep 2002 04:51:39 -0000 1.12 +++ pslCodeGen.cxx 8 Sep 2002 18:56:29 -0000 1.13 @@ -170,6 +170,8 @@ void pslCompiler::pushNotEqual () { pushCodeByte ( OPCODE_NOTEQUAL ) ; } void pslCompiler::pushEqual () { pushCodeByte ( OPCODE_EQUAL ) ; } +void pslCompiler::pushStackDup () { pushCodeByte ( OPCODE_STACK_DUPLICATE ) ; } + int pslCompiler::pushJumpIfTrue ( int l ) { pushCodeByte ( OPCODE_JUMP_TRUE ) ; Index: pslCompiler.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.cxx,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- pslCompiler.cxx 8 Sep 2002 04:51:39 -0000 1.12 +++ pslCompiler.cxx 8 Sep 2002 18:56:29 -0000 1.13 @@ -90,6 +90,86 @@ } +int pslCompiler::pushSwitchStatement () +{ + if ( ! pushExpression () ) + return error ( "Missing control expression for 'switch'" ) ; + + char c [ MAX_TOKEN ] ; + + getToken ( c ) ; /* Hopefully, the word 'while' */ [...445 lines suppressed...] if ( c[0] != ')' ) - { - error ( "Missing ')' in declaration of '%s'", fn ) ; - return FALSE ; - } + return error ( "Missing ')' in declaration of '%s'", fn ) ; getToken ( c ) ; if ( c [ 0 ] != '{' ) - error ( "Missing '{' in function '%s'", fn ) ; + return error ( "Missing '{' in function '%s'", fn ) ; if ( ! pushCompoundStatement () ) - error ( "Missing '}' in function '%s'", fn ) ; + return error ( "Missing '}' in function '%s'", fn ) ; getToken ( c ) ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pslCompiler.h 8 Sep 2002 04:51:39 -0000 1.8 +++ pslCompiler.h 8 Sep 2002 18:56:29 -0000 1.9 @@ -62,6 +62,7 @@ /* Basic low level code generation. */ + void pushStackDup () ; void pushPop () ; void pushSubtract () ; void pushAdd () ; @@ -107,6 +108,7 @@ int pushReturnStatement () ; int pushPauseStatement () ; + int pushSwitchStatement () ; int pushWhileStatement () ; int pushDoWhileStatement () ; int pushForStatement () ; @@ -117,9 +119,9 @@ int pushStatement () ; int pushFunctionDeclaration ( const char *fn ) ; - int pushLocalVariableDeclaration ( pslType t ) ; - int pushGlobalVariableDeclaration ( const char *fn, pslType t ) ; - int pushStaticVariableDeclaration () ; + int pushLocalVarDecl ( pslType t ) ; + int pushGlobalVarDecl ( const char *fn, pslType t ) ; + int pushStaticVarDecl () ; int pushGlobalDeclaration () ; void pushProgram () ; @@ -146,8 +148,8 @@ const char *getProgName () const { return progName ; } - void error ( const char *fmt, ... ) ; - void warning ( const char *fmt, ... ) ; + int error ( const char *fmt, ... ) ; + int warning ( const char *fmt, ... ) ; int next_var ; int next_label ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pslContext.cxx 8 Sep 2002 04:51:39 -0000 1.4 +++ pslContext.cxx 8 Sep 2002 18:56:29 -0000 1.5 @@ -114,6 +114,14 @@ } return PSL_PROGRAM_CONTINUE ; + case OPCODE_STACK_DUPLICATE : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pushNumber ( v1 ) ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + case OPCODE_SUB : { pslValue *v1 = & stack [ sp - 1 ] ; Index: pslError.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslError.cxx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pslError.cxx 7 Sep 2002 23:05:06 -0000 1.1 +++ pslError.cxx 8 Sep 2002 18:56:29 -0000 1.2 @@ -39,7 +39,7 @@ -void pslCompiler::warning ( const char *fmt, ... ) +int pslCompiler::warning ( const char *fmt, ... ) { va_list argp; va_start ( argp, fmt ) ; @@ -55,11 +55,12 @@ _pslErrorBuffer ) ; bumpWarnings () ; + return FALSE ; } -void pslCompiler::error ( const char *fmt, ... ) +int pslCompiler::error ( const char *fmt, ... ) { va_list argp; va_start ( argp, fmt ) ; @@ -75,6 +76,7 @@ _pslErrorBuffer ) ; bumpErrors () ; + return FALSE ; } Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pslExpression.cxx 7 Sep 2002 23:05:06 -0000 1.8 +++ pslExpression.cxx 8 Sep 2002 18:56:29 -0000 1.9 @@ -34,18 +34,16 @@ { if ( ! pushExpression () ) { - error ( "Missing expression after '('" ) ; ungetToken ( c ) ; - return FALSE ; + return error ( "Missing expression after '('" ) ; } getToken ( c ) ; if ( c [ 0 ] != ')' ) { - error ( "Missing ')' (found '%s')", c ); ungetToken ( c ) ; - return FALSE ; + return error ( "Missing ')' (found '%s')", c ); } return TRUE ; Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pslOpcodes.h 8 Sep 2002 04:51:39 -0000 1.3 +++ pslOpcodes.h 8 Sep 2002 18:56:29 -0000 1.4 @@ -54,4 +54,6 @@ #define OPCODE_SET_INT_VARIABLE 0x1B #define OPCODE_SET_FLOAT_VARIABLE 0x1C #define OPCODE_SET_STRING_VARIABLE 0x1D +#define OPCODE_STACK_DUPLICATE 0x1E + Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pslToken.cxx 8 Sep 2002 04:51:39 -0000 1.10 +++ pslToken.cxx 8 Sep 2002 18:56:29 -0000 1.11 @@ -151,6 +151,8 @@ case 'a' : res [ tp++ ] = '\a' ; break ; default: res [ tp++ ] = c ; break ; } + + isBkSlash = FALSE ; } else res [ tp++ ] = c ; |