when checking a token, they type of the token must be taken into account.

This commit is contained in:
Bill Currie 2001-03-14 04:14:09 +00:00
parent 00e71e3cc5
commit 6247233e0e
3 changed files with 49 additions and 49 deletions

View file

@ -357,8 +357,8 @@ void PR_Lex (void);
type_t *PR_ParseType (void); type_t *PR_ParseType (void);
char *PR_ParseName (void); char *PR_ParseName (void);
qboolean PR_Check (char *string); qboolean PR_Check (token_type_t type, char *string);
void PR_Expect (char *string); void PR_Expect (token_type_t type, char *string);
void PR_ParseError (char *error, ...); void PR_ParseError (char *error, ...);

View file

@ -354,7 +354,7 @@ PR_ParseFunctionCall (def_t *func)
// copy the arguments to the global parameter variables // copy the arguments to the global parameter variables
arg = 0; arg = 0;
if (!PR_Check (")")) { if (!PR_Check (tt_punct, ")")) {
do { do {
if (t->num_parms != -1 && arg >= t->num_parms) if (t->num_parms != -1 && arg >= t->num_parms)
PR_ParseError ("too many parameters"); PR_ParseError ("too many parameters");
@ -378,11 +378,11 @@ PR_ParseFunctionCall (def_t *func)
def_parms[arg].type = t->parm_types[arg]; def_parms[arg].type = t->parm_types[arg];
PR_Statement (&pr_opcodes[OP_STORE_V], e, &def_parms[arg]); PR_Statement (&pr_opcodes[OP_STORE_V], e, &def_parms[arg]);
arg++; arg++;
} while (PR_Check (",")); } while (PR_Check (tt_punct, ","));
if (t->num_parms != -1 && arg != t->num_parms) if (t->num_parms != -1 && arg != t->num_parms)
PR_ParseError ("too few parameters"); PR_ParseError ("too few parameters");
PR_Expect (")"); PR_Expect (tt_punct, ")");
} }
if (arg > 8) if (arg > 8)
@ -428,7 +428,7 @@ PR_Term (void)
def_t *e; def_t *e;
etype_t t; etype_t t;
if (PR_Check ("!")) { if (PR_Check (tt_punct, "!")) {
e = PR_Expression (NOT_PRIORITY); e = PR_Expression (NOT_PRIORITY);
t = e->type->type; t = e->type->type;
switch (t) { switch (t) {
@ -448,9 +448,9 @@ PR_Term (void)
} }
} }
if (PR_Check ("(")) { if (PR_Check (tt_punct, "(")) {
e = PR_Expression (TOP_PRIORITY); e = PR_Expression (TOP_PRIORITY);
PR_Expect (")"); PR_Expect (tt_punct, ")");
return e; return e;
} }
@ -474,7 +474,7 @@ PR_Expression (int priority)
e = PR_Expression (priority - 1); e = PR_Expression (priority - 1);
while (1) { while (1) {
if (priority == 1 && PR_Check ("(")) if (priority == 1 && PR_Check (tt_punct, "("))
return PR_ParseFunctionCall (e); return PR_ParseFunctionCall (e);
for (op = pr_opcodes; op->name; op++) { for (op = pr_opcodes; op->name; op++) {
@ -482,7 +482,7 @@ PR_Expression (int priority)
if (op->priority != priority) if (op->priority != priority)
continue; continue;
if (!PR_Check (op->name)) if (!PR_Check (tt_punct, op->name))
continue; continue;
if (op->right_associative) { if (op->right_associative) {
@ -550,32 +550,32 @@ PR_ParseStatement (void)
def_t *e; def_t *e;
dstatement_t *patch1, *patch2; dstatement_t *patch1, *patch2;
if (PR_Check ("{")) { if (PR_Check (tt_punct, "{")) {
do { do {
PR_ParseStatement (); PR_ParseStatement ();
} while (!PR_Check ("}")); } while (!PR_Check (tt_punct, "}"));
return; return;
} }
if (PR_Check ("return")) { if (PR_Check (tt_name, "return")) {
if (PR_Check (";")) { if (PR_Check (tt_punct, ";")) {
PR_Statement (&pr_opcodes[OP_RETURN], 0, 0); PR_Statement (&pr_opcodes[OP_RETURN], 0, 0);
return; return;
} }
e = PR_Expression (TOP_PRIORITY); e = PR_Expression (TOP_PRIORITY);
PR_Expect (";"); PR_Expect (tt_punct, ";");
PR_Statement (&pr_opcodes[OP_RETURN], e, 0); PR_Statement (&pr_opcodes[OP_RETURN], e, 0);
return; return;
} }
if (PR_Check ("while")) { if (PR_Check (tt_name, "while")) {
PR_Expect ("("); PR_Expect (tt_punct, "(");
patch2 = &statements[numstatements]; patch2 = &statements[numstatements];
e = PR_Expression (TOP_PRIORITY); e = PR_Expression (TOP_PRIORITY);
PR_Expect (")"); PR_Expect (tt_punct, ")");
patch1 = &statements[numstatements]; patch1 = &statements[numstatements];
PR_Statement (&pr_opcodes[OP_IFNOT], e, 0); PR_Statement (&pr_opcodes[OP_IFNOT], e, 0);
PR_ParseStatement (); PR_ParseStatement ();
@ -585,36 +585,36 @@ PR_ParseStatement (void)
return; return;
} }
if (PR_Check ("do")) { if (PR_Check (tt_name, "do")) {
patch1 = &statements[numstatements]; patch1 = &statements[numstatements];
PR_ParseStatement (); PR_ParseStatement ();
PR_Expect ("while"); PR_Expect (tt_name, "while");
PR_Expect ("("); PR_Expect (tt_punct, "(");
e = PR_Expression (TOP_PRIORITY); e = PR_Expression (TOP_PRIORITY);
PR_Expect (")"); PR_Expect (tt_punct, ")");
PR_Expect (";"); PR_Expect (tt_punct, ";");
junkdef.ofs = patch1 - &statements[numstatements]; junkdef.ofs = patch1 - &statements[numstatements];
PR_Statement (&pr_opcodes[OP_IF], e, &junkdef); PR_Statement (&pr_opcodes[OP_IF], e, &junkdef);
return; return;
} }
if (PR_Check ("local")) { if (PR_Check (tt_name, "local")) {
PR_ParseDefs (); PR_ParseDefs ();
locals_end = numpr_globals; locals_end = numpr_globals;
return; return;
} }
if (PR_Check ("if")) { if (PR_Check (tt_name, "if")) {
PR_Expect ("("); PR_Expect (tt_punct, "(");
e = PR_Expression (TOP_PRIORITY); e = PR_Expression (TOP_PRIORITY);
PR_Expect (")"); PR_Expect (tt_punct, ")");
patch1 = &statements[numstatements]; patch1 = &statements[numstatements];
PR_Statement (&pr_opcodes[OP_IFNOT], e, 0); PR_Statement (&pr_opcodes[OP_IFNOT], e, 0);
PR_ParseStatement (); PR_ParseStatement ();
if (PR_Check ("else")) { if (PR_Check (tt_name, "else")) {
patch2 = &statements[numstatements]; patch2 = &statements[numstatements];
PR_Statement (&pr_opcodes[OP_GOTO], 0, 0); PR_Statement (&pr_opcodes[OP_GOTO], 0, 0);
patch1->b = &statements[numstatements] - patch1; patch1->b = &statements[numstatements] - patch1;
@ -628,7 +628,7 @@ PR_ParseStatement (void)
} }
PR_Expression (TOP_PRIORITY); PR_Expression (TOP_PRIORITY);
PR_Expect (";"); PR_Expect (tt_punct, ";");
} }
@ -663,12 +663,12 @@ PR_ParseState (void)
s1 = PR_ParseImmediate (); s1 = PR_ParseImmediate ();
PR_Expect (","); PR_Expect (tt_punct, ",");
name = PR_ParseName (); name = PR_ParseName ();
def = PR_GetDef (&type_function, name, 0, true); def = PR_GetDef (&type_function, name, 0, true);
PR_Expect ("]"); PR_Expect (tt_punct, "]");
PR_Statement (&pr_opcodes[OP_STATE], s1, def); PR_Statement (&pr_opcodes[OP_STATE], s1, def);
} }
@ -688,7 +688,7 @@ PR_ParseImmediateStatements (type_t *type)
f = malloc (sizeof (function_t)); f = malloc (sizeof (function_t));
// check for builtin function definition #1, #2, etc // check for builtin function definition #1, #2, etc
if (PR_Check ("#")) { if (PR_Check (tt_punct, "#")) {
if (pr_token_type != tt_immediate if (pr_token_type != tt_immediate
|| pr_immediate_type != &type_float || pr_immediate_type != &type_float
|| pr_immediate._float != (int) pr_immediate._float) { || pr_immediate._float != (int) pr_immediate._float) {
@ -713,13 +713,13 @@ PR_ParseImmediateStatements (type_t *type)
f->code = numstatements; f->code = numstatements;
// check for a state opcode // check for a state opcode
if (PR_Check ("[")) if (PR_Check (tt_punct, "["))
PR_ParseState (); PR_ParseState ();
// parse regular statements // parse regular statements
PR_Expect ("{"); PR_Expect (tt_punct, "{");
while (!PR_Check ("}")) while (!PR_Check (tt_punct, "}"))
PR_ParseStatement (); PR_ParseStatement ();
// emit an end of statements opcode // emit an end of statements opcode
@ -848,7 +848,7 @@ PR_ParseDefs (void)
def = PR_GetDef (type, name, pr_scope, true); def = PR_GetDef (type, name, pr_scope, true);
// check for an initialization // check for an initialization
if (PR_Check ("=")) { if (PR_Check (tt_punct, "=")) {
if (def->initialized) if (def->initialized)
PR_ParseError ("%s redeclared", name); PR_ParseError ("%s redeclared", name);
@ -892,9 +892,9 @@ PR_ParseDefs (void)
PR_Lex (); PR_Lex ();
} }
} while (PR_Check (",")); } while (PR_Check (tt_punct, ","));
PR_Expect (";"); PR_Expect (tt_punct, ";");
} }
/* /*

View file

@ -502,9 +502,9 @@ PR_ParseError (char *error, ...)
to string to string
*/ */
void void
PR_Expect (char *string) PR_Expect (token_type_t type, char *string)
{ {
if (strcmp (string, pr_token)) if (type != pr_token_type || strcmp (string, pr_token))
PR_ParseError ("expected %s, found %s", string, pr_token); PR_ParseError ("expected %s, found %s", string, pr_token);
PR_Lex (); PR_Lex ();
} }
@ -517,9 +517,9 @@ PR_Expect (char *string)
Otherwise, return false and do nothing else. Otherwise, return false and do nothing else.
*/ */
qboolean qboolean
PR_Check (char *string) PR_Check (token_type_t type, char *string)
{ {
if (strcmp (string, pr_token)) if (type != pr_token_type || strcmp (string, pr_token))
return false; return false;
PR_Lex (); PR_Lex ();
@ -599,7 +599,7 @@ void
PR_SkipToSemicolon (void) PR_SkipToSemicolon (void)
{ {
do { do {
if (!pr_bracelevel && PR_Check (";")) if (!pr_bracelevel && PR_Check (tt_punct, ";"))
return; return;
PR_Lex (); PR_Lex ();
} while (pr_token[0]); // eof will return a null token } while (pr_token[0]); // eof will return a null token
@ -620,7 +620,7 @@ PR_ParseType (void)
type_t *type; type_t *type;
char *name; char *name;
if (PR_Check (".")) { if (PR_Check (tt_punct, ".")) {
memset (&new, 0, sizeof (new)); memset (&new, 0, sizeof (new));
new.type = ev_field; new.type = ev_field;
new.aux_type = PR_ParseType (); new.aux_type = PR_ParseType ();
@ -645,7 +645,7 @@ PR_ParseType (void)
} }
PR_Lex (); PR_Lex ();
if (!PR_Check ("(")) if (!PR_Check (tt_punct, "("))
return type; return type;
// function type // function type
@ -653,8 +653,8 @@ PR_ParseType (void)
new.type = ev_function; new.type = ev_function;
new.aux_type = type; // return type new.aux_type = type; // return type
new.num_parms = 0; new.num_parms = 0;
if (!PR_Check (")")) { if (!PR_Check (tt_punct, ")")) {
if (PR_Check ("...")) { if (PR_Check (tt_punct, "...")) {
new.num_parms = -1; // variable args new.num_parms = -1; // variable args
} else { } else {
do { do {
@ -663,10 +663,10 @@ PR_ParseType (void)
strcpy (pr_parm_names[new.num_parms], name); strcpy (pr_parm_names[new.num_parms], name);
new.parm_types[new.num_parms] = type; new.parm_types[new.num_parms] = type;
new.num_parms++; new.num_parms++;
} while (PR_Check (",")); } while (PR_Check (tt_punct, ","));
} }
PR_Expect (")"); PR_Expect (tt_punct, ")");
} }
return PR_FindType (&new); return PR_FindType (&new);