[Plib-cvs] plib/src/psl pslLocal.h,1.1,1.2 pslStatement.cxx,1.2,1.3 pslSymbols.cxx,1.2,1.3
Brought to you by:
sjbaker
From: Steve B. <sj...@us...> - 2002-09-05 15:30:40
|
Update of /cvsroot/plib/plib/src/psl In directory usw-pr-cvs1:/tmp/cvs-serv14996/plib/src/psl Modified Files: pslLocal.h pslStatement.cxx pslSymbols.cxx Log Message: Added global variable declarations. Index: pslLocal.h =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslLocal.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pslLocal.h 5 Sep 2002 14:58:57 -0000 1.1 +++ pslLocal.h 5 Sep 2002 15:30:35 -0000 1.2 @@ -184,12 +184,20 @@ int pushAssignmentStatement ( char *c ) ; int pushCompoundStatement () ; int pushStatement () ; - int pushFunction () ; - void pushProgram () ; + + int pushFunctionDeclaration ( char *fn ) ; + int pushLocalVariableDeclaration () ; + int pushGlobalVariableDeclaration ( char *fn ) ; + int pushStaticVariableDeclaration () ; + + int pushGlobalDeclaration () ; + void pushProgram () ; void print_opcode ( FILE *fd, unsigned char op ) ; PSL_Address getVarSymbol ( char *s ) ; + PSL_Address setVarSymbol ( char *s ) ; + PSL_Address getCodeSymbol ( char *s ) ; void setCodeSymbol ( char *s, PSL_Address v ) ; int getExtensionSymbol ( char *s ) ; Index: pslStatement.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslStatement.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslStatement.cxx 5 Sep 2002 14:58:57 -0000 1.2 +++ pslStatement.cxx 5 Sep 2002 15:30:35 -0000 1.3 @@ -230,6 +230,12 @@ getToken ( c ) ; + if ( strcmp ( c, "static" ) == 0 ) + return pushStaticVariableDeclaration () ; + + if ( strcmp ( c, "float" ) == 0 ) + return pushLocalVariableDeclaration () ; + if ( strcmp ( c, "return" ) == 0 ) return pushReturnStatement () ; [...96 lines suppressed...] + "PSL: Expected a declaration of a variable or function - but got '%s'", c); + return FALSE ; +} + + +int PSL_Parser::pushFunctionDeclaration ( char *fn ) +{ + char c [ MAX_TOKEN ] ; + setCodeSymbol ( fn, next_code ) ; getToken ( c ) ; @@ -343,6 +424,7 @@ pushConstant ( "0.0" ) ; pushReturn () ; + return TRUE ; } Index: pslSymbols.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/psl/pslSymbols.cxx,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pslSymbols.cxx 5 Sep 2002 14:58:57 -0000 1.2 +++ pslSymbols.cxx 5 Sep 2002 15:30:35 -0000 1.3 @@ -2,12 +2,43 @@ #include "pslLocal.h" +PSL_Address PSL_Parser::setVarSymbol ( char *s ) +{ + for ( int i = 0 ; i < MAX_SYMBOL ; i++ ) + { + if ( symtab [ i ] . symbol == NULL ) + { + if ( next_var >= MAX_VARIABLE-1 ) + { + ulSetError ( UL_WARNING, "PSL: Too many variables." ) ; + next_var-- ; + } + + symtab [ i ] . set ( s, next_var++ ) ; + return symtab [ i ] . address ; + } + else + if ( strcmp ( s, symtab [ i ] . symbol ) == 0 ) + { + ulSetError ( UL_WARNING, "PSL: Multiple definition of '%s'.", s ) ; + return symtab [ i ] . address ; + } + } + + ulSetError ( UL_WARNING, "PSL: Too many variables." ) ; + return MAX_VARIABLE-1 ; +} + + + PSL_Address PSL_Parser::getVarSymbol ( char *s ) { for ( int i = 0 ; i < MAX_SYMBOL ; i++ ) { if ( symtab [ i ] . symbol == NULL ) { + ulSetError ( UL_WARNING, "PSL: Undefined symbol '%s'.", s ) ; + if ( next_var >= MAX_VARIABLE-1 ) { ulSetError ( UL_WARNING, "PSL: Too many variables." ) ; @@ -22,7 +53,8 @@ return symtab [ i ] . address ; } - ulSetError ( UL_WARNING, "PSL: Too many symbols." ) ; + ulSetError ( UL_WARNING, "PSL: Undefined symbol '%s'.", s ) ; + ulSetError ( UL_WARNING, "PSL: Too many variables." ) ; return MAX_VARIABLE-1 ; } |