Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Generic String Parser


Files

file  toyparse.c
 Implementations for generic tokenizer routines.

file  toyparse.h
 A simple text tokeniser/interpreter borrowed from my school project.


Classes

struct  TokenType
 A structure defining the type and subtype of a token. More...


Defines

#define TYPE_ENDOPEN   0xffff
 Denotes an open-ended syntax check.

#define TYPE_ENDCLOSE   0xfffe
 Denotes a strict syntax-check, last argument MUST be the last.


Typedefs

typedef TokenType TokenType
 A structure defining the type and subtype of a token.


Functions

void FreeType (TokenType *types)
 Frees an array of token-types and everything it contains.

TokenTypeLineToTypes (const char *str, const char **table[])
 Converts a line of text to an array of token-types.

int DetermineType (const char *str, const char **table[])
 Determines the root type of a token.

int DetermineSubType (int type, const char *str, const char **args[])
 Determines the sub-type from a known type.

int CheckLineSyntax (TokenType *tarray,...)
 Define PRINT_COMMENTS to print comments at runtime. Used for debugging. A generalized function to check the syntax of an array of token types.


Detailed Description

How the parser works:

At the root of it all, is the command table. It contains a list of pointers; each pointer points to a list of strings. Both the table and each list in it are NULL-terminated. The strings denote valid commands or valid command forms. For instance, say you have the root category of 'value'. Being the first thing in the command table, it would be at index 0, and point to a list of strings, like { "#%d","\"s",NULL }; d means accept any sequence of numbers in that spot, s means accept any integer values in that spot. So both "#100" and "\"Hello" would be accepted as valid commands. "#100" would be subcommand 0, while "\"Hello" would be subcommand 1.


Typedef Documentation

typedef struct TokenType TokenType
 

When used in arrays, if token==NULL that is the last element.


Function Documentation

int CheckLineSyntax TokenType tarray,
... 
 

Used like: CheckLineSyntax(tokens,TYPE_COMMAND,-1,TYPE_ENDOPEN);

This means that the first token can be any kind of command, and that more arguments may come after it.

Returns 0 on success, -1 on bad syntax.

Definition at line 41 of file toyparse.c.

References TokenType::subtype, TokenType::token, TokenType::type, TYPE_ENDCLOSE, and TYPE_ENDOPEN.

Referenced by SpriteLoader::ProcessLine().

int DetermineSubType int  type,
const char *  str,
const char **  args[]
 

Returns the array sub-index on success, -1 on failure.

Definition at line 190 of file toyparse.c.

References FindInList().

Referenced by TokensToType().

Here is the call graph for this function:

int DetermineType const char *  str,
const char **  table[]
 

Returns the root array index on success, -1 on failure.

Definition at line 219 of file toyparse.c.

References FindInList().

Referenced by TokensToType().

Here is the call graph for this function:

void FreeType TokenType types  ) 
 

Returns no values.

Definition at line 125 of file toyparse.c.

References TokenType::token.

TokenType* LineToTypes const char *  str,
const char **  table[]
 

Returns a tokentype array on success, NULL on failure.

Definition at line 96 of file toyparse.c.

References Explode(), and TokensToType().

Referenced by SpriteLoader::ProcessLine().

Here is the call graph for this function:


Generated on Sat Oct 11 13:19:41 2003 for Spritelib by doxygen 1.3.4