2001-06-12 21:06:28 +00:00
|
|
|
%{
|
2001-09-28 07:09:38 +00:00
|
|
|
/*
|
2002-11-06 16:32:28 +00:00
|
|
|
qc-lex.l
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
lexer for quakec
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/06/12
|
2001-09-28 07:09:38 +00:00
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-14 20:18:29 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
#include <QF/dstring.h>
|
2001-06-13 07:16:39 +00:00
|
|
|
#include <QF/hash.h>
|
2001-10-24 22:50:06 +00:00
|
|
|
#include <QF/sys.h>
|
2002-06-27 22:48:28 +00:00
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
#include "qfcc.h"
|
2002-06-01 05:30:16 +00:00
|
|
|
#include "expr.h"
|
2002-05-22 01:39:07 +00:00
|
|
|
#include "class.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "immediate.h"
|
|
|
|
#include "options.h"
|
2001-12-08 08:19:48 +00:00
|
|
|
#include "struct.h"
|
2002-01-23 20:50:25 +00:00
|
|
|
#include "type.h"
|
2001-06-12 21:06:28 +00:00
|
|
|
#include "qc-parse.h"
|
|
|
|
|
2003-04-16 19:41:52 +00:00
|
|
|
#ifndef YY_PROTO
|
|
|
|
# define YY_PROTO(x) x
|
|
|
|
#else
|
|
|
|
# define YY_FLEX_REALLOC_HACK
|
|
|
|
#endif
|
|
|
|
int yyget_lineno (void);
|
|
|
|
FILE *yyget_in (void);
|
|
|
|
FILE *yyget_out (void);
|
|
|
|
int yyget_leng (void);
|
|
|
|
char *yyget_text (void);
|
|
|
|
void yyset_lineno (int line_number);
|
|
|
|
void yyset_in (FILE * in_str);
|
|
|
|
void yyset_out (FILE * out_str);
|
|
|
|
int yyget_debug (void);
|
|
|
|
void yyset_debug (int bdebug);
|
|
|
|
int yylex_destroy (void);
|
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
#define YY_NO_UNPUT
|
2003-01-06 18:28:13 +00:00
|
|
|
#define YY_DECL int yylex YY_PROTO(( void ))
|
|
|
|
YY_DECL;
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2003-04-16 19:41:52 +00:00
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
int type_or_name (char *token);
|
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
int do_grab (char *token);
|
|
|
|
|
|
|
|
void add_frame_macro (char *token);
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
const char *make_string (char *token);
|
2001-06-25 22:11:20 +00:00
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
extern YYSTYPE yylval;
|
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
DIGIT [0-9]
|
2002-10-26 03:23:19 +00:00
|
|
|
XDIGIT [0-9a-fA-F]
|
2001-06-12 21:06:28 +00:00
|
|
|
ID [a-zA-Z_][a-zA-Z_0-9]*
|
2001-06-13 07:16:39 +00:00
|
|
|
FLOAT {DIGIT}+"."{DIGIT}*
|
|
|
|
NUM ({DIGIT}+("."{DIGIT}*)?)
|
|
|
|
s [ \t]
|
|
|
|
m ([\-+]?)
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
%x grab_frame grab_other
|
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
%%
|
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
"/*" {
|
|
|
|
int c;
|
|
|
|
do {
|
|
|
|
while ((c = input ()) != '*' && c != EOF
|
|
|
|
&& c != '\n')
|
|
|
|
;
|
|
|
|
while (c == '*')
|
|
|
|
c = input ();
|
|
|
|
if (c == EOF)
|
2001-06-28 21:26:40 +00:00
|
|
|
error (0, "EOF in comment");
|
2001-06-13 07:16:39 +00:00
|
|
|
if (c == '\n')
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line++;
|
2001-06-13 07:16:39 +00:00
|
|
|
} while (c != '/' && c != EOF);
|
|
|
|
}
|
|
|
|
|
2001-06-27 20:47:41 +00:00
|
|
|
"//".* /* nothing to do */
|
2001-06-13 07:16:39 +00:00
|
|
|
|
|
|
|
{DIGIT}+ {
|
2001-07-23 01:31:22 +00:00
|
|
|
yylval.integer_val = atoi (yytext);
|
2001-06-13 07:16:39 +00:00
|
|
|
return INT_VAL;
|
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2002-10-26 03:41:10 +00:00
|
|
|
0[xX]{XDIGIT}+ {
|
2002-10-26 03:23:19 +00:00
|
|
|
const char *c = yytext + 2;
|
|
|
|
yylval.integer_val = 0;
|
|
|
|
while (*c) {
|
|
|
|
yylval.integer_val *= 16;
|
|
|
|
yylval.integer_val += *c - '0';
|
|
|
|
if (*c > '9')
|
|
|
|
yylval.integer_val -= 'A' - '9' - 1;
|
|
|
|
if (*c > 'F')
|
|
|
|
yylval.integer_val -= 'a' - 'A';
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
return INT_VAL;
|
|
|
|
}
|
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
{FLOAT}* {
|
|
|
|
yylval.float_val = atof (yytext);
|
|
|
|
return FLOAT_VAL;
|
|
|
|
}
|
2001-06-12 22:26:10 +00:00
|
|
|
|
2002-05-07 16:55:54 +00:00
|
|
|
{ID} return type_or_name(yytext);
|
|
|
|
@{ID} {
|
|
|
|
int tok = type_or_name(yytext);
|
|
|
|
if (tok == '@')
|
|
|
|
REJECT;
|
|
|
|
return tok;
|
|
|
|
}
|
|
|
|
@ return '@';
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2003-03-04 17:03:49 +00:00
|
|
|
\"(\\.|[^"\\])*\" {
|
2001-06-25 22:11:20 +00:00
|
|
|
yylval.string_val = make_string (yytext);
|
2001-06-13 07:16:39 +00:00
|
|
|
return STRING_VAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
2001-06-25 17:15:56 +00:00
|
|
|
sscanf (yytext, "' %f %f %f '",
|
|
|
|
&yylval.vector_val[0], &yylval.vector_val[1],
|
|
|
|
&yylval.vector_val[2]);
|
2001-06-13 07:16:39 +00:00
|
|
|
return VECTOR_VAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
2001-06-25 17:15:56 +00:00
|
|
|
sscanf (yytext, "' %f %f %f %f '",
|
2004-04-08 03:32:14 +00:00
|
|
|
&yylval.quaternion_val[0],
|
|
|
|
&yylval.quaternion_val[1],
|
|
|
|
&yylval.quaternion_val[2],
|
|
|
|
&yylval.quaternion_val[3]);
|
2002-01-04 08:45:24 +00:00
|
|
|
return QUATERNION_VAL;
|
|
|
|
}
|
|
|
|
|
2002-01-04 17:13:13 +00:00
|
|
|
'(\\[^xX0-7\r\n]|[^'\r\n]|\\[xX][0-9A-Fa-f]+|\\[0-7]+)*' {
|
2002-06-27 22:48:28 +00:00
|
|
|
const char *str = make_string (yytext);
|
2002-01-04 08:45:24 +00:00
|
|
|
|
|
|
|
if (str[1])
|
|
|
|
warning (0, "multibyte char constant");
|
|
|
|
yylval.integer_val = *str;
|
|
|
|
return INT_VAL;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
|
|
|
|
2004-05-09 02:12:49 +00:00
|
|
|
^{s}*#{s}*pragma.*$ /* skip */
|
|
|
|
|
2002-01-04 18:27:01 +00:00
|
|
|
^#{s}+{DIGIT}+{s}+\"(\.|[^"\n])*\".*$ {
|
2001-06-25 23:38:32 +00:00
|
|
|
char *p;
|
2002-01-04 18:27:01 +00:00
|
|
|
char *s;
|
2002-06-27 22:48:28 +00:00
|
|
|
const char *str;
|
2001-06-25 23:38:32 +00:00
|
|
|
int line;
|
|
|
|
|
2002-01-04 18:27:01 +00:00
|
|
|
p = yytext + 1;
|
|
|
|
line = strtol (p, &s, 10);
|
|
|
|
p = s;
|
2002-04-07 05:44:34 +00:00
|
|
|
while (isspace ((unsigned char)*p))
|
2002-01-04 18:27:01 +00:00
|
|
|
p++;
|
|
|
|
if (!*p)
|
2001-08-10 18:35:55 +00:00
|
|
|
error (0, "Unexpected end of file");
|
2002-06-27 22:48:28 +00:00
|
|
|
str = make_string (p); // grab the filename
|
2002-01-04 18:27:01 +00:00
|
|
|
while (*p && *p != '\n') // ignore flags
|
|
|
|
p++;
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line = line - 1;
|
|
|
|
pr.source_file = ReuseString (strip_path (str));
|
2001-06-13 18:35:41 +00:00
|
|
|
}
|
|
|
|
|
2001-08-20 06:22:28 +00:00
|
|
|
[+\-*/&|^%]= {
|
|
|
|
yylval.op = yytext[0];
|
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
|
|
|
"<<=" {
|
|
|
|
yylval.op = SHL;
|
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
|
|
|
">>=" {
|
|
|
|
yylval.op = SHR;
|
|
|
|
return ASX;
|
|
|
|
}
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
[!(){}.*/&|^~+\-=\[\];,#%?:] {
|
|
|
|
return yytext[0];
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2002-05-08 05:15:19 +00:00
|
|
|
"..." return ELLIPSIS;
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-08-10 16:17:00 +00:00
|
|
|
"<<" return SHL;
|
|
|
|
">>" return SHR;
|
|
|
|
|
2001-06-12 21:06:28 +00:00
|
|
|
"&&" return AND;
|
|
|
|
"||" return OR;
|
|
|
|
"==" return EQ;
|
|
|
|
"!=" return NE;
|
|
|
|
"<=" return LE;
|
|
|
|
">=" return GE;
|
|
|
|
"<" return LT;
|
|
|
|
">" return GT;
|
|
|
|
|
2001-08-20 06:22:28 +00:00
|
|
|
"++" {
|
|
|
|
yylval.op = '+';
|
|
|
|
return INCOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
"--" {
|
|
|
|
yylval.op = '-';
|
|
|
|
return INCOP;
|
|
|
|
}
|
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
"$"{s}*{ID} {
|
|
|
|
int ret = do_grab(yytext);
|
|
|
|
if (ret > 0)
|
2001-06-13 07:16:39 +00:00
|
|
|
return ret;
|
2001-06-13 18:35:41 +00:00
|
|
|
else
|
|
|
|
BEGIN (-ret);
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
<grab_frame>{ID} add_frame_macro (yytext);
|
|
|
|
|
2002-01-04 17:13:13 +00:00
|
|
|
<grab_other>[^\r\n]* /* skip */
|
2001-06-13 18:35:41 +00:00
|
|
|
|
2002-01-04 18:27:01 +00:00
|
|
|
<*>\r*\n {
|
2002-07-03 21:32:03 +00:00
|
|
|
pr.source_line++;
|
2001-06-13 18:35:41 +00:00
|
|
|
BEGIN (INITIAL);
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
2001-06-12 21:06:28 +00:00
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
<*>{s}* /* skip */
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2001-06-28 21:26:40 +00:00
|
|
|
<*>. error (0, "all your typo are belong to us");
|
2001-06-12 21:06:28 +00:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
int
|
|
|
|
yywrap (void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
int value;
|
|
|
|
type_t *type;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int traditional;
|
|
|
|
unsigned int version;
|
2001-06-13 07:16:39 +00:00
|
|
|
} keyword_t;
|
|
|
|
|
|
|
|
static keyword_t keywords[] = {
|
2002-02-18 06:23:59 +00:00
|
|
|
{"void", TYPE, &type_void, 1, PROG_ID_VERSION},
|
|
|
|
{"float", TYPE, &type_float, 1, PROG_ID_VERSION},
|
|
|
|
{"string", TYPE, &type_string, 1, PROG_ID_VERSION},
|
|
|
|
{"vector", TYPE, &type_vector, 1, PROG_ID_VERSION},
|
|
|
|
{"entity", TYPE, &type_entity, 1, PROG_ID_VERSION},
|
|
|
|
{"quaternion", TYPE, &type_quaternion, 0, PROG_VERSION},
|
|
|
|
{"integer", TYPE, &type_integer, 0, PROG_VERSION},
|
2003-07-26 21:07:51 +00:00
|
|
|
{"unsigned", TYPE, &type_uinteger, 0, PROG_VERSION},
|
2002-02-18 06:23:59 +00:00
|
|
|
{"function", TYPE, &type_function, 0, PROG_VERSION},
|
2002-05-09 06:37:40 +00:00
|
|
|
{"id", TYPE, &type_id, 0, PROG_VERSION},
|
2002-05-21 21:28:40 +00:00
|
|
|
{"Class", TYPE, &type_Class, 0, PROG_VERSION},
|
2004-11-11 00:34:00 +00:00
|
|
|
// {"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION},
|
2002-05-22 05:03:36 +00:00
|
|
|
{"Method", TYPE, &type_Method, 0, PROG_VERSION},
|
2003-05-15 05:58:31 +00:00
|
|
|
{"Super", TYPE, &type_Super, 0, PROG_VERSION},
|
2002-05-17 19:47:15 +00:00
|
|
|
{"SEL", TYPE, &type_SEL, 0, PROG_VERSION},
|
|
|
|
{"IMP", TYPE, &type_IMP, 0, PROG_VERSION},
|
2002-02-18 06:23:59 +00:00
|
|
|
{"local", LOCAL, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"return", RETURN, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"while", WHILE, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"do", DO, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"if", IF, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"else", ELSE, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"for", FOR, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"break", BREAK, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"continue", CONTINUE, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"switch", SWITCH, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"case", CASE, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"default", DEFAULT, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"NIL", NIL, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"struct", STRUCT, 0, 0, PROG_VERSION},
|
2002-06-20 20:28:01 +00:00
|
|
|
{"union", UNION, 0, 0, PROG_VERSION},
|
2002-02-18 06:23:59 +00:00
|
|
|
{"enum", ENUM, 0, 0, PROG_ID_VERSION},
|
|
|
|
{"typedef", TYPEDEF, 0, 0, PROG_ID_VERSION},
|
2002-05-17 19:47:15 +00:00
|
|
|
{"super", SUPER, 0, 0, PROG_VERSION},
|
2002-05-07 16:55:54 +00:00
|
|
|
|
|
|
|
{"@class", CLASS, 0, 0, PROG_VERSION},
|
|
|
|
{"@defs", DEFS, 0, 0, PROG_VERSION},
|
|
|
|
{"@encode", ENCODE, 0, 0, PROG_VERSION},
|
|
|
|
{"@end", END, 0, 0, PROG_VERSION},
|
|
|
|
{"@implementation", IMPLEMENTATION, 0, 0, PROG_VERSION},
|
|
|
|
{"@interface", INTERFACE, 0, 0, PROG_VERSION},
|
|
|
|
{"@private", PRIVATE, 0, 0, PROG_VERSION},
|
|
|
|
{"@protected", PROTECTED, 0, 0, PROG_VERSION},
|
|
|
|
{"@protocol", PROTOCOL, 0, 0, PROG_VERSION},
|
|
|
|
{"@public", PUBLIC, 0, 0, PROG_VERSION},
|
|
|
|
{"@selector", SELECTOR, 0, 0, PROG_VERSION},
|
2002-05-18 00:30:14 +00:00
|
|
|
{"@self", SELF, 0, 0, PROG_VERSION},
|
2002-05-31 16:58:42 +00:00
|
|
|
{"@this", THIS, 0, 0, PROG_VERSION},
|
2002-10-16 02:28:08 +00:00
|
|
|
{"@args", ARGS, 0, 0, PROG_VERSION},
|
2002-05-22 20:43:29 +00:00
|
|
|
{"@argc", ARGC, 0, 0, PROG_VERSION},
|
|
|
|
{"@argv", ARGV, 0, 0, PROG_VERSION},
|
2002-10-16 02:28:08 +00:00
|
|
|
{"@va_list", TYPE, &type_va_list, 0, PROG_VERSION},
|
2004-11-13 04:02:00 +00:00
|
|
|
{"@param", TYPE, &type_param, 0, PROG_VERSION},
|
2002-09-10 04:07:34 +00:00
|
|
|
{"@extern", EXTERN, 0, 1, PROG_ID_VERSION},
|
|
|
|
{"@static", STATIC, 0, 1, PROG_ID_VERSION},
|
2002-09-16 15:42:11 +00:00
|
|
|
{"@system", SYSTEM, 0, 1, PROG_ID_VERSION},
|
2002-08-18 04:08:02 +00:00
|
|
|
{"@sizeof", SIZEOF, 0, 0, PROG_VERSION},
|
2004-11-13 11:50:00 +00:00
|
|
|
{"@overload", OVERLOAD, 0, 0, PROG_VERSION},
|
2001-06-13 07:16:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
keyword_get_key (void *kw, void *unused)
|
|
|
|
{
|
|
|
|
return ((keyword_t*)kw)->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
type_or_name (char *token)
|
|
|
|
{
|
|
|
|
static hashtab_t *keyword_tab;
|
2001-12-08 08:19:48 +00:00
|
|
|
keyword_t *keyword;
|
2004-11-02 07:02:00 +00:00
|
|
|
typedef_t *typename;
|
2002-08-18 04:08:02 +00:00
|
|
|
class_t *class;
|
2001-06-13 07:16:39 +00:00
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
if (!keyword_tab) {
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2001-06-13 07:16:39 +00:00
|
|
|
keyword_tab = Hash_NewTable (1021, keyword_get_key, 0, 0);
|
|
|
|
for (i = 0; i < sizeof (keywords) / sizeof (keywords[0]); i++)
|
2002-02-18 06:23:59 +00:00
|
|
|
if (keywords[i].traditional >= options.traditional
|
|
|
|
&& keywords[i].version <= options.code.progsversion)
|
2001-08-07 16:50:22 +00:00
|
|
|
Hash_Add (keyword_tab, &keywords[i]);
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
|
|
|
keyword = Hash_Find (keyword_tab, token);
|
|
|
|
if (keyword) {
|
2004-01-21 21:43:31 +00:00
|
|
|
if (!options.traditional && token[0] == '@'
|
|
|
|
&& !class_Class.super_class)
|
2002-05-22 01:39:07 +00:00
|
|
|
class_init ();
|
2001-06-13 07:16:39 +00:00
|
|
|
yylval.type = keyword->type;
|
|
|
|
return keyword->value;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
if (token[0] == '@') {
|
|
|
|
return '@';
|
|
|
|
}
|
2004-11-02 07:02:00 +00:00
|
|
|
if ((typename = get_typedef (token))) {
|
|
|
|
yylval.typename = typename;
|
|
|
|
return TYPE_NAME;
|
2001-12-08 08:19:48 +00:00
|
|
|
}
|
2002-08-18 04:08:02 +00:00
|
|
|
if ((class = get_class (token, 0))) {
|
|
|
|
yylval.string_val = save_string (token);
|
|
|
|
return CLASS_NAME;
|
|
|
|
}
|
2002-06-27 22:48:28 +00:00
|
|
|
yylval.string_val = save_string (token);
|
2001-06-13 07:16:39 +00:00
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
static hashtab_t *frame_tab;
|
|
|
|
static hashtab_t *grab_tab;
|
|
|
|
|
2002-06-05 21:13:29 +00:00
|
|
|
typedef struct frame_s {
|
|
|
|
struct frame_s *next;
|
2001-06-13 18:35:41 +00:00
|
|
|
const char *name;
|
|
|
|
int num;
|
|
|
|
} frame_t;
|
|
|
|
|
2002-06-05 21:13:29 +00:00
|
|
|
static frame_t *free_frames;
|
|
|
|
|
2001-06-13 18:35:41 +00:00
|
|
|
static frame_t grab_list[] = {
|
2002-06-05 21:13:29 +00:00
|
|
|
{0, "cd", 0},
|
|
|
|
{0, "origin", 0},
|
|
|
|
{0, "base", 0},
|
|
|
|
{0, "flags", 0},
|
|
|
|
{0, "scale", 0},
|
|
|
|
{0, "skin", 0},
|
2001-06-13 18:35:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
frame_get_key (void *f, void *unused)
|
|
|
|
{
|
|
|
|
return ((frame_t*)f)->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-05 21:13:29 +00:00
|
|
|
frame_free (void *_f, void *unused)
|
2001-06-13 18:35:41 +00:00
|
|
|
{
|
2002-06-05 21:13:29 +00:00
|
|
|
frame_t *f = (frame_t *)_f;
|
|
|
|
f->next = free_frames;
|
|
|
|
free_frames = f;
|
2001-06-13 18:35:41 +00:00
|
|
|
}
|
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
int
|
2001-06-13 18:35:41 +00:00
|
|
|
do_grab (char *token)
|
2001-06-13 07:16:39 +00:00
|
|
|
{
|
|
|
|
static int initialized;
|
2001-06-13 18:35:41 +00:00
|
|
|
frame_t *frame;
|
2001-06-13 07:16:39 +00:00
|
|
|
|
|
|
|
if (!initialized) {
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int i;
|
2001-06-13 18:35:41 +00:00
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
initialized = 1;
|
2001-06-13 18:35:41 +00:00
|
|
|
frame_tab = Hash_NewTable (1021, frame_get_key, frame_free, 0);
|
|
|
|
grab_tab = Hash_NewTable (1021, frame_get_key, 0, 0);
|
|
|
|
for (i = 0; i < sizeof (grab_list) / sizeof (grab_list[0]); i++)
|
|
|
|
Hash_Add (grab_tab, &grab_list[i]);
|
|
|
|
}
|
2002-04-07 05:44:34 +00:00
|
|
|
while (isspace ((unsigned char)*++token))
|
|
|
|
// advance over $ and leading space
|
2001-06-13 18:35:41 +00:00
|
|
|
;
|
|
|
|
if (!strcmp (token, "frame"))
|
|
|
|
return -grab_frame;
|
|
|
|
if (Hash_Find (grab_tab, token))
|
|
|
|
return -grab_other;
|
|
|
|
frame = Hash_Find (frame_tab, token);
|
|
|
|
if (frame) {
|
2001-07-23 01:31:22 +00:00
|
|
|
yylval.integer_val = frame->num;
|
2001-06-13 18:35:41 +00:00
|
|
|
return INT_VAL;
|
2001-06-13 07:16:39 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2001-06-13 18:35:41 +00:00
|
|
|
|
|
|
|
static int frame_number;
|
|
|
|
|
|
|
|
void
|
|
|
|
add_frame_macro (char *token)
|
|
|
|
{
|
2002-06-05 21:13:29 +00:00
|
|
|
frame_t *frame;
|
|
|
|
ALLOC (1024, frame_t, frames, frame);
|
2001-06-13 18:35:41 +00:00
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
frame->name = save_string (token);
|
2001-06-13 18:35:41 +00:00
|
|
|
frame->num = frame_number++;
|
|
|
|
Hash_Add (frame_tab, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clear_frame_macros (void)
|
|
|
|
{
|
|
|
|
frame_number = 0;
|
|
|
|
if (frame_tab)
|
|
|
|
Hash_FlushTable (frame_tab);
|
|
|
|
}
|
2001-06-25 22:11:20 +00:00
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
const char *
|
2001-06-25 22:11:20 +00:00
|
|
|
make_string (char *token)
|
|
|
|
{
|
2002-06-27 22:48:28 +00:00
|
|
|
char s[2];
|
2002-01-04 18:27:01 +00:00
|
|
|
int c;
|
|
|
|
int i;
|
|
|
|
int mask;
|
|
|
|
int boldnext;
|
|
|
|
int quote;
|
2002-06-27 22:48:28 +00:00
|
|
|
static dstring_t *str;
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
str = dstring_newstr ();
|
|
|
|
dstring_clearstr (str);
|
2002-01-04 18:27:01 +00:00
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
s[1] = 0;
|
2002-01-04 18:27:01 +00:00
|
|
|
|
|
|
|
mask = 0x00;
|
|
|
|
boldnext = 0;
|
|
|
|
|
|
|
|
quote = *token++;
|
|
|
|
do {
|
|
|
|
c = *token++;
|
|
|
|
if (!c)
|
|
|
|
error (0, "EOF inside quote");
|
|
|
|
if (c == '\n')
|
|
|
|
error (0, "newline inside quote");
|
|
|
|
if (c == '\\') { // escape char
|
|
|
|
c = *token++;
|
|
|
|
if (!c)
|
|
|
|
error (0, "EOF inside quote");
|
|
|
|
switch (c) {
|
|
|
|
case '\\':
|
|
|
|
c = '\\';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
c = '\n';
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
c = '\"';
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
c = '\'';
|
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
for (i = c = 0; i < 3
|
|
|
|
&& *token >= '0'
|
|
|
|
&& *token <= '7'; i++, token++) {
|
|
|
|
c *= 8;
|
|
|
|
c += *token - '0';
|
|
|
|
}
|
|
|
|
if (!*token)
|
|
|
|
error (0, "EOF inside quote");
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
c = 0;
|
2002-04-07 05:44:34 +00:00
|
|
|
while (*token && isxdigit ((unsigned char)*token)) {
|
2002-01-04 18:27:01 +00:00
|
|
|
c *= 16;
|
|
|
|
if (*token <= '9')
|
|
|
|
c += *token - '0';
|
|
|
|
else if (*token <= 'F')
|
|
|
|
c += *token - 'A' + 10;
|
|
|
|
else
|
|
|
|
c += *token - 'a' + 10;
|
|
|
|
token++;
|
|
|
|
}
|
|
|
|
if (!*token)
|
|
|
|
error (0, "EOF inside quote");
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
c = '\a';
|
|
|
|
break;
|
|
|
|
case 'b':
|
2002-04-26 22:23:28 +00:00
|
|
|
//XXX mask ^= 0x80;
|
2002-01-04 18:27:01 +00:00
|
|
|
c = '\b';
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
c = '\033';
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
c = '\f';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
c = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
c = '\t';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
c = '\v';
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
if (*token == '\"')
|
|
|
|
error (0, "Unexpected end of string after \\^");
|
|
|
|
boldnext = 1;
|
|
|
|
continue;
|
2002-04-26 22:23:28 +00:00
|
|
|
case '[':
|
|
|
|
c = 0x90;
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
c = 0x91;
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
c = 28;
|
|
|
|
break;
|
2002-01-04 18:27:01 +00:00
|
|
|
case '<':
|
2002-04-26 22:23:28 +00:00
|
|
|
//XXX c = 29;
|
2002-01-04 18:27:01 +00:00
|
|
|
mask = 0x80;
|
|
|
|
continue;
|
2002-04-26 22:23:28 +00:00
|
|
|
case '-':
|
|
|
|
c = 30;
|
|
|
|
break;
|
2002-01-04 18:27:01 +00:00
|
|
|
case '>':
|
2002-04-26 22:23:28 +00:00
|
|
|
//XXX c = 31;
|
2002-01-04 18:27:01 +00:00
|
|
|
mask = 0x00;
|
|
|
|
continue;
|
2002-04-26 22:23:28 +00:00
|
|
|
case '(':
|
|
|
|
c = 128;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
c = 129;
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
c = 130;
|
|
|
|
break;
|
|
|
|
case '{':
|
|
|
|
c = 0;
|
|
|
|
while (*token && *token != '}'
|
|
|
|
&& isdigit ((unsigned char)*token)) {
|
|
|
|
c *= 10;
|
|
|
|
c += *token - '0';
|
|
|
|
}
|
|
|
|
if (!*token)
|
|
|
|
error (0, "EOF inside quote");
|
|
|
|
if (*token != '}')
|
|
|
|
error (0, "non-digit inside \\{}");
|
|
|
|
else
|
|
|
|
token++;
|
|
|
|
if (c > 255)
|
|
|
|
warning (0, "\\{%d} > 255", c);
|
|
|
|
break;
|
2002-01-04 18:27:01 +00:00
|
|
|
default:
|
|
|
|
error (0, "Unknown escape char");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (c == quote) {
|
|
|
|
break;;
|
|
|
|
}
|
|
|
|
if (boldnext)
|
|
|
|
c = c ^ 0x80;
|
|
|
|
boldnext = 0;
|
|
|
|
c = c ^ mask;
|
2002-06-27 22:48:28 +00:00
|
|
|
s[0] = c;
|
|
|
|
dstring_appendstr (str, s);
|
2002-01-04 18:27:01 +00:00
|
|
|
} while (1);
|
|
|
|
|
2002-06-27 22:48:28 +00:00
|
|
|
return save_string (str->str);
|
2001-06-25 22:11:20 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
|
2003-04-16 19:41:52 +00:00
|
|
|
#ifdef YY_FLEX_REALLOC_HACK
|
2005-03-31 09:55:41 +00:00
|
|
|
static __attribute__ ((unused)) void *(*const yy_flex_realloc_hack)(void *,yy_size_t) = yy_flex_realloc;
|
2003-04-17 00:25:55 +00:00
|
|
|
#else
|
2003-04-17 00:01:48 +00:00
|
|
|
static __attribute__ ((unused)) void (*yyunput_hack)(int, char*) = yyunput;
|
2003-04-17 00:14:13 +00:00
|
|
|
#endif
|