mirror of
https://github.com/UberGames/rpgxEF.git
synced 2024-11-10 07:11:34 +00:00
Added flex based lexer
- not ready to be used yet as not added to Makefile yet - reentrant so it could be used for parrallel lexing
This commit is contained in:
parent
9b0c16d7ba
commit
0a6b8f9e41
5 changed files with 3635 additions and 33 deletions
|
@ -1,43 +1,124 @@
|
|||
#ifndef G_LEX_H_
|
||||
#define G_LEX_H_
|
||||
#ifndef BG_LEX_H
|
||||
#define BG_LEX_H
|
||||
|
||||
#include "q_shared.h"
|
||||
|
||||
typedef enum {
|
||||
MTYPE_VECTOR,
|
||||
MTYPE_NUMBER,
|
||||
MTYPE_STRING,
|
||||
MTYPE_KEYWORD,
|
||||
MTYPE_BRACE_OPEN,
|
||||
MTYPE_BRACE_CLOSE,
|
||||
MTYPE_SQBRACE_OPEN,
|
||||
MTYPE_SQBRACE_CLOSE,
|
||||
MTYPE_CUBRACE_OPEN,
|
||||
MTYPE_CUBRACE_CLOSE,
|
||||
MTYPE_MAX
|
||||
} morphType;
|
||||
LSYM_OBRACE, /* ( */
|
||||
LSYM_OBRACEC, /* { */
|
||||
LSYM_OBRACESQ, /* [ */
|
||||
LSYM_CBRACE, /* ) */
|
||||
LSYM_CBRACEC, /* } */
|
||||
LSYM_CBRACESQ, /* ] */
|
||||
LSYM_SERVER_CHANGE_CONFIG,
|
||||
LSYM_SERVER,
|
||||
LSYM_HOLODECK_DATA,
|
||||
LSYM_PROGRAM,
|
||||
LSYM_MAP_CHANGE_CONFIG,
|
||||
LSYM_MAP,
|
||||
LSYM_LOCATIONS_LIST,
|
||||
LSYM_LOCATIONS_LIST_2,
|
||||
LSYM_MESSAGE,
|
||||
LSYM_CONSOLE_NAME,
|
||||
LSYM_FORMAL_NAME,
|
||||
LSYM_RADAR_COLOR,
|
||||
LSYM_ICON_COLOR,
|
||||
LSYM_NULL,
|
||||
LSYM_MODEL_SKIN,
|
||||
LSYM_WEAPONS,
|
||||
LSYM_HAS_RANKS,
|
||||
LSYM_TEAL,
|
||||
LSYM_MEDICAL,
|
||||
LSYM_GOLD,
|
||||
LSYM_GREEN,
|
||||
LSYM_MARINE,
|
||||
LSYM_RED,
|
||||
LSYM_WP_NULL,
|
||||
LSYM_WP_NULL_HANDS,
|
||||
LSYM_WP_TRICORDER,
|
||||
LSYM_WP_PADD,
|
||||
LSYM_WP_COFFEE,
|
||||
LSYM_WP_PHASER,
|
||||
LSYM_WP_COMPRESSION_RIFLE,
|
||||
LSYM_WP_TR116,
|
||||
LSYM_WP_GRENADE_LAUNCHER,
|
||||
LSYM_WP_QUANTUM_BURST,
|
||||
LSYM_WP_MEDKIT,
|
||||
LSYM_WP_DISRUPTOR,
|
||||
LSYM_WP_VOYAGER_HYPO,
|
||||
LSYM_WP_DERMAL_REGEN,
|
||||
LSYM_WP_TOOLKIT,
|
||||
LSYM_WP_HYPERSPANNER,
|
||||
LSYM_WP_0,
|
||||
LSYM_WP_1,
|
||||
LSYM_WP_2,
|
||||
LSYM_WP_3,
|
||||
LSYM_WP_4,
|
||||
LSYM_WP_5,
|
||||
LSYM_WP_6,
|
||||
LSYM_WP_7,
|
||||
LSYM_WP_8,
|
||||
LSYM_WP_9,
|
||||
LSYM_WP_10,
|
||||
LSYM_WP_11,
|
||||
LSYM_WP_12,
|
||||
LSYM_WP_13,
|
||||
LSYM_WP_14,
|
||||
LSYM_WP_15,
|
||||
LSYM_ADMIN,
|
||||
LSYM_BORG,
|
||||
LSYM_N00B,
|
||||
LSYM_NO_SHOW,
|
||||
LSYM_MENU_TEXTURE_DEF,
|
||||
LSYM_MENU_TEXTURE_RED,
|
||||
LSYM_MENU_TEXTURE_TEAL,
|
||||
LSYM_MENU_TEXTURE_GOLD,
|
||||
LSYM_MENU_TEXTURE_GREEN,
|
||||
LSYM_BOLT_MODEL,
|
||||
LSYM_BOLT_SHADER,
|
||||
LSYM_ADMIRAL_RANK,
|
||||
|
||||
LSYM_UNKNOWN
|
||||
} bgLexSymbol;
|
||||
|
||||
typedef struct morph_s morph_t;
|
||||
struct morph_s {
|
||||
morphType type;
|
||||
union val
|
||||
{
|
||||
vec3_t vector;
|
||||
double number;
|
||||
char* string;
|
||||
char* keyword;
|
||||
} value;
|
||||
typedef enum {
|
||||
LMT_STRING,
|
||||
LMT_INT,
|
||||
LMT_DOUBLE,
|
||||
LMT_VECTOR3,
|
||||
LMT_VECTOR4,
|
||||
LMT_SYMBOL,
|
||||
LMT_IGNORE
|
||||
} bgLexMorphemType;
|
||||
|
||||
typedef struct bgLexMorphem_s bgLexMorphem;
|
||||
struct bgLexMorphem_s {
|
||||
bgLexMorphemType type;
|
||||
union {
|
||||
char* string;
|
||||
bgLexSymbol symbol;
|
||||
int numInteger;
|
||||
double numDouble;
|
||||
vec3_t vector3;
|
||||
vec4_t vector4;
|
||||
} data;
|
||||
int line;
|
||||
int column;
|
||||
};
|
||||
|
||||
typedef struct lex_s lex_t;
|
||||
struct lex_s {
|
||||
void* yylex;
|
||||
morph_t morph;
|
||||
typedef struct bgLex_s bgLex;
|
||||
struct bgLex_s {
|
||||
int line;
|
||||
int column;
|
||||
void* lex;
|
||||
bgLexMorphem morphem;
|
||||
void* buf;
|
||||
};
|
||||
|
||||
extern lex_t* lex_create(void);
|
||||
extern morphType lex(lex_t* lexer);
|
||||
|
||||
|
||||
#endif /* G_LEX_H_ */
|
||||
bgLex* bgLex_create(char* data);
|
||||
void bgLex_destroy(bgLex* lex);
|
||||
int bgLex_lex(bgLex* lex);
|
||||
bgLexSymbol bgLex_textToSymbol(char* text);
|
||||
void bgLexFatalError(const char* msg, void* lex);
|
||||
|
||||
#endif /* BG_LEX_H */
|
686
code/game/bg_lex.lex
Normal file
686
code/game/bg_lex.lex
Normal file
|
@ -0,0 +1,686 @@
|
|||
%top {
|
||||
#include "q_shared.h"
|
||||
#include "bg_lex.h"
|
||||
|
||||
#define YY_FATAL_ERROR(msg) bgLexFatalError(msg, yyscanner)
|
||||
}
|
||||
|
||||
DIGIT [0-9]
|
||||
INT {DIGIT}+
|
||||
DOUBLE {DIGIT}+"."?{DIGIT}*
|
||||
KEYWORD [a-zA-Z]+[a-zA-Z0-9]*
|
||||
|
||||
%option reentrant
|
||||
%option extra-type="bgLexMorphem*"
|
||||
|
||||
%%
|
||||
\"[^\"]*\" {
|
||||
yyextra->type = LMT_STRING;
|
||||
yyextra->data.string = yytext;
|
||||
yyextra->column += strlen(yytext);
|
||||
return 1;
|
||||
}
|
||||
{INT} {
|
||||
yyextra->type = LMT_INT;
|
||||
yyextra->data.numInteger = atoi(yytext);
|
||||
yyextra->column += strlen(yytext);
|
||||
return 1;
|
||||
}
|
||||
{DOUBLE} {
|
||||
yyextra->type = LMT_DOUBLE;
|
||||
yyextra->data.numDouble = atof(yytext);
|
||||
yyextra->column += strlen(yytext);
|
||||
return 1;
|
||||
}
|
||||
{KEYWORD} {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = bgLex_textToSymbol(yytext);
|
||||
yyextra->column += strlen(yytext);
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
|
||||
"{"" "+{INT}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c;
|
||||
sscanf(yytext, "{ %f %f %f }", &a, &b, &c);
|
||||
yyextra->data.vector3[0] = a;
|
||||
yyextra->data.vector3[1] = b;
|
||||
yyextra->data.vector3[2] = c;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR3;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{INT}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{INT}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{INT}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{INT}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{INT}" "+{DOUBLE}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{INT}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{INT}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{INT}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{DOUBLE}" "+{INT}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{"" "+{DOUBLE}" "+{DOUBLE}" "+{DOUBLE}" "+{DOUBLE}" "+"}" {
|
||||
double a, b, c, d;
|
||||
sscanf(yytext, "{ %f %f %f %f }", &a, &b, &c, &d);
|
||||
yyextra->data.vector4[0] = a;
|
||||
yyextra->data.vector4[1] = b;
|
||||
yyextra->data.vector4[2] = c;
|
||||
yyextra->data.vector4[3] = d;
|
||||
yyextra->column += strlen(yytext);
|
||||
yyextra->type = LMT_VECTOR4;
|
||||
return 1;
|
||||
}
|
||||
"{" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_OBRACEC;
|
||||
yyextra->column++;
|
||||
return;
|
||||
}
|
||||
"}" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_CBRACEC;
|
||||
yyextra->column++;
|
||||
return 1;
|
||||
}
|
||||
"(" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_OBRACE;
|
||||
yyextra->column++;
|
||||
return 1;
|
||||
}
|
||||
")" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_CBRACE;
|
||||
yyextra->column++;
|
||||
return 1;
|
||||
}
|
||||
"[" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_OBRACESQ;
|
||||
yyextra->column++;
|
||||
return 1;
|
||||
}
|
||||
"]" {
|
||||
yyextra->type = LMT_SYMBOL;
|
||||
yyextra->data.symbol = LSYM_CBRACESQ;
|
||||
yyextra->column++;
|
||||
return 1;
|
||||
}
|
||||
[ \t] {
|
||||
yyextra->column++;
|
||||
yyextra->type = LMT_IGNORE;
|
||||
return 1;
|
||||
}
|
||||
\n {
|
||||
yyextra->line++;
|
||||
yyextra->type = LMT_IGNORE;
|
||||
return 1;
|
||||
}
|
||||
. {
|
||||
yyextra->column++;
|
||||
yyextra->type = LMT_IGNORE;
|
||||
return 1;
|
||||
}
|
||||
%%
|
||||
|
||||
#ifdef LEX_TEXT
|
||||
int main(int argc, char* argv[]) {
|
||||
char buff[4096];
|
||||
yyscan_t scanner;
|
||||
FILE* f;
|
||||
bgLex* lex;
|
||||
|
||||
f = fopen("test.txt", "r");
|
||||
fread(buff, 4096, 1, f);
|
||||
fclose(f);
|
||||
|
||||
lex = bgLex_create(buff);
|
||||
while(bgLex_lex(lex)) {
|
||||
printf("type=%i symbol=%i yytext=%s\n", lex->morphem.type, lex->morphem.data.symbol, yyget_text(lex->lex));
|
||||
}
|
||||
bgLex_destroy(lex);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
bgLex* bgLex_create(char* data) {
|
||||
bgLex* l = malloc(sizeof(bgLex));
|
||||
|
||||
if(l != NULL) {
|
||||
yylex_init_extra(&l->morphem, &l->lex);
|
||||
l->buf = yy_scan_string(data, l->lex);
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
void bgLex_destroy(bgLex* lex) {
|
||||
if(lex == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(lex->buf != NULL) {
|
||||
yy_delete_buffer(lex->buf, lex->lex);
|
||||
}
|
||||
|
||||
if(lex->lex != NULL) {
|
||||
yylex_destroy(lex->lex);
|
||||
}
|
||||
|
||||
free(lex);
|
||||
}
|
||||
|
||||
int bgLex_lex(bgLex* lex) {
|
||||
return yylex(lex->lex);
|
||||
}
|
||||
|
||||
bgLexSymbol bgLex_textToSymbol(char* text) {
|
||||
if(strcmp("ServerChangeConfig", text) == 0) {
|
||||
return LSYM_SERVER_CHANGE_CONFIG;
|
||||
}
|
||||
|
||||
if(strcmp("Server", text) == 0) {
|
||||
return LSYM_SERVER;
|
||||
}
|
||||
|
||||
if(strcmp("HolodeckData", text) == 0) {
|
||||
return LSYM_HOLODECK_DATA;
|
||||
}
|
||||
|
||||
if(strcmp("Program", text) == 0) {
|
||||
return LSYM_PROGRAM;
|
||||
}
|
||||
|
||||
if(strcmp("MapChangeConfig", text) == 0) {
|
||||
return LSYM_MAP_CHANGE_CONFIG;
|
||||
}
|
||||
|
||||
if(strcmp("Map", text) == 0) {
|
||||
return LSYM_MAP;
|
||||
}
|
||||
|
||||
if(strcmp("LocationsList2", text) == 0) {
|
||||
return LSYM_LOCATIONS_LIST_2;
|
||||
}
|
||||
|
||||
if(strcmp("LocationsList", text) == 0) {
|
||||
return LSYM_LOCATIONS_LIST;
|
||||
}
|
||||
|
||||
if(strcmp("message", text) == 0) {
|
||||
return LSYM_MESSAGE;
|
||||
}
|
||||
|
||||
if(strcmp("consoleName", text) == 0) {
|
||||
return LSYM_CONSOLE_NAME;
|
||||
}
|
||||
|
||||
if(strcmp("formalName", text) == 0) {
|
||||
return LSYM_FORMAL_NAME;
|
||||
}
|
||||
|
||||
if(strcmp("radarColor", text) == 0) {
|
||||
return LSYM_RADAR_COLOR;
|
||||
}
|
||||
|
||||
if(strcmp("iconColor", text) == 0) {
|
||||
return LSYM_ICON_COLOR;
|
||||
}
|
||||
|
||||
if(strcmp("NULL", text) == 0) {
|
||||
return LSYM_NULL;
|
||||
}
|
||||
|
||||
if(strcmp("modelSkin", text) == 0) {
|
||||
return LSYM_MODEL_SKIN;
|
||||
}
|
||||
|
||||
if(strcmp("weapons", text) == 0) {
|
||||
return LSYM_WEAPONS;
|
||||
}
|
||||
|
||||
if(strcmp("hasRanks", text) == 0) {
|
||||
return LSYM_HAS_RANKS;
|
||||
}
|
||||
|
||||
if(strcmp("teal", text) == 0) {
|
||||
return LSYM_TEAL;
|
||||
}
|
||||
|
||||
if(strcmp("medical", text) == 0) {
|
||||
return LSYM_MEDICAL;
|
||||
}
|
||||
|
||||
if(strcmp("gold", text) == 0) {
|
||||
return LSYM_GOLD;
|
||||
}
|
||||
|
||||
if(strcmp("green", text) == 0) {
|
||||
return LSYM_GREEN;
|
||||
}
|
||||
|
||||
if(strcmp("marine", text) == 0) {
|
||||
return LSYM_MARINE;
|
||||
}
|
||||
|
||||
if(strcmp("red", text) == 0) {
|
||||
return LSYM_RED;
|
||||
}
|
||||
|
||||
if(strcmp("WP_TRICORDER", text) == 0) {
|
||||
return LSYM_WP_TRICORDER;
|
||||
}
|
||||
|
||||
if(strcmp("WP_PADD", text) == 0) {
|
||||
return LSYM_WP_PADD;
|
||||
}
|
||||
|
||||
if(strcmp("WP_COFFEE", text) == 0) {
|
||||
return LSYM_WP_COFFEE;
|
||||
}
|
||||
|
||||
if(strcmp("WP_PHASER", text) == 0) {
|
||||
return LSYM_WP_PHASER;
|
||||
}
|
||||
|
||||
if(strcmp("WP_COMPRESSION_RIFLE", text) == 0) {
|
||||
return LSYM_WP_COMPRESSION_RIFLE;
|
||||
}
|
||||
|
||||
if(strcmp("WP_TR116", text) == 0) {
|
||||
return LSYM_WP_TR116;
|
||||
}
|
||||
|
||||
if(strcmp("WP_GRENADE_LAUNCHER", text) == 0) {
|
||||
return LSYM_WP_GRENADE_LAUNCHER;
|
||||
}
|
||||
|
||||
if(strcmp("WP_QUANTUM_BURST", text) == 0) {
|
||||
return LSYM_WP_QUANTUM_BURST;
|
||||
}
|
||||
|
||||
if(strcmp("WP_MEDKIT", text) == 0) {
|
||||
return LSYM_WP_MEDKIT;
|
||||
}
|
||||
|
||||
if(strcmp("WP_VOYAGER_HYPO", text) == 0) {
|
||||
return LSYM_WP_VOYAGER_HYPO;
|
||||
}
|
||||
|
||||
if(strcmp("WP_DERMAL_REGEN", text) == 0) {
|
||||
return LSYM_WP_DERMAL_REGEN;
|
||||
}
|
||||
|
||||
if(strcmp("WP_TOOLKIT", text) == 0) {
|
||||
return LSYM_WP_TOOLKIT;
|
||||
}
|
||||
|
||||
if(strcmp("WP_HYPERSPANNER", text) == 0) {
|
||||
return LSYM_WP_HYPERSPANNER;
|
||||
}
|
||||
|
||||
if(strcmp("WP_DISRUPTOR", text) == 0) {
|
||||
return LSYM_WP_DISRUPTOR;
|
||||
}
|
||||
|
||||
if(strcmp("WP_NULL", text) == 0) {
|
||||
return LSYM_WP_NULL;
|
||||
}
|
||||
|
||||
if(strcmp("WP_NULL_HANDS", text) == 0) {
|
||||
return LSYM_WP_NULL_HANDS;
|
||||
}
|
||||
|
||||
if(strcmp("WP_0", text) == 0) {
|
||||
return LSYM_WP_0;
|
||||
}
|
||||
|
||||
if(strcmp("WP_1", text) == 0) {
|
||||
return LSYM_WP_1;
|
||||
}
|
||||
|
||||
if(strcmp("WP_2", text) == 0) {
|
||||
return LSYM_WP_2;
|
||||
}
|
||||
|
||||
if(strcmp("WP_3", text) == 0) {
|
||||
return LSYM_WP_3;
|
||||
}
|
||||
|
||||
if(strcmp("WP_4", text) == 0) {
|
||||
return LSYM_WP_4;
|
||||
}
|
||||
|
||||
if(strcmp("WP_5", text) == 0) {
|
||||
return LSYM_WP_5;
|
||||
}
|
||||
|
||||
if(strcmp("WP_6", text) == 0) {
|
||||
return LSYM_WP_6;
|
||||
}
|
||||
|
||||
if(strcmp("WP_7", text) == 0) {
|
||||
return LSYM_WP_7;
|
||||
}
|
||||
|
||||
if(strcmp("WP_8", text) == 0) {
|
||||
return LSYM_WP_8;
|
||||
}
|
||||
|
||||
if(strcmp("WP_9", text) == 0) {
|
||||
return LSYM_WP_9;
|
||||
}
|
||||
|
||||
if(strcmp("WP_10", text) == 0) {
|
||||
return LSYM_WP_10;
|
||||
}
|
||||
|
||||
if(strcmp("WP_11", text) == 0) {
|
||||
return LSYM_WP_11;
|
||||
}
|
||||
|
||||
if(strcmp("WP_12", text) == 0) {
|
||||
return LSYM_WP_12;
|
||||
}
|
||||
|
||||
if(strcmp("WP_13", text) == 0) {
|
||||
return LSYM_WP_13;
|
||||
}
|
||||
|
||||
if(strcmp("WP_14", text) == 0) {
|
||||
return LSYM_WP_14;
|
||||
}
|
||||
|
||||
if(strcmp("WP_15", text) == 0) {
|
||||
return LSYM_WP_15;
|
||||
}
|
||||
|
||||
if(strcmp("admin", text) == 0) {
|
||||
return LSYM_ADMIN;
|
||||
}
|
||||
|
||||
if(strcmp("borg", text) == 0) {
|
||||
return LSYM_BORG;
|
||||
}
|
||||
|
||||
if(strcmp("n00b", text) == 0) {
|
||||
return LSYM_N00B;
|
||||
}
|
||||
|
||||
if(strcmp("noShow", text) == 0) {
|
||||
return LSYM_NO_SHOW;
|
||||
}
|
||||
|
||||
if(strcmp("MenuTextureDef", text) == 0) {
|
||||
return LSYM_MENU_TEXTURE_DEF;
|
||||
}
|
||||
|
||||
if(strcmp("ConsoleName", text) == 0) {
|
||||
return LSYM_CONSOLE_NAME;
|
||||
}
|
||||
|
||||
if(strcmp("FormalName", text) == 0) {
|
||||
return LSYM_FORMAL_NAME;
|
||||
}
|
||||
|
||||
if(strcmp("MenuTextureRed", text) == 0) {
|
||||
return LSYM_MENU_TEXTURE_RED;
|
||||
}
|
||||
|
||||
if(strcmp("MenuTextureTeal", text) == 0) {
|
||||
return LSYM_MENU_TEXTURE_TEAL;
|
||||
}
|
||||
|
||||
if(strcmp("MenuTextureGold", text) == 0) {
|
||||
return LSYM_MENU_TEXTURE_GOLD;
|
||||
}
|
||||
|
||||
if(strcmp("MenuTextureGreen", text) == 0) {
|
||||
return LSYM_MENU_TEXTURE_GREEN;
|
||||
}
|
||||
|
||||
if(strcmp("BoltModel", text) == 0) {
|
||||
return LSYM_BOLT_MODEL;
|
||||
}
|
||||
|
||||
if(strcmp("BoltShader", text) == 0) {
|
||||
return LSYM_BOLT_SHADER;
|
||||
}
|
||||
|
||||
if(strcmp("AdmiralRank", text) == 0) {
|
||||
return LSYM_ADMIRAL_RANK;
|
||||
}
|
||||
|
||||
return LSYM_UNKNOWN;
|
||||
}
|
||||
|
||||
void bgLexFatalError(const char* msg, void* lex) {
|
||||
Com_Printf("LEXER ERROR: %s\n", msg);
|
||||
}
|
||||
|
2827
code/game/bg_lex.yy.c
Normal file
2827
code/game/bg_lex.yy.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -199,6 +199,7 @@
|
|||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;_WINDOWS</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bg_lex.yy.c" />
|
||||
<ClCompile Include="bg_lib.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
|
@ -541,6 +542,7 @@
|
|||
<ClInclude Include="syn.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="bg_lex.lex" />
|
||||
<None Include="game.def" />
|
||||
<CustomBuildStep Include="g_syscalls.asm">
|
||||
<FileType>Document</FileType>
|
||||
|
|
|
@ -279,6 +279,9 @@
|
|||
<ClCompile Include="sqlite3.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="bg_lex.yy.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ai_chat.h">
|
||||
|
@ -475,6 +478,9 @@
|
|||
<None Include="game.def">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="bg_lex.lex">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuildStep Include="g_syscalls.asm" />
|
||||
|
|
Loading…
Reference in a new issue