2011-01-06 07:32:53 +00:00
|
|
|
%{
|
|
|
|
/*
|
2011-01-24 23:54:02 +00:00
|
|
|
qp-parse.y
|
2011-01-06 07:32:53 +00:00
|
|
|
|
2011-01-24 23:54:02 +00:00
|
|
|
parser for quakepascal
|
2011-01-06 07:32:53 +00:00
|
|
|
|
2011-01-24 23:54:02 +00:00
|
|
|
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
2011-01-06 07:32:53 +00:00
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
2011-01-24 23:54:02 +00:00
|
|
|
Date: 2011/01/06
|
2011-01-06 07:32:53 +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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|
|
|
|
2011-01-06 11:27:32 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
#include "QF/dstring.h"
|
|
|
|
|
2011-01-12 14:35:56 +00:00
|
|
|
#include "codespace.h"
|
2011-01-24 12:54:57 +00:00
|
|
|
#include "diagnostic.h"
|
2011-01-06 07:32:53 +00:00
|
|
|
#include "expr.h"
|
|
|
|
#include "function.h"
|
2011-01-06 14:13:18 +00:00
|
|
|
#include "qfcc.h"
|
2011-01-12 14:35:56 +00:00
|
|
|
#include "reloc.h"
|
2011-01-13 05:58:16 +00:00
|
|
|
#include "symtab.h"
|
2011-01-06 07:32:53 +00:00
|
|
|
#include "type.h"
|
|
|
|
|
|
|
|
#define YYDEBUG 1
|
|
|
|
#define YYERROR_VERBOSE 1
|
|
|
|
#undef YYERROR_VERBOSE
|
|
|
|
|
|
|
|
extern char *yytext;
|
|
|
|
|
|
|
|
static void
|
|
|
|
yyerror (const char *s)
|
|
|
|
{
|
|
|
|
#ifdef YYERROR_VERBOSE
|
|
|
|
error (0, "%s %s\n", yytext, s);
|
|
|
|
#else
|
|
|
|
error (0, "%s before %s", s, yytext);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_error (void)
|
|
|
|
{
|
|
|
|
error (0, "parse error before %s", yytext);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PARSE_ERROR do { parse_error (); YYERROR; } while (0)
|
|
|
|
|
|
|
|
int yylex (void);
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
|
|
|
int op;
|
|
|
|
struct def_s *def;
|
|
|
|
struct hashtab_s *def_list;
|
|
|
|
struct type_s *type;
|
|
|
|
struct typedef_s *typename;
|
|
|
|
struct expr_s *expr;
|
|
|
|
struct function_s *function;
|
|
|
|
struct switch_block_s *switch_block;
|
|
|
|
struct param_s *param;
|
|
|
|
struct struct_s *strct;
|
2011-01-13 05:58:16 +00:00
|
|
|
struct symtab_s *symtab;
|
|
|
|
struct symbol_s *symbol;
|
2011-01-27 05:17:12 +00:00
|
|
|
int storage;
|
2011-01-06 07:32:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 14:13:18 +00:00
|
|
|
// these tokens are common with qc
|
2011-01-06 07:32:53 +00:00
|
|
|
%nonassoc IFX
|
|
|
|
%nonassoc ELSE
|
2011-01-06 14:13:18 +00:00
|
|
|
%nonassoc BREAK_PRIMARY
|
|
|
|
%nonassoc ';'
|
|
|
|
%nonassoc CLASS_NOT_CATEGORY
|
|
|
|
%nonassoc STORAGEX
|
|
|
|
|
|
|
|
%right <op> '=' ASX PAS /* pointer assign */
|
|
|
|
%right '?' ':'
|
|
|
|
%left OR
|
|
|
|
%left AND
|
|
|
|
%left '|'
|
|
|
|
%left '^'
|
|
|
|
%left '&'
|
|
|
|
%left EQ NE
|
|
|
|
%left LE GE LT GT
|
|
|
|
// end of tokens common with qc
|
2011-01-06 07:32:53 +00:00
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
%left <op> RELOP
|
|
|
|
%left <op> ADDOP
|
|
|
|
%left <op> MULOP
|
2011-01-06 07:32:53 +00:00
|
|
|
%right UNARY
|
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
%token <type> TYPE TYPE_NAME
|
|
|
|
%token <symbol> ID
|
|
|
|
%token <expr> CONST
|
2011-01-06 07:32:53 +00:00
|
|
|
|
|
|
|
%token PROGRAM VAR ARRAY OF FUNCTION PROCEDURE PBEGIN END IF THEN ELSE
|
2011-01-12 14:39:59 +00:00
|
|
|
%token WHILE DO RANGE ASSIGNOP NOT ELLIPSIS
|
2011-01-30 13:16:59 +00:00
|
|
|
%token RETURN
|
2011-01-06 07:32:53 +00:00
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
%type <type> type standard_type
|
|
|
|
%type <symbol> program_head identifier_list subprogram_head
|
2011-01-30 12:42:10 +00:00
|
|
|
%type <symtab> param_scope
|
2011-01-13 05:58:16 +00:00
|
|
|
%type <param> arguments parameter_list
|
|
|
|
%type <expr> compound_statement optional_statements statement_list
|
|
|
|
%type <expr> statement procedure_statement
|
|
|
|
%type <expr> expression_list expression unary_expr primary variable name
|
|
|
|
%type <op> sign
|
2011-01-06 07:32:53 +00:00
|
|
|
|
|
|
|
%{
|
2011-01-13 05:58:16 +00:00
|
|
|
symtab_t *current_symtab;
|
2011-01-26 05:48:22 +00:00
|
|
|
storage_class_t current_storage = st_global;
|
2011-01-06 07:32:53 +00:00
|
|
|
function_t *current_func;
|
2011-01-12 14:34:15 +00:00
|
|
|
struct class_type_s *current_class;
|
2011-01-06 07:32:53 +00:00
|
|
|
expr_t *local_expr;
|
2011-01-06 11:27:32 +00:00
|
|
|
param_t *current_params;
|
2011-01-30 12:42:10 +00:00
|
|
|
|
|
|
|
/* When defining a new symbol, already existing symbols must be in a
|
|
|
|
different scope. However, when they are in a different scope, we want a
|
|
|
|
truly new symbol.
|
|
|
|
*/
|
|
|
|
static symbol_t *
|
|
|
|
check_redefined (symbol_t *sym)
|
|
|
|
{
|
|
|
|
if (sym->table == current_symtab)
|
|
|
|
error (0, "%s redefined", sym->name);
|
|
|
|
if (sym->table) // truly new symbols are not in any symbol table
|
|
|
|
sym = new_symbol (sym->name);
|
|
|
|
return sym;
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
program
|
2011-01-06 14:13:18 +00:00
|
|
|
: program_head
|
2011-01-06 07:32:53 +00:00
|
|
|
declarations
|
|
|
|
subprogram_declarations
|
2011-01-06 14:13:18 +00:00
|
|
|
compound_statement '.'
|
|
|
|
{
|
2011-01-19 13:19:26 +00:00
|
|
|
symtab_t *st = current_symtab;
|
2011-01-13 05:58:16 +00:00
|
|
|
// move the symbol for the program name to the end of the list
|
|
|
|
symtab_removesymbol (current_symtab, $1);
|
|
|
|
symtab_addsymbol (current_symtab, $1);
|
2011-01-18 03:37:12 +00:00
|
|
|
|
2011-02-15 03:38:29 +00:00
|
|
|
current_func = begin_function ($1, 0, current_symtab, 0);
|
2011-01-18 03:37:12 +00:00
|
|
|
current_symtab = current_func->symtab;
|
2011-01-18 23:38:09 +00:00
|
|
|
build_code_function ($1, 0, $4);
|
2011-01-19 13:19:26 +00:00
|
|
|
current_symtab = st;
|
2011-01-18 23:38:09 +00:00
|
|
|
|
|
|
|
$4 = function_expr (new_symbol_expr ($1), 0);
|
|
|
|
$1 = new_symbol (".main");
|
|
|
|
$1->params = 0;
|
|
|
|
$1->type = parse_params (&type_void, 0);
|
|
|
|
$1 = function_symbol ($1, 0, 1);
|
2011-02-15 03:38:29 +00:00
|
|
|
current_func = begin_function ($1, 0, current_symtab, 0);
|
2011-01-18 23:38:09 +00:00
|
|
|
current_symtab = current_func->symtab;
|
|
|
|
build_code_function ($1, 0, $4);
|
2011-01-19 13:19:26 +00:00
|
|
|
current_symtab = st;
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
2011-01-06 14:13:18 +00:00
|
|
|
program_head
|
2011-01-30 12:42:10 +00:00
|
|
|
: PROGRAM { current_symtab = pr.symtab; }
|
|
|
|
ID '(' opt_identifier_list ')' ';'
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
2011-01-30 12:42:10 +00:00
|
|
|
$$ = $3;
|
2011-01-18 03:37:12 +00:00
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
$$->type = parse_params (&type_void, 0);
|
2011-01-18 03:37:12 +00:00
|
|
|
$$ = function_symbol ($$, 0, 1);
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
2011-01-13 05:58:16 +00:00
|
|
|
opt_identifier_list
|
|
|
|
: /* empty */
|
|
|
|
| identifier_list
|
|
|
|
;
|
|
|
|
|
2011-01-06 07:32:53 +00:00
|
|
|
identifier_list
|
2011-01-30 12:42:10 +00:00
|
|
|
: ID { $$ = check_redefined ($1); }
|
2011-01-06 07:32:53 +00:00
|
|
|
| identifier_list ',' ID
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
symbol_t **s;
|
|
|
|
$$ = $1;
|
2011-01-30 12:42:10 +00:00
|
|
|
$3 = check_redefined ($3);
|
2011-01-13 05:58:16 +00:00
|
|
|
for (s = &$$; *s; s = &(*s)->next)
|
|
|
|
;
|
|
|
|
*s = $3;
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
declarations
|
|
|
|
: declarations VAR identifier_list ':' type ';'
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
while ($3) {
|
|
|
|
symbol_t *next = $3->next;
|
2011-01-27 05:17:12 +00:00
|
|
|
initialize_def ($3, $5, 0, current_symtab->space,
|
|
|
|
current_storage);
|
2011-01-13 05:58:16 +00:00
|
|
|
$3 = next;
|
|
|
|
}
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| /* empty */
|
|
|
|
;
|
|
|
|
|
|
|
|
type
|
2011-01-13 05:58:16 +00:00
|
|
|
: standard_type
|
|
|
|
| ARRAY '[' CONST RANGE CONST ']' OF standard_type
|
2011-01-06 07:32:53 +00:00
|
|
|
{
|
2011-01-18 23:41:24 +00:00
|
|
|
$$ = based_array_type ($8, expr_integer ($3), expr_integer ($5));
|
2011-01-06 07:32:53 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
standard_type
|
2011-01-13 05:58:16 +00:00
|
|
|
: TYPE
|
|
|
|
| TYPE_NAME
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
subprogram_declarations
|
|
|
|
: subprogram_declarations subprogram_declaration
|
|
|
|
| /* emtpy */
|
|
|
|
;
|
|
|
|
|
|
|
|
subprogram_declaration
|
2011-01-06 11:27:32 +00:00
|
|
|
: subprogram_head ';'
|
|
|
|
{
|
2011-01-27 05:17:12 +00:00
|
|
|
$<storage>$ = current_storage;
|
2011-01-28 12:56:17 +00:00
|
|
|
current_storage = st_local;
|
2011-02-15 03:38:29 +00:00
|
|
|
current_func = begin_function ($1, 0, current_symtab, 0);
|
2011-01-18 03:37:12 +00:00
|
|
|
current_symtab = current_func->symtab;
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
|
|
|
declarations compound_statement ';'
|
|
|
|
{
|
2011-01-18 23:38:09 +00:00
|
|
|
build_code_function ($1, 0, $5);
|
2011-01-27 05:17:12 +00:00
|
|
|
current_symtab = current_symtab->parent;
|
|
|
|
current_storage = $<storage>3;
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-13 05:58:16 +00:00
|
|
|
| subprogram_head ASSIGNOP '#' CONST ';'
|
2011-01-17 13:33:33 +00:00
|
|
|
{
|
2011-02-15 03:38:29 +00:00
|
|
|
build_builtin_function ($1, $4, 0);
|
2011-01-17 13:33:33 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
subprogram_head
|
|
|
|
: FUNCTION ID arguments ':' standard_type
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = $2;
|
|
|
|
if ($$->table == current_symtab) {
|
|
|
|
error (0, "%s redefined", $$->name);
|
|
|
|
} else {
|
|
|
|
$$->params = $3;
|
|
|
|
$$->type = parse_params ($5, $3);
|
2011-01-18 03:37:12 +00:00
|
|
|
$$ = function_symbol ($$, 0, 1);
|
2011-01-13 05:58:16 +00:00
|
|
|
}
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| PROCEDURE ID arguments
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = $2;
|
|
|
|
if ($$->table == current_symtab) {
|
|
|
|
error (0, "%s redefined", $$->name);
|
|
|
|
} else {
|
|
|
|
$$->params = $3;
|
|
|
|
$$->type = parse_params (&type_void, $3);
|
2011-01-18 03:37:12 +00:00
|
|
|
$$ = function_symbol ($$, 0, 1);
|
2011-01-13 05:58:16 +00:00
|
|
|
}
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
arguments
|
2011-01-30 12:42:10 +00:00
|
|
|
: '(' param_scope parameter_list ')'
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
current_symtab = $2;
|
|
|
|
}
|
|
|
|
| '(' param_scope parameter_list ';' ELLIPSIS ')'
|
2011-01-12 14:39:59 +00:00
|
|
|
{
|
2011-01-30 12:42:10 +00:00
|
|
|
$$ = param_append_identifiers ($3, 0, 0);
|
|
|
|
current_symtab = $2;
|
2011-01-12 14:39:59 +00:00
|
|
|
}
|
2011-01-13 05:58:16 +00:00
|
|
|
| '(' ELLIPSIS ')' { $$ = new_param (0, 0, 0); }
|
|
|
|
| /* emtpy */ { $$ = 0; }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
2011-01-30 12:42:10 +00:00
|
|
|
param_scope
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = current_symtab;
|
|
|
|
current_symtab = new_symtab (current_symtab, stab_local);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2011-01-06 07:32:53 +00:00
|
|
|
parameter_list
|
|
|
|
: identifier_list ':' type
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = param_append_identifiers (0, $1, $3);
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| parameter_list ';' identifier_list ':' type
|
2011-01-06 11:27:32 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = param_append_identifiers ($1, $3, $5);
|
2011-01-06 11:27:32 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
compound_statement
|
2011-01-13 05:58:16 +00:00
|
|
|
: PBEGIN optional_statements END { $$ = $2; }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
optional_statements
|
2011-01-13 05:58:16 +00:00
|
|
|
: statement_list opt_semi
|
|
|
|
| /* emtpy */ { $$ = 0; }
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_semi
|
|
|
|
: ';'
|
|
|
|
| /* empty */
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement_list
|
|
|
|
: statement
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
$$ = new_block_expr ();
|
|
|
|
append_expr ($$, $1);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| statement_list ';' statement
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
append_expr ($$, $3);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement
|
|
|
|
: variable ASSIGNOP expression
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = $1;
|
|
|
|
if ($$->type == ex_symbol && extract_type ($$) == ev_func)
|
|
|
|
$$ = new_ret_expr ($$->e.symbol->type->t.func.type);
|
|
|
|
$$ = assign_expr ($$, $3);
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-13 05:58:16 +00:00
|
|
|
| procedure_statement
|
|
|
|
| compound_statement
|
2011-01-06 07:32:53 +00:00
|
|
|
| IF expression THEN statement ELSE statement
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = build_if_statement ($2, $4, $6);
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| IF expression THEN statement %prec IFX
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
$$ = build_if_statement ($2, $4, 0);
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| WHILE expression DO statement
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
2011-01-17 13:33:33 +00:00
|
|
|
$$ = build_while_statement ($2, $4,
|
|
|
|
new_label_expr (),
|
|
|
|
new_label_expr ());
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-30 13:16:59 +00:00
|
|
|
| RETURN
|
|
|
|
{
|
|
|
|
$$ = return_expr (current_func, 0);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
variable
|
2011-01-13 05:58:16 +00:00
|
|
|
: name
|
|
|
|
| name '[' expression ']' { $$ = array_expr ($1, $3); }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
procedure_statement
|
2011-01-13 05:58:16 +00:00
|
|
|
: name { $$ = function_expr ($1, 0); }
|
|
|
|
| name '(' expression_list ')' { $$ = function_expr ($1, $3); }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
expression_list
|
|
|
|
: expression
|
|
|
|
| expression_list ',' expression
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
$$ = $3;
|
2011-01-13 05:58:16 +00:00
|
|
|
$$->next = $1;
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
unary_expr
|
|
|
|
: primary
|
2011-01-13 05:58:16 +00:00
|
|
|
| sign unary_expr %prec UNARY { $$ = unary_expr ($1, $2); }
|
|
|
|
| NOT expression %prec UNARY { $$ = unary_expr ('!', $2); }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
primary
|
|
|
|
: variable
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
$$ = $1;
|
2011-01-13 05:58:16 +00:00
|
|
|
if ($$->type == ex_symbol && extract_type ($$) == ev_func)
|
|
|
|
$$ = function_expr ($$, 0);
|
2011-01-06 14:13:18 +00:00
|
|
|
}
|
2011-01-13 05:58:16 +00:00
|
|
|
| CONST
|
|
|
|
| name '(' expression_list ')' { $$ = function_expr ($1, $3); }
|
|
|
|
| '(' expression ')' { $$ = $2; }
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
expression
|
|
|
|
: unary_expr
|
2011-01-13 05:58:16 +00:00
|
|
|
| expression RELOP expression { $$ = binary_expr ($2, $1, $3); }
|
2011-01-06 07:32:53 +00:00
|
|
|
| expression ADDOP expression
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
if ($2 == 'o')
|
|
|
|
$$ = bool_expr (OR, new_label_expr (), $1, $3);
|
|
|
|
else
|
|
|
|
$$ = binary_expr ($2, $1, $3);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
| expression MULOP expression
|
2011-01-06 14:13:18 +00:00
|
|
|
{
|
|
|
|
if ($2 == 'd')
|
|
|
|
$2 = '/';
|
|
|
|
else if ($2 == 'm')
|
|
|
|
$2 = '%';
|
|
|
|
if ($2 == 'a')
|
|
|
|
$$ = bool_expr (AND, new_label_expr (), $1, $3);
|
|
|
|
else
|
|
|
|
$$ = binary_expr ($2, $1, $3);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
sign
|
|
|
|
: ADDOP
|
|
|
|
{
|
2011-01-13 05:58:16 +00:00
|
|
|
if ($$ == 'o')
|
2011-01-06 07:32:53 +00:00
|
|
|
PARSE_ERROR;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2011-01-06 14:13:18 +00:00
|
|
|
name
|
2011-01-17 13:33:33 +00:00
|
|
|
: ID
|
|
|
|
{
|
|
|
|
if (!$1->table) {
|
|
|
|
error (0, "%s undefined", $1->name);
|
|
|
|
$1->type = &type_integer;
|
|
|
|
symtab_addsymbol (current_symtab, $1);
|
|
|
|
}
|
|
|
|
$$ = new_symbol_expr ($1);
|
|
|
|
}
|
2011-01-06 07:32:53 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|