[Plib-cvs] plib/src/psl pslCodeGen.cxx,1.26,1.27 pslCompiler.h,1.28,1.29 pslContext.cxx,1.15,1.16 ps
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-15 17:45:56
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv23942/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.h pslContext.cxx pslExpression.cxx pslToken.cxx Log Message: Added character constants and string variable addition. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- pslCodeGen.cxx 15 Sep 2002 06:36:24 -0000 1.26 +++ pslCodeGen.cxx 15 Sep 2002 17:45:53 -0000 1.27 @@ -49,6 +49,18 @@ } +void pslCompiler::pushCharConstant ( char c ) +{ + /* A bit wasteful but... */ + + pushCodeByte ( OPCODE_PUSH_INT_CONSTANT ) ; + pushCodeByte ( c ) ; + pushCodeByte ( 0 ) ; + pushCodeByte ( 0 ) ; + pushCodeByte ( 0 ) ; +} + + void pslCompiler::pushConstant ( const char *c ) { int isInteger = TRUE ; Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- pslCompiler.h 15 Sep 2002 14:32:53 -0000 1.28 +++ pslCompiler.h 15 Sep 2002 17:45:53 -0000 1.29 @@ -119,6 +119,7 @@ void pushIntConstant ( const char *s ) ; void pushFloatConstant ( const char *s ) ; void pushStringConstant( const char *s ) ; + void pushCharConstant ( char c ) ; void pushIntConstant ( int i ) ; void pushVoidConstant () ; Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- pslContext.cxx 15 Sep 2002 14:32:53 -0000 1.15 +++ pslContext.cxx 15 Sep 2002 17:45:53 -0000 1.16 @@ -189,6 +189,16 @@ if ( v1->getType() == PSL_FLOAT || v2->getType() == PSL_FLOAT ) v2 -> set ( v2 -> getFloat() + v1 -> getFloat() ) ; else + if ( v1->getType() == PSL_STRING && v2->getType() == PSL_STRING ) + { + char *s = new char [ strlen ( v1 -> getString () ) + + strlen ( v2 -> getString () ) + 1 ] ; + strcpy ( s, v2 -> getString () ) ; + strcat ( s, v1 -> getString () ) ; + v2 -> set ( s ) ; + delete s ; + } + else v2 -> set ( v2 -> getInt () + v1 -> getInt () ) ; popVoid () ; @@ -491,7 +501,6 @@ pc++ ; return PSL_PROGRAM_CONTINUE ; - case OPCODE_POP_ADD_VARIABLE : { pslVariable *v = & ( variable [ code[++pc] ] ) ; @@ -499,11 +508,20 @@ if ( v -> getType () == PSL_INT ) v -> set ( v -> getInt() + stack[--sp].getInt()) ; else + if ( v -> getType () == PSL_STRING ) + { + char *s = new char [ strlen ( v -> getString () ) + + strlen ( stack[sp-1] . getString () ) + 1 ] ; + strcpy ( s, v -> getString () ) ; + strcat ( s, stack[--sp] . getString () ) ; + v -> set ( s ) ; + delete s ; + } + else v -> set ( v -> getFloat() + stack[--sp].getFloat()) ; pc++ ; } return PSL_PROGRAM_CONTINUE ; - case OPCODE_POP_SUB_VARIABLE : { Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- pslExpression.cxx 15 Sep 2002 04:34:39 -0000 1.15 +++ pslExpression.cxx 15 Sep 2002 17:45:53 -0000 1.16 @@ -102,6 +102,12 @@ } } + if ( c [ 0 ] == '\'' ) + { + pushCharConstant ( c [ 1 ] ) ; + return TRUE ; + } + if ( c [ 0 ] == '"' ) { pushStringConstant ( & c [ 1 ] ) ; Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- pslToken.cxx 15 Sep 2002 01:05:18 -0000 1.20 +++ pslToken.cxx 15 Sep 2002 17:45:53 -0000 1.21 @@ -438,7 +438,7 @@ case 'f' : res [ tp++ ] = '\f' ; break ; case 'b' : res [ tp++ ] = '\b' ; break ; case 'a' : res [ tp++ ] = '\a' ; break ; - default: res [ tp++ ] = c ; break ; + default : res [ tp++ ] = c ; break ; } isBkSlash = FALSE ; @@ -460,6 +460,41 @@ error ( "Missing \\\" character" ) ; /* The trailing quotes character is not included into the string */ + res [ tp ] = '\0' ; + return ; + } + + if ( c == '\'' ) + { + res [ tp++ ] = '\'' ; + + c = getChar () ; + + if ( c == '\\' ) + { + c = getChar () ; + + switch ( c ) + { + case '0' : res [ tp++ ] = '\0' ; break ; + case 'r' : res [ tp++ ] = '\r' ; break ; + case 't' : res [ tp++ ] = '\t' ; break ; + case 'n' : res [ tp++ ] = '\n' ; break ; + case 'f' : res [ tp++ ] = '\f' ; break ; + case 'b' : res [ tp++ ] = '\b' ; break ; + case 'a' : res [ tp++ ] = '\a' ; break ; + default : res [ tp++ ] = c ; break ; + } + } + else + res [ tp++ ] = c ; + + c = getChar () ; + + if ( c != '\'' ) + error ( "Missing \\' character" ) ; + + /* The trailing quote character is not included into the string */ res [ tp ] = '\0' ; return ; } |