codemp/icarus/interpreter.h

Go to the documentation of this file.
00001 // Interpreter.h
00002 
00003 #ifndef __INTERPRETER__
00004 #define __INTERPRETER__
00005 
00006 #define ICARUS_VERSION  1.33
00007 
00008 #define MAX_STRING_SIZE 256
00009 #define MAX_VAR_NAME    64
00010 
00011 typedef float   vector_t[3];
00012 
00013 //If you modify this, you MUST modify in g_ICARUScb.c as well.
00014 //Token defines
00015 enum 
00016 {
00017         TK_BLOCK_START = TK_USERDEF,
00018         TK_BLOCK_END,
00019         TK_VECTOR_START,
00020         TK_VECTOR_END,
00021         TK_OPEN_PARENTHESIS,
00022         TK_CLOSED_PARENTHESIS,
00023         TK_VECTOR,
00024         TK_GREATER_THAN,
00025         TK_LESS_THAN,
00026         TK_EQUALS,
00027         TK_NOT,
00028 
00029         NUM_USER_TOKENS
00030 };
00031 
00032 //ID defines
00033 enum
00034 {
00035         ID_AFFECT = NUM_USER_TOKENS,
00036         ID_SOUND,
00037         ID_MOVE,
00038         ID_ROTATE,
00039         ID_WAIT,
00040         ID_BLOCK_START,
00041         ID_BLOCK_END,
00042         ID_SET,
00043         ID_LOOP,
00044         ID_LOOPEND,
00045         ID_PRINT,
00046         ID_USE,
00047         ID_FLUSH,
00048         ID_RUN,
00049         ID_KILL,
00050         ID_REMOVE,
00051         ID_CAMERA,
00052         ID_GET,
00053         ID_RANDOM,
00054         ID_IF,
00055         ID_ELSE,
00056         ID_REM,
00057         ID_TASK,
00058         ID_DO,
00059         ID_DECLARE,
00060         ID_FREE,
00061         ID_DOWAIT,
00062         ID_SIGNAL,
00063         ID_WAITSIGNAL,
00064         ID_PLAY,
00065 
00066         ID_TAG,
00067         ID_EOF,
00068         NUM_IDS
00069 };
00070 
00071 //Type defines
00072 enum
00073 {
00074         //Wait types
00075         TYPE_WAIT_COMPLETE       = NUM_IDS,
00076         TYPE_WAIT_TRIGGERED,
00077 
00078         //Set types
00079         TYPE_ANGLES,
00080         TYPE_ORIGIN,
00081 
00082         //Affect types
00083         TYPE_INSERT,    
00084         TYPE_FLUSH,     
00085         
00086         //Camera types
00087         TYPE_PAN,
00088         TYPE_ZOOM,
00089         TYPE_MOVE,
00090         TYPE_FADE,
00091         TYPE_PATH,
00092         TYPE_ENABLE,
00093         TYPE_DISABLE,
00094         TYPE_SHAKE,
00095         TYPE_ROLL,
00096         TYPE_TRACK,
00097         TYPE_DISTANCE,
00098         TYPE_FOLLOW,
00099                 
00100         //Variable type
00101         TYPE_VARIABLE,
00102 
00103         TYPE_EOF,
00104         NUM_TYPES
00105 };
00106 
00107 enum
00108 {
00109         MSG_COMPLETED,
00110         MSG_EOF,
00111         NUM_MESSAGES,
00112 };
00113 
00114 #ifdef __cplusplus
00115 typedef struct variable_s
00116 {
00117         char    name[MAX_VAR_NAME];
00118         int             type;
00119         void    *data;
00120 } variable_t;
00121 
00122 typedef map< string, variable_t * >     variable_m;
00123 typedef vector < variable_t * > variable_v;
00124 
00125 //CInterpreter
00126 
00127 class CInterpreter 
00128 {
00129 public:
00130 
00131         CInterpreter();
00132         ~CInterpreter();
00133 
00134         int Interpret( CTokenizer *, CBlockStream *, char *filename=NULL );     //Main interpretation function
00135         
00136         int Match( int );               //Looks ahead to the next token to try and match it to the passed token, consumes token on success
00137         int LookAhead( int );   //Looks ahead without consuming on success
00138 
00139         int FindSymbol( const char *,  keywordArray_t * );              //Searches the symbol table for the given name.  Returns the ID if found
00140 
00141         int GetAffect( void );          //Handles the affect() function
00142         int GetWait( void );            //Handles the wait() function
00143         int GetSet( void );                     //Handles the set() function
00144         int GetBroadcast( void );       //Handles the broadcast() function
00145         int GetLoop( void );            //Handles the loop() function
00146         int GetPrint( void );           //Handles the print() function
00147         int GetUse( void );                     //Handles the use() function
00148         int GetFlush( void );           //Handles the flush() function
00149         int     GetRun( void );                 //Handles the run() function
00150         int     GetKill( void );                //Handles the kill() function
00151         int     GetRemove( void );              //Handles the remove() function 
00152         int GetCamera( void );          //Handles the camera() function
00153         int GetIf( void );                      //Handles the if() conditional statement
00154         int GetSound( void );           //Handles the sound() function
00155         int GetMove( void );            //Handles the move() function
00156         int GetRotate( void );          //Handles the rotate() function
00157         int GetRem( void );                     //Handles the rem() function
00158         int     GetTask( void );
00159         int GetDo( void );
00160         int GetElse( void );
00161         int GetDeclare( void );
00162         int GetFree( void );
00163         int GetDoWait( void );
00164         int GetSignal( void );
00165         int GetWaitSignal( void );
00166         int GetPlay( void );
00167         
00168         int GetRandom( CBlock *block );
00169         int GetGet( CBlock *block );            //Heh
00170         int     GetTag( CBlock *block );                //Handles the tag() identifier
00171         int GetVector( CBlock *block );
00172 
00173         int GetNextType( void );
00174 
00175         int GetType( char *get );
00176 
00177         int GetAny( CBlock *block );
00178         int GetEvaluator( CBlock *block );
00179         int GetString( CBlock *);                       //Attempts to match and retrieve the value of a string token
00180         int     GetIdentifier( CBlock *get );   //Attempts to match and retrieve the value of an identifier token
00181         int     GetInteger( CBlock * );         //Attempts to match and retrieve the value of a int token
00182         int GetFloat( CBlock * );               //Attempts to match and retrieve the value of a float token
00183         int GetVariable( int type );
00184 
00185         int GetID ( char * );   //Attempts to match and interpret an identifier
00186         
00187         keywordArray_t *GetSymbols( void )      {       return (keywordArray_t *) &m_symbolKeywords;    }       //Returns the interpreter's symbol table
00188         keywordArray_t *GetIDs( void )          {       return (keywordArray_t *) &m_IDKeywords;                }       //Returns the interpreter's ID table
00189         keywordArray_t *GetTypes( void )        {       return (keywordArray_t *) &m_typeKeywords;      }               //Returns the interpreter's type table
00190 
00191 protected:
00192 
00193         void InitVars( void );
00194         void FreeVars( void );
00195         
00196         variable_t *AddVar( const char *name, int type );
00197         variable_t *FindVar( const char *name );
00198 
00199         const char *GetTokenName( int );        //Returns the name of a token
00200         int Error( char *, ... );                       //Prints an error message
00201         
00202         int MatchTag( void );                           //Attempts to match to a tag identifier
00203         int MatchGet( void );                           //Attempts to match to a get identifier
00204         int     MatchRandom( void );                    //Attempts to match to a random identifier
00205 
00206         CTokenizer      *m_tokenizer;                   //Pointer to the tokenizer
00207         CBlockStream *m_blockStream;            //Pointer to the block stream
00208 
00209         variable_v      m_vars;
00210         variable_m      m_varMap;
00211 
00212         string  m_sCurrentLine;                         // used in IBIze error reporting for more clarity
00213         string  m_sCurrentFile;                         // full-pathed name of .TXT file (needed because of above, which affects parsestreams)
00214         int             m_iCurrentLine;                         // also needed now because of 'm_sCurrentLine'
00215         int             m_iBadCBlockNumber;                     // used for final app return code (NZ = err)
00216 
00217         static keywordArray_t   m_symbolKeywords[];             //Symbols
00218         static keywordArray_t   m_IDKeywords[];                 //Identifiers
00219         static keywordArray_t   m_typeKeywords[];                       //Types
00220         static keywordArray_t   m_conditionalKeywords[];        //Conditional
00221 };
00222 
00223 #endif __cplusplus
00224 #endif  //__INTERPRETER__