2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
/*
|
|
|
|
* Parse.h
|
|
|
|
*
|
|
|
|
* Definitions for the script parser
|
|
|
|
*/
|
|
|
|
#ifndef _parse_h
|
|
|
|
#define _parse_h
|
|
|
|
|
2007-10-05 15:44:18 -07:00
|
|
|
#include <physfs.h>
|
|
|
|
|
2007-01-02 12:12:14 -08:00
|
|
|
#ifndef MAXSTRLEN
|
|
|
|
#define MAXSTRLEN 255
|
|
|
|
#endif
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Maximum number of TEXT items in any one Yacc rule */
|
|
|
|
#define TEXT_BUFFERS 10
|
|
|
|
|
2006-11-16 06:30:29 -08:00
|
|
|
#ifdef DEBUG_SCRIPT
|
|
|
|
#define RULE(...) script_debug(__VA_ARGS__);
|
|
|
|
#else
|
|
|
|
#define RULE(...)
|
|
|
|
#endif
|
|
|
|
|
2007-01-02 12:12:14 -08:00
|
|
|
/* Script includes */
|
|
|
|
#define MAX_SCR_INCLUDE_DEPTH 10
|
|
|
|
|
|
|
|
/* Script defines */
|
|
|
|
#define MAX_SCR_MACRO_DEPTH 10
|
|
|
|
#define MAX_SCR_MACROS 150 /* Max defines in a file */
|
2007-09-29 07:41:46 -07:00
|
|
|
#define MAX_SCR_MACRO_LEN 32
|
2007-01-02 12:12:14 -08:00
|
|
|
|
|
|
|
/* Structure to hold script define directive information */
|
|
|
|
typedef struct _scr_define
|
|
|
|
{
|
|
|
|
char scr_define_macro[MAX_SCR_MACRO_LEN];
|
|
|
|
char scr_define_body[MAXSTRLEN];
|
|
|
|
}SCR_MACRO;
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Definition for the chunks of code that are used within the compiler */
|
|
|
|
typedef struct _code_block
|
|
|
|
{
|
2006-11-16 06:30:29 -08:00
|
|
|
UDWORD size; // size of the code block
|
|
|
|
INTERP_VAL *pCode; // pointer to the code data
|
|
|
|
UDWORD debugEntries;
|
|
|
|
SCRIPT_DEBUG *psDebug; // Debugging info for the script.
|
|
|
|
INTERP_TYPE type; // The type of the code block
|
2007-06-28 10:47:08 -07:00
|
|
|
} CODE_BLOCK;
|
|
|
|
|
|
|
|
/* The chunk of code returned from parsing a parameter list. */
|
|
|
|
typedef struct _param_block
|
|
|
|
{
|
|
|
|
UDWORD numParams;
|
|
|
|
INTERP_TYPE *aParams; // List of parameter types
|
|
|
|
UDWORD size;
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode; // The code that puts the parameters onto the stack
|
2007-06-28 10:47:08 -07:00
|
|
|
}PARAM_BLOCK;
|
|
|
|
|
|
|
|
/* The types of a functions parameters, returned from parsing a parameter declaration */
|
|
|
|
typedef struct _param_decl
|
|
|
|
{
|
|
|
|
UDWORD numParams;
|
|
|
|
INTERP_TYPE *aParams;
|
|
|
|
} PARAM_DECL;
|
|
|
|
|
|
|
|
/* The chunk of code used while parsing a conditional statement */
|
|
|
|
typedef struct _cond_block
|
|
|
|
{
|
|
|
|
UDWORD numOffsets;
|
|
|
|
UDWORD *aOffsets; // Positions in the code that have to be
|
|
|
|
// replaced with the offset to the end of the
|
2006-11-16 06:30:29 -08:00
|
|
|
// conditional statement (for the jumps). - //TODO: change to INTERP_VAL - probbaly not necessary
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD size;
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode;
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD debugEntries; // Number of debugging entries in psDebug.
|
|
|
|
SCRIPT_DEBUG *psDebug; // Debugging info for the script.
|
|
|
|
} COND_BLOCK;
|
|
|
|
|
|
|
|
/* The possible access types for a type */
|
|
|
|
typedef enum _access_type
|
|
|
|
{
|
|
|
|
AT_SIMPLE, // The type represents a simple data value
|
|
|
|
AT_OBJECT, // The type represents an object
|
|
|
|
} ACCESS_TYPE;
|
|
|
|
|
|
|
|
|
|
|
|
// function pointer for script variable saving
|
|
|
|
// if pBuffer is NULL the script system is just asking how much space the saved variable will require
|
|
|
|
// otherwise pBuffer points to an array to store the value in
|
2006-11-24 17:26:05 -08:00
|
|
|
typedef BOOL (*SCR_VAL_SAVE)(INTERP_VAL *psVal, char *pBuffer, UDWORD *pSize);
|
2007-06-28 10:47:08 -07:00
|
|
|
// function pointer for script variable loading
|
2006-11-24 17:26:05 -08:00
|
|
|
typedef BOOL (*SCR_VAL_LOAD)(SDWORD version, INTERP_VAL *psVal, char *pBuffer, UDWORD size);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Type for a user type symbol */
|
|
|
|
typedef struct _type_symbol
|
|
|
|
{
|
2006-11-26 05:45:04 -08:00
|
|
|
const char *pIdent; // Type identifier
|
2006-09-17 13:39:25 -07:00
|
|
|
INTERP_TYPE typeID; // The type id to use in the type field of values
|
2007-06-28 10:47:08 -07:00
|
|
|
SWORD accessType; // Whether the type is an object or a simple value
|
|
|
|
SCR_VAL_SAVE saveFunc; // load and save functions
|
2006-11-26 05:45:04 -08:00
|
|
|
SCR_VAL_LOAD loadFunc; //
|
2007-06-28 10:47:08 -07:00
|
|
|
} TYPE_SYMBOL;
|
|
|
|
|
|
|
|
/* Type for a variable identifier declaration */
|
|
|
|
typedef struct _var_ident_decl
|
|
|
|
{
|
2006-11-03 13:35:50 -08:00
|
|
|
char *pIdent; // variable identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
SDWORD dimensions; // number of dimensions of an array - 0 for normal var
|
2006-11-26 05:45:04 -08:00
|
|
|
SDWORD elements[VAR_MAX_DIMENSIONS]; // number of elements in an array
|
2007-06-28 10:47:08 -07:00
|
|
|
} VAR_IDENT_DECL;
|
|
|
|
|
|
|
|
/* Type for a variable symbol */
|
|
|
|
typedef struct _var_symbol
|
|
|
|
{
|
2006-11-03 13:35:50 -08:00
|
|
|
char *pIdent; // variable's identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
INTERP_TYPE type; // variable type
|
|
|
|
STORAGE_TYPE storage; // Where the variable is stored
|
|
|
|
INTERP_TYPE objType; // The object type if this is an object variable
|
|
|
|
UDWORD index; // Index of the variable in its data space
|
|
|
|
SCRIPT_VARFUNC get, set; // Access functions if the variable is stored in an object/in-game
|
|
|
|
SDWORD dimensions; // number of dimensions of an array - 0 for normal var
|
2006-11-26 05:45:04 -08:00
|
|
|
SDWORD elements[VAR_MAX_DIMENSIONS]; // number of elements in an array
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
struct _var_symbol *psNext;
|
|
|
|
} VAR_SYMBOL;
|
|
|
|
|
|
|
|
|
|
|
|
/* Type for an array access block */
|
|
|
|
typedef struct _array_block
|
|
|
|
{
|
|
|
|
VAR_SYMBOL *psArrayVar;
|
|
|
|
SDWORD dimensions;
|
|
|
|
|
|
|
|
UDWORD size;
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode;
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD debugEntries; // Number of debugging entries in psDebug.
|
|
|
|
SCRIPT_DEBUG *psDebug; // Debugging info for the script.
|
|
|
|
} ARRAY_BLOCK;
|
|
|
|
|
|
|
|
/* Type for a constant symbol */
|
|
|
|
typedef struct _const_symbol
|
|
|
|
{
|
2006-11-26 05:45:04 -08:00
|
|
|
const char *pIdent; // variable's identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
INTERP_TYPE type; // variable type
|
|
|
|
|
2006-11-26 05:45:04 -08:00
|
|
|
/* The actual value of the constant.
|
2007-06-28 10:47:08 -07:00
|
|
|
* Only one of these will be valid depending on type.
|
|
|
|
* A union is not used as a union cannot be statically initialised
|
|
|
|
*/
|
|
|
|
BOOL bval;
|
|
|
|
SDWORD ival;
|
|
|
|
void *oval;
|
2006-11-03 13:35:50 -08:00
|
|
|
char *sval; //String values
|
2006-11-16 06:30:29 -08:00
|
|
|
float fval;
|
2007-06-28 10:47:08 -07:00
|
|
|
} CONST_SYMBOL;
|
|
|
|
|
|
|
|
/* The chunk of code used to reference an object variable */
|
|
|
|
typedef struct _objvar_block
|
|
|
|
{
|
|
|
|
VAR_SYMBOL *psObjVar; // The object variables symbol
|
|
|
|
|
|
|
|
UDWORD size;
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode; // The code to get the object value on the stack
|
2007-06-28 10:47:08 -07:00
|
|
|
} OBJVAR_BLOCK;
|
|
|
|
|
|
|
|
/* The maximum number of parameters for an instinct function */
|
|
|
|
#define INST_MAXPARAMS 20
|
|
|
|
|
|
|
|
/* Type for a function symbol */
|
|
|
|
typedef struct _func_symbol
|
|
|
|
{
|
2006-11-03 13:35:50 -08:00
|
|
|
char *pIdent; // function's identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
SCRIPT_FUNC pFunc; // Pointer to the instinct function
|
|
|
|
INTERP_TYPE type; // function type
|
|
|
|
UDWORD numParams; // Number of parameters to the function
|
|
|
|
INTERP_TYPE aParams[INST_MAXPARAMS];
|
|
|
|
// List of parameter types
|
|
|
|
BOOL script; // Whether the function is defined in the script
|
|
|
|
// or a C instinct function
|
|
|
|
UDWORD size; // The size of script code
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode; // The code for a function if it is defined in the script
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD location; // The position of the function in the final code block
|
|
|
|
UDWORD debugEntries; // Number of debugging entries in psDebug.
|
|
|
|
SCRIPT_DEBUG *psDebug; // Debugging info for the script.
|
|
|
|
|
|
|
|
struct _func_symbol *psNext;
|
|
|
|
} FUNC_SYMBOL;
|
|
|
|
|
|
|
|
/* The type for a variable declaration */
|
|
|
|
typedef struct _var_decl
|
|
|
|
{
|
|
|
|
INTERP_TYPE type;
|
|
|
|
STORAGE_TYPE storage;
|
|
|
|
} VAR_DECL;
|
|
|
|
|
|
|
|
/* The type for a trigger sub declaration */
|
|
|
|
typedef struct _trigger_decl
|
|
|
|
{
|
|
|
|
TRIGGER_TYPE type;
|
|
|
|
UDWORD size;
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode;
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD time;
|
|
|
|
} TRIGGER_DECL;
|
|
|
|
|
|
|
|
/* Type for a trigger symbol */
|
|
|
|
typedef struct _trigger_symbol
|
|
|
|
{
|
2006-11-03 13:35:50 -08:00
|
|
|
char *pIdent; // Trigger's identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD index; // The triggers index number
|
|
|
|
TRIGGER_TYPE type; // Trigger type
|
|
|
|
UDWORD size; // Code size for the trigger
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode; // The trigger code
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD time; // How often to check the trigger
|
|
|
|
|
|
|
|
UDWORD debugEntries;
|
|
|
|
SCRIPT_DEBUG *psDebug;
|
|
|
|
|
|
|
|
struct _trigger_symbol *psNext;
|
|
|
|
} TRIGGER_SYMBOL;
|
|
|
|
|
|
|
|
/* The type for a callback trigger symbol */
|
|
|
|
typedef struct _callback_symbol
|
|
|
|
{
|
2006-11-26 05:45:04 -08:00
|
|
|
const char *pIdent; // Callback identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
TRIGGER_TYPE type; // user defined callback id >= TR_CALLBACKSTART
|
|
|
|
SCRIPT_FUNC pFunc; // Pointer to the instinct function
|
|
|
|
UDWORD numParams; // Number of parameters to the function
|
|
|
|
INTERP_TYPE aParams[INST_MAXPARAMS];
|
|
|
|
// List of parameter types
|
|
|
|
} CALLBACK_SYMBOL;
|
|
|
|
|
|
|
|
|
|
|
|
/* Type for an event symbol */
|
|
|
|
typedef struct _event_symbol
|
|
|
|
{
|
2006-11-03 13:35:50 -08:00
|
|
|
char *pIdent; // Event's identifier
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD index; // the events index number
|
|
|
|
UDWORD size; // Code size for the event
|
2006-11-16 06:30:29 -08:00
|
|
|
INTERP_VAL *pCode; // Event code
|
2007-06-28 10:47:08 -07:00
|
|
|
SDWORD trigger; // Index of the event's trigger
|
|
|
|
|
|
|
|
UDWORD debugEntries;
|
|
|
|
SCRIPT_DEBUG *psDebug;
|
|
|
|
|
2006-08-12 03:02:59 -07:00
|
|
|
//functions stuff
|
|
|
|
UDWORD numParams; //Number of parameters to the function
|
|
|
|
UDWORD numLocalVars; //local variables
|
|
|
|
BOOL bFunction; //if this event is defined as a function
|
|
|
|
BOOL bDeclared; //if function was declared before
|
|
|
|
INTERP_TYPE retType; //return type if a function
|
|
|
|
|
|
|
|
INTERP_TYPE aParams[INST_MAXPARAMS];
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
struct _event_symbol *psNext;
|
|
|
|
} EVENT_SYMBOL;
|
|
|
|
|
|
|
|
/* The table of user types */
|
|
|
|
extern TYPE_SYMBOL *asScrTypeTab;
|
|
|
|
|
|
|
|
/* The table of external variables and their access functions */
|
|
|
|
extern VAR_SYMBOL *asScrExternalTab;
|
|
|
|
|
|
|
|
/* The table of object variable access routines */
|
|
|
|
extern VAR_SYMBOL *asScrObjectVarTab;
|
|
|
|
|
|
|
|
/* The table of instinct function type definitions */
|
|
|
|
extern FUNC_SYMBOL *asScrInstinctTab;
|
|
|
|
|
|
|
|
/* The table of constant variables */
|
|
|
|
extern CONST_SYMBOL *asScrConstantTab;
|
|
|
|
|
|
|
|
/* The table of callback triggers */
|
|
|
|
extern CALLBACK_SYMBOL *asScrCallbackTab;
|
|
|
|
|
2007-10-05 15:44:18 -07:00
|
|
|
/* Set the current input file for the lexer */
|
|
|
|
extern void scriptSetInputFile(PHYSFS_file* fileHandle);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Initialise the parser ready for a new script */
|
|
|
|
extern BOOL scriptInitParser(void);
|
|
|
|
|
|
|
|
/* Set off the scenario file parser */
|
|
|
|
extern int scr_parse(void);
|
|
|
|
|
|
|
|
/* Give an error message */
|
2006-09-13 02:09:05 -07:00
|
|
|
void scr_error(const char *pMessage, ...);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
extern void scriptGetErrorData(int *pLine, char **ppText);
|
|
|
|
|
|
|
|
/* Look up a type symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpType(const char *pIdent, INTERP_TYPE *pType);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Add a new variable symbol */
|
|
|
|
extern BOOL scriptAddVariable(VAR_DECL *psStorage, VAR_IDENT_DECL *psVarIdent);
|
|
|
|
|
|
|
|
/* Add a new trigger symbol */
|
2006-11-03 13:35:50 -08:00
|
|
|
extern BOOL scriptAddTrigger(const char *pIdent, TRIGGER_DECL *psDecl, UDWORD line);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Add a new event symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptDeclareEvent(const char *pIdent, EVENT_SYMBOL **ppsEvent, SDWORD numArgs);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// Add the code to a defined event
|
|
|
|
extern BOOL scriptDefineEvent(EVENT_SYMBOL *psEvent, CODE_BLOCK *psCode, SDWORD trigger);
|
|
|
|
|
|
|
|
/* Look up a variable symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpVariable(const char *pIdent, VAR_SYMBOL **ppsSym);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Look up a constant variable symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpConstant(const char *pIdent, CONST_SYMBOL **ppsSym);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Lookup a trigger symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpTrigger(const char *pIdent, TRIGGER_SYMBOL **ppsTrigger);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Lookup a callback trigger symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpCallback(const char *pIdent, CALLBACK_SYMBOL **ppsCallback);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Lookup an event symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpEvent(const char *pIdent, EVENT_SYMBOL **ppsEvent);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* Reset the local variable symbol table */
|
|
|
|
extern void scriptClearLocalVariables(void);
|
|
|
|
|
|
|
|
/* Add a new function symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptStartFunctionDef(const char *pIdent, // Functions name
|
2007-06-28 10:47:08 -07:00
|
|
|
INTERP_TYPE type); // return type
|
|
|
|
|
|
|
|
/* Store the parameter types for the current script function definition */
|
|
|
|
extern BOOL scriptSetParameters(UDWORD numParams, // number of parameters
|
|
|
|
INTERP_TYPE *pParams); // parameter types
|
|
|
|
|
|
|
|
/* Store the code for a script function definition.
|
|
|
|
* Clean up the local variable list for this function definition.
|
|
|
|
*/
|
|
|
|
extern BOOL scriptSetCode(CODE_BLOCK *psBlock); // The code block
|
|
|
|
|
|
|
|
/* Look up a function symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpFunction(const char *pIdent, FUNC_SYMBOL **ppsSym);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-08-15 11:38:51 -07:00
|
|
|
/* Look up an in-script custom function symbol */
|
2006-11-26 05:45:04 -08:00
|
|
|
extern BOOL scriptLookUpCustomFunction(const char *pIdent, EVENT_SYMBOL **ppsSym);
|
2006-08-15 11:38:51 -07:00
|
|
|
|
2006-11-16 06:30:29 -08:00
|
|
|
extern BOOL popArguments(INTERP_VAL **ip_temp, SDWORD numParams);
|
2006-08-19 06:26:11 -07:00
|
|
|
|
2007-04-09 07:41:22 -07:00
|
|
|
extern void widgCopyString(char *pDest, const char *pSrc); // FIXME Duplicate declaration of internal widget function
|
2006-08-19 06:26:11 -07:00
|
|
|
|
2006-11-16 06:30:29 -08:00
|
|
|
extern void script_debug(const char *pFormat, ...);
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
#endif
|
|
|
|
|
2006-11-16 06:30:29 -08:00
|
|
|
|