Thread: [Plib-cvs] plib/src/psl pslCodeGen.cxx,1.17,1.18 pslCompiler.h,1.19,1.20 pslContext.cxx,1.8,1.9 pslD
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-14 01:30:08
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv9724/plib/src/psl Modified Files: pslCodeGen.cxx pslCompiler.h pslContext.cxx pslDump.cxx pslExpression.cxx pslOpcodes.h pslToken.cxx Log Message: Changed token parser to handle digraph operators. Added '<<' and '>>'. Index: pslCodeGen.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCodeGen.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslCodeGen.cxx 13 Sep 2002 23:51:29 -0000 1.17 +++ pslCodeGen.cxx 14 Sep 2002 01:30:05 -0000 1.18 @@ -182,6 +182,8 @@ void pslCompiler::pushOr () { pushCodeByte ( OPCODE_OR ) ; } void pslCompiler::pushAnd () { pushCodeByte ( OPCODE_AND ) ; } void pslCompiler::pushXor () { pushCodeByte ( OPCODE_XOR ) ; } +void pslCompiler::pushShiftLeft () { pushCodeByte ( OPCODE_SHIFTLEFT ) ; } +void pslCompiler::pushShiftRight () { pushCodeByte ( OPCODE_SHIFTRIGHT ) ; } void pslCompiler::pushLess () { pushCodeByte ( OPCODE_LESS ) ; } void pslCompiler::pushLessEqual () { pushCodeByte ( OPCODE_LESSEQUAL ) ; } Index: pslCompiler.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslCompiler.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- pslCompiler.h 13 Sep 2002 23:51:30 -0000 1.19 +++ pslCompiler.h 14 Sep 2002 01:30:05 -0000 1.20 @@ -90,6 +90,8 @@ void pushOr () ; void pushAnd () ; void pushXor () ; + void pushShiftLeft () ; + void pushShiftRight () ; void pushLess () ; void pushLessEqual () ; void pushGreater () ; @@ -126,6 +128,7 @@ int pushMultExpression () ; int pushAddExpression () ; int pushRelExpression () ; + int pushShiftExpression () ; int pushExpression () ; /* Statement-level parsers & code generators. */ Index: pslContext.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslContext.cxx,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pslContext.cxx 13 Sep 2002 23:51:30 -0000 1.8 +++ pslContext.cxx 14 Sep 2002 01:30:05 -0000 1.9 @@ -152,6 +152,30 @@ } return PSL_PROGRAM_CONTINUE ; + case OPCODE_SHIFTLEFT : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () << v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + + case OPCODE_SHIFTRIGHT : + { + pslValue *v1 = & stack [ sp - 1 ] ; + pslValue *v2 = & stack [ sp - 2 ] ; + + v2 -> set ( v2 -> getInt () >> v1 -> getInt () ) ; + + popVoid () ; + pc++ ; + } + return PSL_PROGRAM_CONTINUE ; + case OPCODE_ADD : { pslValue *v1 = & stack [ sp - 1 ] ; Index: pslDump.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslDump.cxx,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- pslDump.cxx 13 Sep 2002 23:51:30 -0000 1.14 +++ pslDump.cxx 14 Sep 2002 01:30:05 -0000 1.15 @@ -89,6 +89,8 @@ { "AND", OPCODE_AND , 0 }, { "XOR", OPCODE_XOR , 0 }, + { "SHIFT_LEFT", OPCODE_SHIFTLEFT , 0 }, + { "SHIFT_RIGHT", OPCODE_SHIFTRIGHT , 0 }, /* Boolean operators */ { "LESS", OPCODE_LESS , 0 }, Index: pslExpression.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslExpression.cxx,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pslExpression.cxx 13 Sep 2002 23:51:30 -0000 1.10 +++ pslExpression.cxx 14 Sep 2002 01:30:05 -0000 1.11 @@ -30,7 +30,7 @@ char c [ MAX_TOKEN ] ; getToken ( c ) ; - if ( c [ 0 ] == '(' ) + if ( strcmp ( c, "(" ) == 0 ) { if ( ! pushExpression () ) { @@ -40,7 +40,7 @@ getToken ( c ) ; [...211 lines suppressed...] - { - if ( c [ 1 ] == '=' ) - pushGreaterEqual () ; - else - pushGreater () ; - } - else - if ( c [ 0 ] == '!' ) - pushNotEqual () ; - else - pushEqual () ; + if ( strcmp ( c, "<" ) == 0 ) pushLess () ; else + if ( strcmp ( c, ">" ) == 0 ) pushGreater () ; else + if ( strcmp ( c, "<=" ) == 0 ) pushLessEqual () ; else + if ( strcmp ( c, ">=" ) == 0 ) pushGreaterEqual () ; else + if ( strcmp ( c, "!=" ) == 0 ) pushNotEqual () ; else + if ( strcmp ( c, "==" ) == 0 ) pushEqual () ; } } Index: pslOpcodes.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslOpcodes.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pslOpcodes.h 13 Sep 2002 23:51:30 -0000 1.6 +++ pslOpcodes.h 14 Sep 2002 01:30:05 -0000 1.7 @@ -39,32 +39,33 @@ #define OPCODE_TWIDDLE 0x0C #define OPCODE_OROR 0x0D #define OPCODE_ANDAND 0x0E -#define OPCODE_XORXOR 0x0F /* Unused! */ +#define OPCODE_SHIFTLEFT 0x0F -#define OPCODE_OR 0x10 -#define OPCODE_AND 0x11 -#define OPCODE_XOR 0x12 -#define OPCODE_LESS 0x13 -#define OPCODE_LESSEQUAL 0x14 -#define OPCODE_GREATER 0x15 -#define OPCODE_GREATEREQUAL 0x16 -#define OPCODE_NOTEQUAL 0x17 -#define OPCODE_EQUAL 0x18 -#define OPCODE_JUMP_FALSE 0x19 -#define OPCODE_JUMP_TRUE 0x1A -#define OPCODE_JUMP 0x1B -#define OPCODE_POP 0x1C -#define OPCODE_HALT 0x1D -#define OPCODE_CALLEXT 0x1E -#define OPCODE_PAUSE 0x1F +#define OPCODE_SHIFTRIGHT 0x10 +#define OPCODE_OR 0x11 +#define OPCODE_AND 0x12 +#define OPCODE_XOR 0x13 +#define OPCODE_LESS 0x14 +#define OPCODE_LESSEQUAL 0x15 +#define OPCODE_GREATER 0x16 +#define OPCODE_GREATEREQUAL 0x17 +#define OPCODE_NOTEQUAL 0x18 +#define OPCODE_EQUAL 0x19 +#define OPCODE_JUMP_FALSE 0x1A +#define OPCODE_JUMP_TRUE 0x1B +#define OPCODE_JUMP 0x1C +#define OPCODE_POP 0x1D +#define OPCODE_HALT 0x1E +#define OPCODE_CALLEXT 0x1F -#define OPCODE_RETURN 0x20 -#define OPCODE_PUSH_VARIABLE 0x21 -#define OPCODE_POP_VARIABLE 0x22 -#define OPCODE_SET_INT_VARIABLE 0x23 -#define OPCODE_SET_FLOAT_VARIABLE 0x24 -#define OPCODE_SET_STRING_VARIABLE 0x25 -#define OPCODE_STACK_DUPLICATE 0x26 -#define OPCODE_GET_PARAMETER 0x27 +#define OPCODE_PAUSE 0x20 +#define OPCODE_RETURN 0x21 +#define OPCODE_PUSH_VARIABLE 0x22 +#define OPCODE_POP_VARIABLE 0x23 +#define OPCODE_SET_INT_VARIABLE 0x24 +#define OPCODE_SET_FLOAT_VARIABLE 0x25 +#define OPCODE_SET_STRING_VARIABLE 0x26 +#define OPCODE_STACK_DUPLICATE 0x27 +#define OPCODE_GET_PARAMETER 0x28 Index: pslToken.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslToken.cxx,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- pslToken.cxx 12 Sep 2002 04:39:26 -0000 1.17 +++ pslToken.cxx 14 Sep 2002 01:30:05 -0000 1.18 @@ -464,29 +464,70 @@ return ; } - while ( isalnum ( c ) || c == '.' || c == '_' ) + if ( isalnum ( c ) || c == '.' || c == '_' ) /* variables and numbers */ { - res [ tp++ ] = c ; - c = getChar () ; - - if ( tp >= MAX_TOKEN - 1 ) + while ( isalnum ( c ) || c == '.' || c == '_' ) { - error ( "Input string is bigger than %d characters!", + res [ tp++ ] = c ; + c = getChar () ; + + if ( tp >= MAX_TOKEN - 1 ) + { + error ( "Input string is bigger than %d characters!", MAX_TOKEN - 1 ) ; - tp-- ; + tp-- ; + } } + + _pslUnGetChar ( c ) ; } + else - if ( tp > 0 ) + /* Deal with: + <<, >>, <<=, >>=, + /=, +=, -=, *=, %=, &=, |=, + <=, >=, ==, !=, ++, -- + */ + + if ( c == '*' || c == '/' || c == '%' || + c == '<' || c == '>' || c == '=' || + c == '!' || c == '&' || c == '|' || + c == '+' || c == '-' ) { - _pslUnGetChar ( c ) ; - res [ tp ] = '\0' ; + res [ tp++ ] = c ; + + int c2 = getChar () ; + + if ( c2 == '=' || ( c == '>' && c2 == '>' ) || + ( c == '<' && c2 == '<' ) || + ( c == '&' && c2 == '&' ) || + ( c == '|' && c2 == '|' ) || + ( c == '+' && c2 == '+' ) || + ( c == '-' && c2 == '-' ) ) + { + res [ tp++ ] = c2 ; + + if ( ( c == '<' && c2 == '<' ) || + ( c == '>' && c2 == '>' ) ) + { + int c3 = getChar () ; + + if ( c3 == '=' ) + res [ tp++ ] = c3 ; + else + _pslUnGetChar ( c3 ) ; + } + } + else + _pslUnGetChar ( c2 ) ; } else { res [ 0 ] = c ; - res [ 1 ] = '\0' ; + tp = 1 ; } + + res [ tp ] = '\0' ; /* Don't do define substituting if told not to |