92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
#ifndef SCANNER_H
|
|
#define SCANNER_H
|
|
|
|
#include <sys/types.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
EMPTY
|
|
#ifndef __cplusplus
|
|
, STRING, FLOAT, INT, OPERATOR, LIDENT, FIDENT, LOCATION, FUNCALL, EEK
|
|
#endif
|
|
} Type;
|
|
|
|
#define MAX_TYPE_NAME_LENGTH 16
|
|
extern const char *Type_Name[];
|
|
|
|
typedef enum
|
|
{
|
|
PLUS, MINUS, MUL, DIV, OP, CP, COMMA,
|
|
LT, /* MUST be the first relational operation for parsing to work */
|
|
LE, GE, GT, ISEQUAL, ABOUTEQ,
|
|
NE, /* MUST be the last relational operation for parsing to work */
|
|
POW, MOD
|
|
} Operator;
|
|
|
|
#define MAX_OP_NAME_LENGTH 3
|
|
extern const char *Op_Name[];
|
|
|
|
typedef int Location[3]; /* NOTE: Locations are passed by REFERENCE not value */
|
|
/* I.e., to accapt a Location argument, declare the parameter to be of type
|
|
const Location*
|
|
*/
|
|
|
|
typedef enum { X=0, Y=1, Z=2, HYPER} Dimensions;
|
|
|
|
#define OLOCATION(loc) ((void)memset(loc, 0, sizeof(Location)))
|
|
#define IN_OCTANT(loc) (loc[X]>=0 && loc[Y]>=0 && loc[Z]>=0)
|
|
#define LOCATION_GETS(la,lb) ((void)memcpy(la, lb, sizeof(Location)))
|
|
#define SAME_LOC(la,lb) (memcmp(la,lb,sizeof(Location))==0)
|
|
#define LOCATION_SUB(la,lb) (la)[X]-=(lb)[X]; (la)[Y]-=(lb)[Y]; (la)[Z]-=(lb)[Z];
|
|
#define LOCATION_ADD(la,lb) (la)[X]+=(lb)[X]; (la)[Y]+=(lb)[Y]; (la)[Z]+=(lb)[Z];
|
|
|
|
bool loc_in_box(const Location test,
|
|
const Location b, const Location c);
|
|
|
|
typedef struct Token_struc Token;
|
|
|
|
typedef struct
|
|
{
|
|
int fident;
|
|
int argc;
|
|
Token *argv;
|
|
} FunctionCall;
|
|
|
|
typedef struct Token_struc
|
|
{
|
|
Type type;
|
|
union
|
|
{
|
|
char *string;
|
|
double flt;
|
|
long integer;
|
|
Operator op;
|
|
char *lident;
|
|
int fident;
|
|
Location location;
|
|
FunctionCall funcall;
|
|
char *err;
|
|
} u;
|
|
} Token;
|
|
|
|
#define NULLTOKEN ((Token*)0)
|
|
#define EMPTY_TVEC ((Token**)0)
|
|
|
|
int identcode(const char *s, size_t len);
|
|
void duperror(Token* tok, const char* erro);
|
|
Token **scan(const char **s);
|
|
size_t printtok(char *dest, size_t size, size_t field_width,
|
|
int quote_strings, int use_scientific,
|
|
int precision, int verbose_error, const Token *tok);
|
|
void print(char *s, size_t size, size_t chars, int quote, int scientific, int precision, Token **n);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|