quakeforge/tools/qfcc/source/qc-parse.y

148 lines
1.9 KiB
Text
Raw Normal View History

2001-06-12 19:44:26 +00:00
%{
2001-06-12 20:24:02 +00:00
#include "qfcc.h"
#define YYDEBUG 1
#define YYERROR_VERBOSE 1
2001-06-12 20:24:02 +00:00
void
yyerror (char *s)
{
extern int lineno;
extern char *yytext;
fprintf (stderr, "%d, %s %s\n", lineno, yytext, s);
2001-06-12 20:24:02 +00:00
}
int yylex (void);
2001-06-12 19:44:26 +00:00
%}
2001-06-12 20:24:02 +00:00
%union {
def_t *def;
type_t *type;
int int_val;
float float_val;
char *string_val;
float vector_val[3];
float quaternion_val[4];
2001-06-12 20:24:02 +00:00
}
%left OR AND
2001-06-12 19:44:26 +00:00
%right '='
2001-06-12 20:24:02 +00:00
%left EQ NE LE GE LT GT
2001-06-12 19:44:26 +00:00
%left '+' '-'
%left '*' '/' '&' '|'
%left '!' '.' '('
%token NAME INT_VAL FLOAT_VAL STRING_VAL VECTOR_VAL QUATERNION_VAL
2001-06-12 19:44:26 +00:00
%token LOCAL TYPE RETURN WHILE DO IF ELSE FOR ELIPSIS
2001-06-12 19:44:26 +00:00
%expect 1
%%
defs
: /* empty */
| defs def ';'
;
def
: type def_list
;
type
: TYPE
| '.' TYPE
2001-06-12 19:44:26 +00:00
;
def_list
: def_item ',' def_list
| def_item
;
def_item
: NAME opt_initializer
| '(' param_list ')' NAME opt_initializer
| '(' ')' NAME opt_initializer
| '(' ELIPSIS ')' NAME opt_initializer
2001-06-12 19:44:26 +00:00
;
param_list
: param
2001-06-12 19:44:26 +00:00
| param_list ',' param
;
param
: type def_item
2001-06-12 19:44:26 +00:00
;
opt_initializer
: /*empty*/
| '=' '#' const
2001-06-12 19:44:26 +00:00
| '=' statement_block
| '=' const
2001-06-12 19:44:26 +00:00
| '=' '[' expr ',' expr ']' statement_block
;
statement_block
: '{' statements '}'
;
statements
: /*empty*/
| statements statement
2001-06-12 19:44:26 +00:00
;
statement
: ';'
| statement_block
| RETURN expr ';'
| RETURN ';'
2001-06-12 19:44:26 +00:00
| WHILE '(' expr ')' statement
| DO statement WHILE '(' expr ')' ';'
| LOCAL type def_list ';'
2001-06-12 19:44:26 +00:00
| IF '(' expr ')' statement
| IF '(' expr ')' statement ELSE statement
| FOR '(' expr ';' expr ';' expr ')' statement
| expr ';'
2001-06-12 19:44:26 +00:00
;
expr
2001-06-12 20:24:02 +00:00
: expr AND expr
| expr OR expr
2001-06-12 19:44:26 +00:00
| expr '=' expr
2001-06-12 20:24:02 +00:00
| expr EQ expr
| expr NE expr
| expr LE expr
| expr GE expr
| expr LT expr
| expr GT expr
2001-06-12 19:44:26 +00:00
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| expr '&' expr
| expr '|' expr
| expr '.' expr
| expr '(' arg_list ')'
| expr '(' ')'
| '-' expr
2001-06-12 19:44:26 +00:00
| '!' expr
| NAME
| const
2001-06-12 19:44:26 +00:00
| '(' expr ')'
;
arg_list
: expr
2001-06-12 19:44:26 +00:00
| arg_list ',' expr
;
const
: FLOAT_VAL
| STRING_VAL
| VECTOR_VAL
| QUATERNION_VAL
| INT_VAL
;
2001-06-12 19:44:26 +00:00
%%