/* Core Wars. * Copyright (C) 1999 Walter Hofmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * 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 the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ %{ #include #include #include #include #include #include "main.h" #include "options.h" #include "program.h" #include "program-rc.h" #define cmalloc(x) calloc(1,x) #define EXPR_INTEGER 0 /* integer */ #define EXPR_LABEL 1 /* label */ #define EXPR_ADD 2 /* integer * a + b */ #define EXPR_SUB 3 /* integer * a - b */ #define EXPR_SGN 4 /* integer * a */ #define EXPR_MUL 5 /* a * b */ #define EXPR_DIV 6 /* a / b */ #define EXPR_MOD 7 /* a % b */ #define EXPR_EQU 8 /* a == b */ struct line { struct line *next; struct rc_command *cmd; } ; struct expr { int what; int integer; char *name; int operation; struct expr *a, *b; } ; struct label { struct label *next; char *name; int relative; int address; int in_eval; struct expr *expr; } ; struct label *create_label(char *name); void free_expr(struct expr *expr); struct expr *copy_expr(struct expr *expr); int current_line, *current_cell; struct line *root_line; struct expr *org; struct label *label_list; struct label *for_index; char rc_error_message[1024]; int eval_expr(struct expr *expr, int rel, jmp_buf env); void subs_expr(struct expr *expr, struct label *label, int i); void rc_error (char *s); int rc_lex (void); void rc_restart(FILE *input_file); %} %union { int integer; char *name; struct rc_command *cmd; struct line *line; struct label *label; struct expr *expr; } %token INTEGER %token IDENTIFIER %token WHITESPACE %token COMMENT %token RC_CMD %token RC_INSTR_EQU %token RC_INSTR_ORG %token RC_INSTR_END %token RC_INSTR_FOR %token RC_INSTR_ROF %type list for_list %type line %type instruction %type command %type