From 78a88232efd05c6bd52e71f8167ff38f0fdba473 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 14 Apr 2021 14:41:48 -0400 Subject: [PATCH] removed generated files --- src/lex.yy.c | 2035 ------------------ src/lex.yy.h | 472 ---- src/y.tab.c | 5848 -------------------------------------------------- src/y.tab.h | 171 -- 4 files changed, 8526 deletions(-) delete mode 100644 src/lex.yy.c delete mode 100644 src/lex.yy.h delete mode 100644 src/y.tab.c delete mode 100644 src/y.tab.h diff --git a/src/lex.yy.c b/src/lex.yy.c deleted file mode 100644 index 3200d1d..0000000 --- a/src/lex.yy.c +++ /dev/null @@ -1,2035 +0,0 @@ - -#line 3 "lex.yy.c" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 4 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an - * integer in range [0..255] for use as an array index. - */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - #define YY_LINENO_REWIND_TO(ptr) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -static void yyensure_buffer_stack ( void ); -static void yy_load_buffer_state ( void ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); - -#define yy_new_buffer yy_create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ -typedef flex_uint8_t YY_CHAR; - -FILE *yyin = NULL, *yyout = NULL; - -typedef int yy_state_type; - -extern int yylineno; -int yylineno = 1; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state ( void ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); -static int yy_get_next_buffer ( void ); -static void yynoreturn yy_fatal_error ( const char* msg ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 16 -#define YY_END_OF_BUFFER 17 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static const flex_int16_t yy_acclist[56] = - { 0, - 17, 15, 16, 1, 15, 16, 2, 16, 15, 16, - 15, 16, 8, 15, 16, 8, 15, 16, 8, 15, - 16, 8202, 15, 16,16394, 8, 15, 16, 8, 15, - 16, 8, 15, 16, 9, 15, 16, 1, 7, 12, - 14, 4, 11, 8202,16394, 8202,16394, 13, 3, 5, - 6, 9, 8202, 11, 11 - } ; - -static const flex_int16_t yy_accept[41] = - { 0, - 1, 1, 1, 2, 4, 7, 9, 11, 13, 16, - 19, 22, 26, 29, 32, 35, 38, 39, 40, 40, - 41, 42, 43, 44, 46, 46, 48, 49, 50, 51, - 52, 53, 53, 54, 55, 55, 55, 55, 56, 56 - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 5, 1, 1, 1, 1, 1, 6, - 7, 8, 9, 7, 9, 10, 7, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 12, 7, 13, - 14, 15, 1, 1, 16, 16, 16, 16, 17, 16, - 18, 19, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 20, 18, 18, - 7, 1, 7, 7, 21, 1, 18, 18, 18, 18, - - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 7, 7, 7, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static const YY_CHAR yy_meta[22] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 3, 1, 1, 1, 1, 3, 3, 3, 3, 3, - 3 - } ; - -static const flex_int16_t yy_base[42] = - { 0, - 0, 0, 57, 58, 54, 58, 41, 49, 45, 58, - 42, 12, 37, 36, 35, 27, 45, 58, 41, 58, - 58, 58, 16, 0, 14, 35, 58, 58, 58, 58, - 23, 22, 58, 19, 26, 32, 30, 28, 58, 37, - 31 - } ; - -static const flex_int16_t yy_def[42] = - { 0, - 39, 1, 39, 39, 39, 39, 39, 40, 39, 39, - 39, 39, 39, 39, 39, 41, 39, 39, 40, 39, - 39, 39, 39, 12, 12, 39, 39, 39, 39, 39, - 41, 41, 39, 39, 39, 39, 39, 39, 0, 39, - 39 - } ; - -static const flex_int16_t yy_nxt[80] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 10, 10, 11, - 12, 13, 14, 10, 15, 16, 16, 16, 16, 16, - 4, 23, 24, 39, 25, 33, 34, 25, 25, 34, - 26, 27, 35, 31, 37, 35, 38, 19, 38, 19, - 38, 33, 39, 32, 36, 20, 17, 32, 30, 29, - 28, 22, 21, 20, 18, 17, 39, 3, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 39 - } ; - -static const flex_int16_t yy_chk[80] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 12, 12, 25, 25, 23, 23, 12, 12, 34, - 12, 12, 23, 41, 35, 34, 35, 40, 38, 40, - 37, 36, 32, 31, 26, 19, 17, 16, 15, 14, - 13, 11, 9, 8, 7, 5, 3, 39, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 39, 39, 39, 39, 39, 39, 39, 39 - } ; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; -static char *yy_full_match; -static int yy_lp; -static int yy_looking_for_trail_begin = 0; -static int yy_full_lp; -static int *yy_full_state; -#define YY_TRAILING_MASK 0x2000 -#define YY_TRAILING_HEAD_MASK 0x4000 -#define REJECT \ -{ \ -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ \ -yy_cp = (yy_full_match); /* restore poss. backed-over text */ \ -(yy_lp) = (yy_full_lp); /* restore orig. accepting pos. */ \ -(yy_state_ptr) = (yy_full_state); /* restore orig. state */ \ -yy_current_state = *(yy_state_ptr); /* restore curr. state */ \ -++(yy_lp); \ -goto find_rule; \ -} - -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "Oberon.l" -/*Copyright (C) 2017, 2018, 2019 Karl Landstrom - -This file is part of OBNC. - -OBNC 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 3 of the License, or -(at your option) any later version. - -OBNC 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 OBNC. If not, see .*/ -#line 21 "Oberon.l" -#include "Oberon.h" -#include "Util.h" -#include "../lib/obnc/OBNC.h" -#include "Trees.h" /*needed by YYSTYPE in y.tab.h*/ -#include "y.tab.h" -#include -#include -#include -#include -#include -#include -#include -#include - -static int KeywordToken(const char word[]); - -#line 523 "lex.yy.c" -#line 524 "lex.yy.c" - -#define INITIAL 0 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -static int yy_init_globals ( void ); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy ( void ); - -int yyget_debug ( void ); - -void yyset_debug ( int debug_flag ); - -YY_EXTRA_TYPE yyget_extra ( void ); - -void yyset_extra ( YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in ( void ); - -void yyset_in ( FILE * _in_str ); - -FILE *yyget_out ( void ); - -void yyset_out ( FILE * _out_str ); - - int yyget_leng ( void ); - -char *yyget_text ( void ); - -int yyget_lineno ( void ); - -void yyset_lineno ( int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap ( void ); -#else -extern int yywrap ( void ); -#endif -#endif - -#ifndef YY_NO_UNPUT - - static void yyunput ( int c, char *buf_ptr ); - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus -static int yyinput ( void ); -#else -static int input ( void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - - if ( !(yy_init) ) - { - (yy_init) = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - /* Create the reject buffer large enough to save one state per allowed character. */ - if ( ! (yy_state_buf) ) - (yy_state_buf) = (yy_state_type *)yyalloc(YY_STATE_BUF_SIZE ); - if ( ! (yy_state_buf) ) - YY_FATAL_ERROR( "out of dynamic memory in yylex()" ); - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - { -#line 49 "Oberon.l" - - -#line 750 "lex.yy.c" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); - - (yy_state_ptr) = (yy_state_buf); - *(yy_state_ptr)++ = yy_current_state; - -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 40 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - *(yy_state_ptr)++ = yy_current_state; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 58 ); - -yy_find_action: - yy_current_state = *--(yy_state_ptr); - (yy_lp) = yy_accept[yy_current_state]; -find_rule: /* we branch to this label when backing up */ - for ( ; ; ) /* until we find what rule we matched */ - { - if ( (yy_lp) && (yy_lp) < yy_accept[yy_current_state + 1] ) - { - yy_act = yy_acclist[(yy_lp)]; - if ( yy_act & YY_TRAILING_HEAD_MASK || - (yy_looking_for_trail_begin) ) - { - if ( yy_act == (yy_looking_for_trail_begin) ) - { - (yy_looking_for_trail_begin) = 0; - yy_act &= ~YY_TRAILING_HEAD_MASK; - break; - } - } - else if ( yy_act & YY_TRAILING_MASK ) - { - (yy_looking_for_trail_begin) = yy_act & ~YY_TRAILING_MASK; - (yy_looking_for_trail_begin) |= YY_TRAILING_HEAD_MASK; - } - else - { - (yy_full_match) = yy_cp; - (yy_full_state) = (yy_state_ptr); - (yy_full_lp) = (yy_lp); - break; - } - ++(yy_lp); - goto find_rule; - } - --yy_cp; - yy_current_state = *--(yy_state_ptr); - (yy_lp) = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ -case 1: -YY_RULE_SETUP -#line 51 "Oberon.l" - - YY_BREAK -case 2: -/* rule 2 can match eol */ -YY_RULE_SETUP -#line 53 "Oberon.l" -{ - yylineno++; -} - YY_BREAK -case 3: -YY_RULE_SETUP -#line 57 "Oberon.l" -return BECOMES; - YY_BREAK -case 4: -YY_RULE_SETUP -#line 59 "Oberon.l" -return DOTDOT; - YY_BREAK -case 5: -YY_RULE_SETUP -#line 61 "Oberon.l" -return LE; - YY_BREAK -case 6: -YY_RULE_SETUP -#line 63 "Oberon.l" -return GE; - YY_BREAK -case 7: -YY_RULE_SETUP -#line 65 "Oberon.l" -return NOT_EQ; - YY_BREAK -case 8: -YY_RULE_SETUP -#line 67 "Oberon.l" -return yytext[0]; - YY_BREAK -case 9: -YY_RULE_SETUP -#line 69 "Oberon.l" -{ - int token; - char *lexeme; - - token = KeywordToken(yytext); - if (token < 0) { - token = IDENT; - NEW_ARRAY(lexeme, yyleng + 1); - strcpy(lexeme, yytext); - yylval.ident = lexeme; - } - return token; -} - YY_BREAK -case 10: -YY_RULE_SETUP -#line 83 "Oberon.l" -{ - int base; - unsigned long int max, lexeme; - - base = (yytext[yyleng - 1] == 'H')? 16: 10; - max = (yytext[yyleng - 1] == 'H')? OBNC_UINT_MAX: OBNC_INT_MAX; - errno = 0; - lexeme = strtoul(yytext, NULL, base); - if ((errno != 0) || (lexeme > max)) { - if (base == 10) { - Oberon_PrintError("warning: %s: %s > %lu", strerror(ERANGE), yytext, max); - } else { - Oberon_PrintError("warning: %s: %s > 0%lXH", strerror(ERANGE), yytext, max); - } - } - yylval.integer = (OBNC_INTEGER) lexeme; - return INTEGER; -} - YY_BREAK -case 11: -YY_RULE_SETUP -#line 102 "Oberon.l" -{ - int n = sscanf(yytext, "%" OBNC_REAL_MOD_R "f", &yylval.real); - if (n != 1) { - Oberon_PrintError("warning: %s: %s > %" OBNC_REAL_MOD_W "G", strerror(ERANGE), yytext, OBNC_REAL_MAX); - } - return REAL; -} - YY_BREAK -case 12: -YY_RULE_SETUP -#line 110 "Oberon.l" -{ - int lexemeLen; - char *lexeme; - - lexemeLen = yyleng - 1; - NEW_ARRAY(lexeme, lexemeLen); - memcpy(lexeme, yytext + 1, (size_t) (lexemeLen - 1)); - lexeme[lexemeLen - 1] = '\0'; - yylval.string = lexeme; - return STRING; -} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 122 "Oberon.l" -{ - long ordinalNumber; - char *lexeme; - - if (strcmp(yytext, "0X") == 0) { - ordinalNumber = 0; - } else { - errno = 0; - ordinalNumber = strtol(yytext, NULL, 16); - if ((errno != 0) || (ordinalNumber > UCHAR_MAX)) { - Oberon_PrintError("warning: %s: %s > 0%XX", strerror(ERANGE), yytext, UCHAR_MAX); - } - } - NEW_ARRAY(lexeme, 2); - lexeme[0] = (char) ordinalNumber; - lexeme[1] = '\0'; - yylval.string = lexeme; - return STRING; -} - YY_BREAK -case 14: -YY_RULE_SETUP -#line 142 "Oberon.l" -{ - int linenoStart, level, ch; - - linenoStart = yylineno; - level = 1; - do { - ch = input(); - switch (ch) { - case '(': - ch = input(); - if (ch == '*') { - level++; - } else { - unput(ch); - } - break; - case '*': - ch = input(); - if (ch == ')') { - level--; - } else { - unput(ch); - } - break; - case '\n': - yylineno++; - break; - } - } while ((level > 0) && (ch > 0)); - assert((ch >= 0) || (ch == EOF)); - - /*Note: In Flex 2.6.0 and earlier, input returns EOF (-1) instead of 0 when end-of-file is reached.*/ - - if (level > 0) { - Oberon_PrintError("error: unterminated comment starting at line %d", linenoStart); - exit(EXIT_FAILURE); - } -} - YY_BREAK -case 15: -YY_RULE_SETUP -#line 181 "Oberon.l" -{ - if (isprint(yytext[0])) { - Oberon_PrintError("error: unexpected character: %c", yytext[0]); - } else { - Oberon_PrintError("error: unexpected character: %02X (hex)", yytext[0]); - } - exit(EXIT_FAILURE); -} - YY_BREAK -case 16: -YY_RULE_SETUP -#line 190 "Oberon.l" -ECHO; - YY_BREAK -#line 1020 "lex.yy.c" - case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - /* "- 2" to take care of EOB's */ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); - } - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - yy_state_type yy_current_state; - char *yy_cp; - - yy_current_state = (yy_start); - - (yy_state_ptr) = (yy_state_buf); - *(yy_state_ptr)++ = yy_current_state; - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 40 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - *(yy_state_ptr)++ = yy_current_state; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - int yy_is_jam; - - YY_CHAR yy_c = 1; - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 40 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 39); - if ( ! yy_is_jam ) - *(yy_state_ptr)++ = yy_current_state; - - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - - static void yyunput (int c, char * yy_bp ) -{ - char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - int number_to_move = (yy_n_chars) + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return 0; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); - } - - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf ); - - yyfree( (void *) b ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 1; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) - YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (const char * yystr ) -{ - - return yy_scan_bytes( yystr, (int) strlen(yystr) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yynoreturn yy_fatal_error (const char* msg ) -{ - fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param _line_number line number - * - */ -void yyset_lineno (int _line_number ) -{ - - yylineno = _line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * _in_str ) -{ - yyin = _in_str ; -} - -void yyset_out (FILE * _out_str ) -{ - yyout = _out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int _bdebug ) -{ - yy_flex_debug = _bdebug ; -} - -static int yy_init_globals (void) -{ - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from yylex_destroy(), so don't allocate here. - */ - - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; - - (yy_state_buf) = 0; - (yy_state_ptr) = 0; - (yy_full_match) = 0; - (yy_lp) = 0; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = NULL; - yyout = NULL; -#endif - - /* For future reference: Set errno on error, since we are called by - * yylex_init() - */ - return 0; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - yyfree ( (yy_state_buf) ); - (yy_state_buf) = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * yylex() is called, initialization will occur. */ - yy_init_globals( ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n ) -{ - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s ) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return malloc(size); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#line 190 "Oberon.l" - - -static int Cmp(const void *word, const void *keywordPtr) -{ - return strcmp((char *) word, * (char **) keywordPtr); -} - - -static int KeywordToken(const char word[]) -{ - static const char *keywords[] = {"and", "array", "begin", "by", "case", "const", "div", "do", "else", "elsif", "end", "false", "for", "if", "import", "is", "mod", "module", "nil", "not", "of", "or", "pointer", "procedure", "record", "repeat", "return", "then", "to", "true", "type", "until", "var", "while"}; - - static const int keywordTokens[] = { AND, ARRAY, BEGIN_, BY, CASE, CONST, DIV, DO, ELSE, ELSIF, END, FALSE, FOR, IF, IMPORT, IS, MOD, MODULE, NIL, NOT, OF, OR, POINTER, PROCEDURE, RECORD, REPEAT, RETURN, THEN, TO, TRUE, TYPE, UNTIL, VAR, WHILE}; - - const char **keywordPtr; - ptrdiff_t pos; - int token; - - keywordPtr = bsearch(word, keywords, LEN(keywords), sizeof keywords[0], Cmp); - if (keywordPtr != NULL) { - pos = keywordPtr - keywords; - assert(pos >= 0); - assert(pos < LEN(keywordTokens)); - token = keywordTokens[pos]; - } else { - token = -1; - } - return token; -} - - -int yywrap(void) -{ - const int done = 1; - - return done; -} - diff --git a/src/lex.yy.h b/src/lex.yy.h deleted file mode 100644 index 963e9ca..0000000 --- a/src/lex.yy.h +++ /dev/null @@ -1,472 +0,0 @@ -#ifndef yyHEADER_H -#define yyHEADER_H 1 -#define yyIN_HEADER 1 - -#line 6 "lex.yy.h" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 4 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifndef SIZE_MAX -#define SIZE_MAX (~(size_t)0) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* begin standard C++ headers. */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); - -/* Begin user sect3 */ - -extern int yylineno; - -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int yylex_destroy ( void ); - -int yyget_debug ( void ); - -void yyset_debug ( int debug_flag ); - -YY_EXTRA_TYPE yyget_extra ( void ); - -void yyset_extra ( YY_EXTRA_TYPE user_defined ); - -FILE *yyget_in ( void ); - -void yyset_in ( FILE * _in_str ); - -FILE *yyget_out ( void ); - -void yyset_out ( FILE * _out_str ); - - int yyget_leng ( void ); - -char *yyget_text ( void ); - -int yyget_lineno ( void ); - -void yyset_lineno ( int _line_number ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap ( void ); -#else -extern int yywrap ( void ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#ifndef yy_create_buffer_ALREADY_DEFINED -#undef yy_create_buffer -#endif -#ifndef yy_delete_buffer_ALREADY_DEFINED -#undef yy_delete_buffer -#endif -#ifndef yy_scan_buffer_ALREADY_DEFINED -#undef yy_scan_buffer -#endif -#ifndef yy_scan_string_ALREADY_DEFINED -#undef yy_scan_string -#endif -#ifndef yy_scan_bytes_ALREADY_DEFINED -#undef yy_scan_bytes -#endif -#ifndef yy_init_buffer_ALREADY_DEFINED -#undef yy_init_buffer -#endif -#ifndef yy_flush_buffer_ALREADY_DEFINED -#undef yy_flush_buffer -#endif -#ifndef yy_load_buffer_state_ALREADY_DEFINED -#undef yy_load_buffer_state -#endif -#ifndef yy_switch_to_buffer_ALREADY_DEFINED -#undef yy_switch_to_buffer -#endif -#ifndef yypush_buffer_state_ALREADY_DEFINED -#undef yypush_buffer_state -#endif -#ifndef yypop_buffer_state_ALREADY_DEFINED -#undef yypop_buffer_state -#endif -#ifndef yyensure_buffer_stack_ALREADY_DEFINED -#undef yyensure_buffer_stack -#endif -#ifndef yylex_ALREADY_DEFINED -#undef yylex -#endif -#ifndef yyrestart_ALREADY_DEFINED -#undef yyrestart -#endif -#ifndef yylex_init_ALREADY_DEFINED -#undef yylex_init -#endif -#ifndef yylex_init_extra_ALREADY_DEFINED -#undef yylex_init_extra -#endif -#ifndef yylex_destroy_ALREADY_DEFINED -#undef yylex_destroy -#endif -#ifndef yyget_debug_ALREADY_DEFINED -#undef yyget_debug -#endif -#ifndef yyset_debug_ALREADY_DEFINED -#undef yyset_debug -#endif -#ifndef yyget_extra_ALREADY_DEFINED -#undef yyget_extra -#endif -#ifndef yyset_extra_ALREADY_DEFINED -#undef yyset_extra -#endif -#ifndef yyget_in_ALREADY_DEFINED -#undef yyget_in -#endif -#ifndef yyset_in_ALREADY_DEFINED -#undef yyset_in -#endif -#ifndef yyget_out_ALREADY_DEFINED -#undef yyget_out -#endif -#ifndef yyset_out_ALREADY_DEFINED -#undef yyset_out -#endif -#ifndef yyget_leng_ALREADY_DEFINED -#undef yyget_leng -#endif -#ifndef yyget_text_ALREADY_DEFINED -#undef yyget_text -#endif -#ifndef yyget_lineno_ALREADY_DEFINED -#undef yyget_lineno -#endif -#ifndef yyset_lineno_ALREADY_DEFINED -#undef yyset_lineno -#endif -#ifndef yyget_column_ALREADY_DEFINED -#undef yyget_column -#endif -#ifndef yyset_column_ALREADY_DEFINED -#undef yyset_column -#endif -#ifndef yywrap_ALREADY_DEFINED -#undef yywrap -#endif -#ifndef yyget_lval_ALREADY_DEFINED -#undef yyget_lval -#endif -#ifndef yyset_lval_ALREADY_DEFINED -#undef yyset_lval -#endif -#ifndef yyget_lloc_ALREADY_DEFINED -#undef yyget_lloc -#endif -#ifndef yyset_lloc_ALREADY_DEFINED -#undef yyset_lloc -#endif -#ifndef yyalloc_ALREADY_DEFINED -#undef yyalloc -#endif -#ifndef yyrealloc_ALREADY_DEFINED -#undef yyrealloc -#endif -#ifndef yyfree_ALREADY_DEFINED -#undef yyfree -#endif -#ifndef yytext_ALREADY_DEFINED -#undef yytext -#endif -#ifndef yyleng_ALREADY_DEFINED -#undef yyleng -#endif -#ifndef yyin_ALREADY_DEFINED -#undef yyin -#endif -#ifndef yyout_ALREADY_DEFINED -#undef yyout -#endif -#ifndef yy_flex_debug_ALREADY_DEFINED -#undef yy_flex_debug -#endif -#ifndef yylineno_ALREADY_DEFINED -#undef yylineno -#endif -#ifndef yytables_fload_ALREADY_DEFINED -#undef yytables_fload -#endif -#ifndef yytables_destroy_ALREADY_DEFINED -#undef yytables_destroy -#endif -#ifndef yyTABLES_NAME_ALREADY_DEFINED -#undef yyTABLES_NAME -#endif - -#line 190 "Oberon.l" - - -#line 471 "lex.yy.h" -#undef yyIN_HEADER -#endif /* yyHEADER_H */ diff --git a/src/y.tab.c b/src/y.tab.c deleted file mode 100644 index e3a78cd..0000000 --- a/src/y.tab.c +++ /dev/null @@ -1,5848 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.5.1. */ - -/* Bison implementation for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, - Inc. - - 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 3 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, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* C LALR(1) parser skeleton written by Richard Stallman, by - simplifying the original so-called "semantic" parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Bison version. */ -#define YYBISON_VERSION "3.5.1" - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Push parsers. */ -#define YYPUSH 0 - -/* Pull parsers. */ -#define YYPULL 1 - - - - -/* First part of user prologue. */ -#line 18 "Oberon.y" - -#include "Config.h" -#include "Error.h" -#include "Files.h" -#include "Generate.h" -#include "lex.yy.h" -#include "Maps.h" -#include "Oberon.h" -#include "ModulePaths.h" -#include "Paths.h" -#include "Range.h" -#include "Table.h" -#include "Types.h" -#include "Trees.h" -#include "Util.h" -#include "../lib/obnc/OBNC.h" -#include -#include -#include -#include -#include -#include -#include -#include - -/*assignment contexts*/ -#define ASSIGNMENT_CONTEXT 0 -#define PARAM_SUBST_CONTEXT 1 -#define PROC_RESULT_CONTEXT 2 - -static int initialized = 0; - -static const char *inputFilename; -static int parseMode; -static char *inputModuleName; - -static Trees_Node unresolvedPointerTypes; -static Trees_Node currentTypeIdentdef; -static Trees_Node recordDeclarationStack; -static Trees_Node caseExpressionStack; -static Trees_Node caseLabelsStack; -static Trees_Node procedureDeclarationStack; - -void yyerror(const char msg[]); -static void CheckUnusedIdentifiers(void); - -/*constant predicate functions*/ - -static int IsBoolean(Trees_Node node); -static int IsChar(Trees_Node node); -static int IsInteger(Trees_Node node); -static int IsReal(Trees_Node node); -static int IsString(Trees_Node node); -static int IsSet(Trees_Node node); - -/*functions for type declaration productions*/ - -static Trees_Node ResolvedType(Trees_Node type, int isTypeDecl); -static void ResolvePointerTypes(Trees_Node baseType); -static const char *TypeString(Trees_Node type); - -/*functions for expression productions*/ - -static Trees_Node Designator(const char ident[], Trees_Node selectorList); -static int IsDesignator(Trees_Node exp); -static Trees_Node BaseIdent(Trees_Node designator); -static Trees_Node FirstSelector(Trees_Node designator); -static const char *DesignatorString(Trees_Node designator); -static void CheckIsValueExpression(Trees_Node exp); -static void SetSelectorTypes(Trees_Node identType, Trees_Node designator, int *parameterListFound); -static void RemoveActualParameters(Trees_Node *designator, Trees_Node *actualParameters); -static int IsConstExpression(Trees_Node exp); -static Trees_Node ExpressionConstValue(int relation, Trees_Node expA, Trees_Node expB); -static Trees_Node SimpleExpressionConstValue(int addOperator, Trees_Node expA, Trees_Node expB); -static Trees_Node TermConstValue(int mulOperator, Trees_Node expA, Trees_Node expB); -static const char *OperatorString(int operator); - -/*functions for statement productions*/ - -static int Writable(Trees_Node designator); -static void ValidateAssignment(Trees_Node expression, Trees_Node targetType, int context, int paramPos); -static void HandleProcedureCall(Trees_Node designator, Trees_Node actualParameters, int isFunctionCall, Trees_Node *ast); -static void CheckCaseLabelUniqueness(Trees_Node label); - -/*functions for module productions*/ - -static void ExportSymbolTable(const char symfilePath[]); - -#line 159 "y.tab.c" - -# ifndef YY_CAST -# ifdef __cplusplus -# define YY_CAST(Type, Val) static_cast (Val) -# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) -# else -# define YY_CAST(Type, Val) ((Type) (Val)) -# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) -# endif -# endif -# ifndef YY_NULLPTR -# if defined __cplusplus -# if 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# else -# define YY_NULLPTR ((void*)0) -# endif -# endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 1 -#endif - -/* Use api.header.include to #include this header - instead of duplicating it here. */ -#ifndef YY_YY_Y_TAB_H_INCLUDED -# define YY_YY_Y_TAB_H_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - TOKEN_START = 258, - AND = 259, - ARRAY = 260, - BEGIN_ = 261, - BY = 262, - CASE = 263, - CONST = 264, - DIV = 265, - DO = 266, - ELSE = 267, - ELSIF = 268, - END = 269, - FALSE = 270, - FOR = 271, - IF = 272, - IMPORT = 273, - IS = 274, - MOD = 275, - MODULE = 276, - NIL = 277, - NOT = 278, - OF = 279, - OR = 280, - POINTER = 281, - PROCEDURE = 282, - RECORD = 283, - REPEAT = 284, - RETURN = 285, - THEN = 286, - TO = 287, - TRUE = 288, - TYPE = 289, - UNTIL = 290, - VAR = 291, - WHILE = 292, - BECOMES = 293, - DOTDOT = 294, - GE = 295, - LE = 296, - NOT_EQ = 297, - IDENT = 298, - INTEGER = 299, - REAL = 300, - STRING = 301, - TOKEN_END = 302 - }; -#endif -/* Tokens. */ -#define TOKEN_START 258 -#define AND 259 -#define ARRAY 260 -#define BEGIN_ 261 -#define BY 262 -#define CASE 263 -#define CONST 264 -#define DIV 265 -#define DO 266 -#define ELSE 267 -#define ELSIF 268 -#define END 269 -#define FALSE 270 -#define FOR 271 -#define IF 272 -#define IMPORT 273 -#define IS 274 -#define MOD 275 -#define MODULE 276 -#define NIL 277 -#define NOT 278 -#define OF 279 -#define OR 280 -#define POINTER 281 -#define PROCEDURE 282 -#define RECORD 283 -#define REPEAT 284 -#define RETURN 285 -#define THEN 286 -#define TO 287 -#define TRUE 288 -#define TYPE 289 -#define UNTIL 290 -#define VAR 291 -#define WHILE 292 -#define BECOMES 293 -#define DOTDOT 294 -#define GE 295 -#define LE 296 -#define NOT_EQ 297 -#define IDENT 298 -#define INTEGER 299 -#define REAL 300 -#define STRING 301 -#define TOKEN_END 302 - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -union YYSTYPE -{ -#line 107 "Oberon.y" - - const char *ident; - OBNC_INTEGER integer; - OBNC_REAL real; - const char *string; - Trees_Node node; - -#line 313 "y.tab.c" - -}; -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - -extern YYSTYPE yylval; - -int yyparse (void); - -#endif /* !YY_YY_Y_TAB_H_INCLUDED */ - - - -#ifdef short -# undef short -#endif - -/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure - and (if available) are included - so that the code can choose integer types of a good width. */ - -#ifndef __PTRDIFF_MAX__ -# include /* INFRINGES ON USER NAME SPACE */ -# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_STDINT_H -# endif -#endif - -/* Narrow types that promote to a signed type and that can represent a - signed or unsigned integer of at least N bits. In tables they can - save space and decrease cache pressure. Promoting to a signed type - helps avoid bugs in integer arithmetic. */ - -#ifdef __INT_LEAST8_MAX__ -typedef __INT_LEAST8_TYPE__ yytype_int8; -#elif defined YY_STDINT_H -typedef int_least8_t yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef __INT_LEAST16_MAX__ -typedef __INT_LEAST16_TYPE__ yytype_int16; -#elif defined YY_STDINT_H -typedef int_least16_t yytype_int16; -#else -typedef short yytype_int16; -#endif - -#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST8_TYPE__ yytype_uint8; -#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ - && UINT_LEAST8_MAX <= INT_MAX) -typedef uint_least8_t yytype_uint8; -#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX -typedef unsigned char yytype_uint8; -#else -typedef short yytype_uint8; -#endif - -#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ -typedef __UINT_LEAST16_TYPE__ yytype_uint16; -#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ - && UINT_LEAST16_MAX <= INT_MAX) -typedef uint_least16_t yytype_uint16; -#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX -typedef unsigned short yytype_uint16; -#else -typedef int yytype_uint16; -#endif - -#ifndef YYPTRDIFF_T -# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ -# define YYPTRDIFF_T __PTRDIFF_TYPE__ -# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ -# elif defined PTRDIFF_MAX -# ifndef ptrdiff_t -# include /* INFRINGES ON USER NAME SPACE */ -# endif -# define YYPTRDIFF_T ptrdiff_t -# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX -# else -# define YYPTRDIFF_T long -# define YYPTRDIFF_MAXIMUM LONG_MAX -# endif -#endif - -#ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned -# endif -#endif - -#define YYSIZE_MAXIMUM \ - YY_CAST (YYPTRDIFF_T, \ - (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ - ? YYPTRDIFF_MAXIMUM \ - : YY_CAST (YYSIZE_T, -1))) - -#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) - -/* Stored state numbers (used for stacks). */ -typedef yytype_int16 yy_state_t; - -/* State numbers in computations. */ -typedef int yy_state_fast_t; - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) -# else -# define YY_ATTRIBUTE_PURE -# endif -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -# else -# define YY_ATTRIBUTE_UNUSED -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - -#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ -# define YY_IGNORE_USELESS_CAST_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") -# define YY_IGNORE_USELESS_CAST_END \ - _Pragma ("GCC diagnostic pop") -#endif -#ifndef YY_IGNORE_USELESS_CAST_BEGIN -# define YY_IGNORE_USELESS_CAST_BEGIN -# define YY_IGNORE_USELESS_CAST_END -#endif - - -#define YY_ASSERT(E) ((void) (0 && (E))) - -#if ! defined yyoverflow || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - - -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - yy_state_t yyss_alloc; - YYSTYPE yyvs_alloc; -}; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -# define YYCOPY_NEEDED 1 - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYPTRDIFF_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / YYSIZEOF (*yyptr); \ - } \ - while (0) - -#endif - -#if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from SRC to DST. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYPTRDIFF_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif -#endif /* !YYCOPY_NEEDED */ - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 5 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 224 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 65 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 94 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 173 -/* YYNSTATES -- Number of states. */ -#define YYNSTATES 272 - -#define YYUNDEFTOK 2 -#define YYMAXUTOK 302 - - -/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex. */ -static const yytype_int8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 52, 53, 49, 58, 51, 59, 48, 60, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 55, 54, - 56, 50, 57, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 61, 2, 62, 63, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 64, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47 -}; - -#if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_int16 yyrline[] = -{ - 0, 218, 218, 222, 229, 247, 252, 261, 265, 275, - 291, 306, 329, 339, 340, 341, 342, 343, 347, 367, - 377, 381, 388, 408, 416, 427, 432, 438, 479, 485, - 491, 495, 523, 572, 576, 586, 621, 630, 637, 644, - 646, 655, 693, 694, 741, 745, 749, 753, 757, 761, - 765, 772, 794, 823, 827, 832, 838, 842, 846, 853, - 854, 884, 888, 892, 896, 900, 907, 908, 912, 917, - 921, 926, 946, 951, 972, 992, 1011, 1017, 1025, 1043, - 1048, 1053, 1060, 1065, 1079, 1080, 1081, 1082, 1083, 1084, - 1085, 1087, 1093, 1136, 1154, 1162, 1170, 1181, 1204, 1217, - 1222, 1228, 1233, 1239, 1260, 1298, 1306, 1321, 1327, 1333, - 1337, 1353, 1362, 1409, 1418, 1432, 1517, 1524, 1529, 1535, - 1550, 1568, 1594, 1605, 1623, 1632, 1682, 1703, 1718, 1723, - 1729, 1734, 1740, 1744, 1745, 1749, 1750, 1754, 1766, 1772, - 1779, 1780, 1784, 1785, 1789, 1790, 1794, 1795, 1799, 1806, - 1812, 1818, 1823, 1856, 1876, 1882, 1901, 1906, 1912, 1916, - 1937, 1953, 1958, 1967, 1994, 2008, 2015, 2023, 2059, 2067, - 2078, 2153, 2158, 2164 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE || 1 -/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "TOKEN_START", "AND", "ARRAY", "BEGIN_", - "BY", "CASE", "CONST", "DIV", "DO", "ELSE", "ELSIF", "END", "FALSE", - "FOR", "IF", "IMPORT", "IS", "MOD", "MODULE", "NIL", "NOT", "OF", "OR", - "POINTER", "PROCEDURE", "RECORD", "REPEAT", "RETURN", "THEN", "TO", - "TRUE", "TYPE", "UNTIL", "VAR", "WHILE", "BECOMES", "DOTDOT", "GE", "LE", - "NOT_EQ", "IDENT", "INTEGER", "REAL", "STRING", "TOKEN_END", "'.'", - "'*'", "'='", "','", "'('", "')'", "';'", "':'", "'<'", "'>'", "'+'", - "'-'", "'/'", "'['", "']'", "'^'", "'|'", "$accept", "qualident", - "identdef", "ExportMarkOpt", "number", "ConstDeclaration", - "ConstExpression", "TypeDeclaration", "TypeIdentDef", "type", - "ArrayType", "ArrayLengthOf", "LengthRep", "length", "RecordType", - "RecordHeading", "BaseTypeOpt", "BaseType", "FieldListSequenceOpt", - "FieldListSequence", "FieldList", "IdentList", "PointerType", - "PointerTo", "ProcedureType", "ProcedureTypeSansParam", - "FormalParametersOpt", "VariableDeclaration", "expression", "relation", - "SimpleExpression", "SignOpt", "AddOperator", "term", "MulOperator", - "factor", "designator", "SelectorOptRep", "selector", "ExpList", - "statement", "assignment", "ProcedureCall", "StatementSequence", - "StatementSequenceReversed", "IfStatement", "guard", "ElseIfThenOptRep", - "ElseOpt", "CaseStatement", "CaseExpression", "CaseRep", "case", - "CaseLabelList", "LabelRange", "label", "WhileStatement", - "ElseIfDoOptRep", "RepeatStatement", "ForStatement", "ForInit", - "ForLimit", "ByOpt", "ProcedureDeclaration", "ProcedureHeading", - "ProcedureHeadingSansParam", "StatementSequenceOpt", - "ReturnExpressionOpt", "DeclarationSequence", "ConstSectionOpt", - "ConstDeclarationOptRep", "TypeSectionOpt", "TypeKeyword", - "TypeDeclarationOptRep", "VariableSectionOpt", - "VariableDeclarationOptRep", "ProcedureDeclarationOptRep", - "FormalParameters", "FPSectionsOpt", "FPSectionRep", "ResultTypeOpt", - "FPSection", "ParameterKindOpt", "IdentRep", "FormalType", - "OpenArrayOptRep", "module", "ModuleHeading", "ImportListOpt", - "ImportList", "ImportRep", "import", "BecomesIdentOpt", - "ModuleStatements", YY_NULLPTR -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[NUM] -- (External) token number corresponding to the - (internal) symbol number NUM (which must be that of a token). */ -static const yytype_int16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, 46, 42, - 61, 44, 40, 41, 59, 58, 60, 62, 43, 45, - 47, 91, 93, 94, 124 -}; -# endif - -#define YYPACT_NINF (-129) - -#define yypact_value_is_default(Yyn) \ - ((Yyn) == YYPACT_NINF) - -#define YYTABLE_NINF (-158) - -#define yytable_value_is_error(Yyn) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -7, -14, 19, -17, -129, -129, 31, 28, 53, -129, - 35, -16, -129, -129, 71, 50, 45, -129, 28, -129, - 47, 95, -129, 77, -129, 56, -129, -129, -129, 44, - 59, 40, 21, 67, 21, 95, 21, -129, 75, -129, - -129, -129, -129, 61, -129, -129, -129, -129, -129, 74, - -129, -129, 47, -129, -129, 21, -129, -129, -129, -129, - 64, 85, 92, 81, 93, -129, 96, 91, 122, -31, - 21, 95, 86, 47, 108, 89, 82, 15, -129, -129, - -129, -129, -129, -129, -129, -129, -129, -129, -129, -129, - 21, 85, -129, -129, 85, -129, -129, -129, -129, 21, - -129, 6, -129, -129, 24, 21, 21, 95, 21, 95, - 97, -2, 21, -129, -129, -129, -129, -129, -129, -27, - 87, 47, 88, 90, 94, -129, -129, 21, 111, -129, - 99, 100, -129, -129, -129, 15, -129, 47, -129, 15, - -129, 94, -12, 6, -129, 101, -129, -129, -129, -129, - -129, 85, -129, -129, -129, -5, -129, -24, -129, 106, - -129, -129, 140, -129, -129, -129, -129, -129, -129, 10, - -28, 47, 15, -129, -129, -129, 53, -21, -129, -129, - -129, -6, -129, -129, 112, -129, 113, -129, 135, 103, - -129, -3, -129, -129, -129, -129, -129, 24, 24, 95, - 24, 21, 147, 41, 73, 21, -129, -129, -129, -129, - 71, -129, 107, 105, -129, 118, -129, 21, -129, 109, - -129, -129, 47, 15, -129, -129, -129, -129, -129, 95, - 95, 21, 149, 21, -129, -129, 137, 110, 132, -129, - 9, -129, -129, -129, -129, 155, -129, 139, -129, 161, - 21, 159, 112, -129, -129, 131, -129, -129, 95, 95, - -129, 133, -129, -129, -129, 7, -129, -129, -129, 153, - -129, -129 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 0, 0, 0, 0, 164, 1, 166, 0, 134, 165, - 172, 0, 168, 136, 129, 138, 0, 170, 0, 167, - 133, 91, 173, 0, 139, 143, 141, 171, 169, 6, - 0, 0, 55, 0, 55, 91, 55, 76, 93, 95, - 84, 85, 128, 94, 86, 87, 88, 89, 90, 0, - 145, 147, 137, 5, 4, 55, 135, 53, 54, 104, - 42, 0, 0, 0, 0, 98, 0, 0, 0, 74, - 55, 91, 0, 142, 132, 0, 0, 0, 9, 10, - 50, 58, 49, 47, 45, 44, 46, 48, 56, 57, - 55, 0, 70, 68, 0, 69, 7, 8, 67, 55, - 66, 51, 59, 71, 108, 55, 55, 91, 55, 91, - 0, 55, 55, 79, 75, 92, 96, 163, 33, 0, - 0, 0, 0, 0, 40, 12, 140, 55, 0, 38, - 26, 2, 13, 11, 14, 0, 15, 29, 16, 0, - 17, 40, 43, 52, 73, 0, 65, 63, 64, 61, - 62, 0, 113, 114, 115, 0, 105, 0, 109, 111, - 121, 122, 124, 100, 119, 118, 77, 81, 82, 0, - 0, 0, 0, 144, 127, 146, 134, 150, 126, 39, - 22, 0, 20, 36, 0, 24, 0, 18, 0, 28, - 30, 0, 35, 37, 72, 60, 103, 108, 0, 91, - 0, 55, 0, 102, 0, 55, 80, 78, 34, 41, - 129, 156, 0, 149, 151, 0, 19, 55, 27, 0, - 3, 23, 0, 0, 106, 110, 107, 112, 123, 91, - 91, 55, 0, 55, 116, 83, 131, 154, 157, 158, - 0, 21, 25, 31, 32, 0, 101, 0, 97, 0, - 55, 0, 0, 148, 152, 0, 162, 120, 91, 91, - 130, 0, 153, 159, 155, 0, 99, 117, 125, 0, - 160, 161 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -129, -99, -19, -129, -129, -129, -51, -129, -129, -128, - -129, -129, -129, -39, -129, -129, -129, -129, -129, -129, - -43, 115, -129, -129, -129, -129, 39, -129, -30, -129, - 102, -129, -129, 98, -129, -86, -55, -129, -129, 69, - 114, -129, -129, -35, -129, -129, -33, -129, -129, -129, - -129, -129, -15, -129, -8, -9, -129, -129, -129, -129, - -129, -129, -129, -129, -129, -129, -26, -129, 17, -129, - -129, -129, -129, -129, -129, -129, -129, -129, -129, -129, - -129, -52, -129, -129, -129, -129, -129, -129, -129, -129, - -129, 165, -129, -129 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 132, 118, 54, 100, 31, 180, 76, 77, 133, - 134, 135, 181, 182, 136, 137, 185, 219, 188, 189, - 190, 191, 138, 139, 140, 141, 178, 120, 65, 90, - 60, 61, 91, 101, 151, 102, 38, 69, 114, 169, - 39, 40, 41, 42, 43, 44, 66, 203, 232, 45, - 62, 155, 156, 157, 158, 159, 46, 204, 47, 48, - 64, 162, 202, 122, 123, 124, 22, 251, 14, 15, - 20, 25, 26, 52, 51, 73, 74, 179, 212, 213, - 253, 214, 215, 240, 264, 265, 2, 3, 8, 9, - 11, 12, 17, 23 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 67, 30, 59, 68, 78, 154, 103, 187, 144, 196, - 146, 192, 269, 81, 1, 211, 147, 110, 216, 5, - 127, 111, -157, 205, 171, 79, 148, 198, 172, 4, - 112, 199, 113, 75, 207, 18, 103, 6, 19, 103, - 115, 128, 129, 130, 209, 217, 88, 89, 171, 7, - 131, 167, 223, 230, 231, 149, 57, 58, 131, 197, - 255, 205, 13, 206, 256, 195, 150, 131, 152, 145, - 153, 10, 163, 16, 165, 160, 161, 21, 164, 57, - 58, 168, 168, 80, 24, 218, 233, 234, 27, 81, - 29, 49, 50, 53, 56, 244, 103, 79, 154, 154, - 92, 154, 174, 32, 82, 83, 84, 93, 94, 55, - 63, 33, 34, 70, 85, 71, 104, 72, 95, 105, - 86, 87, 88, 89, 35, 106, 108, 107, 37, 96, - 97, 98, 36, 109, 117, 121, 126, 99, 37, 125, - 166, 173, 175, 183, 176, 200, 177, 201, 186, 221, - 228, 184, 208, 262, 194, 131, 220, 222, 229, 238, - 237, 239, 242, 248, 226, 252, 270, 250, 211, 257, - 258, 79, 259, 261, 263, 235, 268, 271, 241, 243, - 193, 170, 224, 28, 236, 116, 254, 79, 119, 143, - 225, 227, 142, 210, 245, 246, 0, 0, 247, 0, - 249, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 260, 0, 0, 266, 267 -}; - -static const yytype_int16 yycheck[] = -{ - 35, 20, 32, 36, 55, 104, 61, 135, 94, 14, - 4, 139, 5, 25, 21, 36, 10, 48, 24, 0, - 5, 52, 43, 51, 51, 55, 20, 51, 55, 43, - 61, 55, 63, 52, 62, 51, 91, 54, 54, 94, - 70, 26, 27, 28, 172, 51, 58, 59, 51, 18, - 43, 53, 55, 12, 13, 49, 58, 59, 43, 64, - 51, 51, 9, 53, 55, 151, 60, 43, 44, 99, - 46, 43, 107, 38, 109, 105, 106, 6, 108, 58, - 59, 111, 112, 19, 34, 184, 13, 14, 43, 25, - 43, 14, 36, 49, 54, 223, 151, 127, 197, 198, - 15, 200, 121, 8, 40, 41, 42, 22, 23, 50, - 43, 16, 17, 38, 50, 54, 24, 43, 33, 38, - 56, 57, 58, 59, 29, 32, 35, 31, 43, 44, - 45, 46, 37, 11, 48, 27, 54, 52, 43, 50, - 43, 54, 54, 32, 54, 39, 52, 7, 48, 14, - 201, 52, 171, 252, 53, 43, 43, 54, 11, 54, - 53, 43, 53, 14, 199, 55, 265, 30, 36, 14, - 31, 201, 11, 14, 43, 205, 43, 24, 217, 222, - 141, 112, 197, 18, 210, 71, 238, 217, 73, 91, - 198, 200, 90, 176, 229, 230, -1, -1, 231, -1, - 233, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 250, -1, -1, 258, 259 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 21, 151, 152, 43, 0, 54, 18, 153, 154, - 43, 155, 156, 9, 133, 134, 38, 157, 51, 54, - 135, 6, 131, 158, 34, 136, 137, 43, 156, 43, - 67, 70, 8, 16, 17, 29, 37, 43, 101, 105, - 106, 107, 108, 109, 110, 114, 121, 123, 124, 14, - 36, 139, 138, 49, 68, 50, 54, 58, 59, 93, - 95, 96, 115, 43, 125, 93, 111, 108, 111, 102, - 38, 54, 43, 140, 141, 67, 72, 73, 71, 93, - 19, 25, 40, 41, 42, 50, 56, 57, 58, 59, - 94, 97, 15, 22, 23, 33, 44, 45, 46, 52, - 69, 98, 100, 101, 24, 38, 32, 31, 35, 11, - 48, 52, 61, 63, 103, 93, 105, 48, 67, 86, - 92, 27, 128, 129, 130, 50, 54, 5, 26, 27, - 28, 43, 66, 74, 75, 76, 79, 80, 87, 88, - 89, 90, 95, 98, 100, 93, 4, 10, 20, 49, - 60, 99, 44, 46, 66, 116, 117, 118, 119, 120, - 93, 93, 126, 108, 93, 108, 43, 53, 93, 104, - 104, 51, 55, 54, 67, 54, 54, 52, 91, 142, - 71, 77, 78, 32, 52, 81, 48, 74, 83, 84, - 85, 86, 74, 91, 53, 100, 14, 64, 51, 55, - 39, 7, 127, 112, 122, 51, 53, 62, 67, 74, - 133, 36, 143, 144, 146, 147, 24, 51, 66, 82, - 43, 14, 54, 55, 117, 119, 108, 120, 71, 11, - 12, 13, 113, 13, 14, 93, 131, 53, 54, 43, - 148, 78, 53, 85, 74, 108, 108, 111, 14, 111, - 30, 132, 55, 145, 146, 51, 55, 14, 31, 11, - 93, 14, 66, 43, 149, 150, 108, 108, 43, 5, - 66, 24 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 65, 66, 66, 67, 68, 68, 69, 69, 70, - 71, 72, 73, 74, 74, 74, 74, 74, 75, 76, - 77, 77, 78, 79, 80, 81, 81, 82, 83, 83, - 84, 84, 85, 86, 86, 87, 88, 89, 90, 91, - 91, 92, 93, 93, 94, 94, 94, 94, 94, 94, - 94, 95, 95, 96, 96, 96, 97, 97, 97, 98, - 98, 99, 99, 99, 99, 99, 100, 100, 100, 100, - 100, 100, 100, 100, 101, 102, 102, 103, 103, 103, - 103, 103, 104, 104, 105, 105, 105, 105, 105, 105, - 105, 105, 106, 107, 108, 109, 109, 110, 111, 112, - 112, 113, 113, 114, 115, 116, 116, 117, 117, 118, - 118, 119, 119, 120, 120, 120, 121, 122, 122, 123, - 124, 125, 126, 127, 127, 128, 129, 130, 131, 131, - 132, 132, 133, 134, 134, 135, 135, 136, 136, 137, - 138, 138, 139, 139, 140, 140, 141, 141, 142, 143, - 143, 144, 144, 145, 145, 146, 147, 147, 148, 148, - 149, 150, 150, 151, 152, 153, 153, 154, 155, 155, - 156, 157, 157, 158 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_int8 yyr2[] = -{ - 0, 2, 1, 3, 2, 1, 0, 1, 1, 3, - 1, 2, 2, 1, 1, 1, 1, 1, 2, 3, - 1, 3, 1, 3, 2, 3, 0, 1, 1, 0, - 1, 3, 3, 1, 3, 2, 2, 2, 1, 1, - 0, 3, 1, 3, 1, 1, 1, 1, 1, 1, - 1, 2, 3, 1, 1, 0, 1, 1, 1, 1, - 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 3, 2, 2, 2, 0, 2, 3, 1, - 3, 2, 1, 3, 1, 1, 1, 1, 1, 1, - 1, 0, 3, 1, 1, 1, 3, 7, 1, 5, - 0, 2, 0, 5, 1, 1, 3, 3, 0, 1, - 3, 1, 3, 1, 1, 1, 6, 5, 0, 4, - 8, 3, 1, 2, 0, 7, 2, 2, 2, 0, - 2, 0, 4, 2, 0, 3, 0, 2, 0, 1, - 3, 0, 2, 0, 3, 0, 3, 0, 4, 1, - 0, 1, 3, 2, 0, 4, 1, 0, 1, 3, - 2, 3, 0, 8, 2, 1, 0, 3, 1, 3, - 2, 2, 0, 1 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ - do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ - while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -/* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif - - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - - -/*-----------------------------------. -| Print this symbol's value on YYO. | -`-----------------------------------*/ - -static void -yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) -{ - FILE *yyoutput = yyo; - YYUSE (yyoutput); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyo, yytoknum[yytype], *yyvaluep); -# endif - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - -/*---------------------------. -| Print this symbol on YYO. | -`---------------------------*/ - -static void -yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep) -{ - YYFPRINTF (yyo, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyo, yytype, yyvaluep); - YYFPRINTF (yyo, ")"); -} - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (included). | -`------------------------------------------------------------------*/ - -static void -yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) -{ - int yylno = yyrline[yyrule]; - int yynrhs = yyr2[yyrule]; - int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", - yyrule - 1, yylno); - /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[+yyssp[yyi + 1 - yynrhs]], - &yyvsp[(yyi + 1) - (yynrhs)] - ); - YYFPRINTF (stderr, "\n"); - } -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) -# else -/* Return the length of YYSTR. */ -static YYPTRDIFF_T -yystrlen (const char *yystr) -{ - YYPTRDIFF_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif - -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYPTRDIFF_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYPTRDIFF_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (yyres) - return yystpcpy (yyres, yystr) - yyres; - else - return yystrlen (yystr); -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, - yy_state_t *yyssp, int yytoken) -{ - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat: reported tokens (one for the "unexpected", - one per "expected"). */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Actual size of YYARG. */ - int yycount = 0; - /* Cumulated lengths of YYARG. */ - YYPTRDIFF_T yysize = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[+*yyssp]; - YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - yysize = yysize0; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYPTRDIFF_T yysize1 - = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - default: /* Avoid compiler warnings. */ - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - /* Don't count the "%s"s in the final size, but reserve room for - the terminator. */ - YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; - if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) - yysize = yysize1; - else - return 2; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - ++yyp; - ++yyformat; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ - -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) -{ - YYUSE (yyvaluep); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); - YY_IGNORE_MAYBE_UNINITIALIZED_END -} - - - - -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; -/* Number of syntax errors so far. */ -int yynerrs; - - -/*----------. -| yyparse. | -`----------*/ - -int -yyparse (void) -{ - yy_state_fast_t yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - yy_state_t yyssa[YYINITDEPTH]; - yy_state_t *yyss; - yy_state_t *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYPTRDIFF_T yystacksize; - - int yyn; - int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; -#endif - -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) - - /* The number of symbols on the RHS of the reduced rule. - Keep to zero when no symbol should be popped. */ - int yylen = 0; - - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - goto yysetstate; - - -/*------------------------------------------------------------. -| yynewstate -- push a new state, which is found in yystate. | -`------------------------------------------------------------*/ -yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. So pushing a state here evens the stacks. */ - yyssp++; - - -/*--------------------------------------------------------------------. -| yysetstate -- set current state (the top of the stack) to yystate. | -`--------------------------------------------------------------------*/ -yysetstate: - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - YY_ASSERT (0 <= yystate && yystate < YYNSTATES); - YY_IGNORE_USELESS_CAST_BEGIN - *yyssp = YY_CAST (yy_state_t, yystate); - YY_IGNORE_USELESS_CAST_END - - if (yyss + yystacksize - 1 <= yyssp) -#if !defined yyoverflow && !defined YYSTACK_RELOCATE - goto yyexhaustedlab; -#else - { - /* Get the current used size of the three stacks, in elements. */ - YYPTRDIFF_T yysize = yyssp - yyss + 1; - -# if defined yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - yy_state_t *yyss1 = yyss; - YYSTYPE *yyvs1 = yyvs; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * YYSIZEOF (*yyssp), - &yyvs1, yysize * YYSIZEOF (*yyvsp), - &yystacksize); - yyss = yyss1; - yyvs = yyvs1; - } -# else /* defined YYSTACK_RELOCATE */ - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yy_state_t *yyss1 = yyss; - union yyalloc *yyptr = - YY_CAST (union yyalloc *, - YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - YY_IGNORE_USELESS_CAST_BEGIN - YYDPRINTF ((stderr, "Stack size increased to %ld\n", - YY_CAST (long, yystacksize))); - YY_IGNORE_USELESS_CAST_END - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } -#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - - if (yystate == YYFINAL) - YYACCEPT; - - goto yybackup; - - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - /* Do appropriate processing given the current state. Read a - lookahead token if we need one and don't already have one. */ - - /* First try to decide what to do without reference to lookahead token. */ - yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (); - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - /* Discard the shifted token. */ - yychar = YYEMPTY; - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - '$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 2: -#line 219 "Oberon.y" - { - (yyval.node) = Trees_NewIdent((yyvsp[0].ident)); - } -#line 1713 "y.tab.c" - break; - - case 3: -#line 223 "Oberon.y" - { - (yyval.node) = Trees_NewIdent(Util_String("%s.%s", (yyvsp[-2].ident), (yyvsp[0].ident))); - } -#line 1721 "y.tab.c" - break; - - case 4: -#line 230 "Oberon.y" - { - if (! Table_LocallyDeclared((yyvsp[-1].ident)) || (recordDeclarationStack != NULL)) { - (yyval.node) = Trees_NewIdent((yyvsp[-1].ident)); - if ((yyvsp[0].integer)) { - Trees_SetExported((yyval.node)); - } - if (Table_ScopeLocal()) { - Trees_SetLocal((yyval.node)); - } - } else { - Oberon_PrintError("error: redeclaration of identifier: %s", (yyvsp[-1].ident)); - YYABORT; - } - } -#line 1740 "y.tab.c" - break; - - case 5: -#line 248 "Oberon.y" - { - (yyval.integer) = 1; - } -#line 1748 "y.tab.c" - break; - - case 6: -#line 252 "Oberon.y" - { - (yyval.integer) = 0; - } -#line 1756 "y.tab.c" - break; - - case 7: -#line 262 "Oberon.y" - { - (yyval.node) = Trees_NewInteger((yyvsp[0].integer)); - } -#line 1764 "y.tab.c" - break; - - case 8: -#line 266 "Oberon.y" - { - (yyval.node) = Trees_NewReal((yyvsp[0].real)); - } -#line 1772 "y.tab.c" - break; - - case 9: -#line 276 "Oberon.y" - { - if (! (Trees_Exported((yyvsp[-2].node)) && Trees_Local((yyvsp[-2].node)))) { - Trees_SetKind(TREES_CONSTANT_KIND, (yyvsp[-2].node)); - Trees_SetType(Trees_Type((yyvsp[0].node)), (yyvsp[-2].node)); - Trees_SetValue((yyvsp[0].node), (yyvsp[-2].node)); - Table_Put((yyvsp[-2].node)); - Generate_ConstDeclaration((yyvsp[-2].node)); - } else { - Oberon_PrintError("error: cannot export local constant: %s", Trees_Name((yyvsp[-2].node))); - YYABORT; - } - } -#line 1789 "y.tab.c" - break; - - case 10: -#line 292 "Oberon.y" - { - if (IsConstExpression((yyvsp[0].node))) { - (yyval.node) = (yyvsp[0].node); - } else { - Oberon_PrintError("error: constant expression expected"); - YYABORT; - } - } -#line 1802 "y.tab.c" - break; - - case 11: -#line 307 "Oberon.y" - { - Trees_Node sourceType; - - sourceType = ResolvedType((yyvsp[0].node), 1); - if (sourceType != NULL) { - if (! (Trees_Exported((yyvsp[-1].node)) && Trees_Local((yyvsp[-1].node)))) { - Trees_SetType(sourceType, (yyvsp[-1].node)); - ResolvePointerTypes((yyvsp[-1].node)); - currentTypeIdentdef = NULL; - Generate_TypeDeclaration((yyvsp[-1].node)); - } else { - Oberon_PrintError("error: cannot export local type: %s", Trees_Name((yyvsp[-1].node))); - YYABORT; - } - } else { - Oberon_PrintError("error: 8 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } -#line 1826 "y.tab.c" - break; - - case 12: -#line 330 "Oberon.y" - { - Trees_SetKind(TREES_TYPE_KIND, (yyvsp[-1].node)); - currentTypeIdentdef = (yyvsp[-1].node); - Table_Put((yyvsp[-1].node)); - (yyval.node) = (yyvsp[-1].node); - } -#line 1837 "y.tab.c" - break; - - case 18: -#line 348 "Oberon.y" - { - Trees_Node reversedLengths, length; - - (yyval.node) = ResolvedType((yyvsp[0].node), 0); - if ((yyval.node) != NULL) { - reversedLengths = (yyvsp[-1].node); - do { - length = Trees_Left(reversedLengths); - (yyval.node) = Types_NewArray(length, (yyval.node)); - reversedLengths = Trees_Right(reversedLengths); - } while (reversedLengths != NULL); - } else { - Oberon_PrintError("error: 10 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - exit(EXIT_FAILURE); - } - } -#line 1858 "y.tab.c" - break; - - case 19: -#line 368 "Oberon.y" - { - if ((currentTypeIdentdef != NULL) && (Trees_Type(currentTypeIdentdef) == NULL)) { - Trees_SetType(Trees_NewLeaf(ARRAY), currentTypeIdentdef); /*incomplete type*/ - } - (yyval.node) = (yyvsp[-1].node); - } -#line 1869 "y.tab.c" - break; - - case 20: -#line 378 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), NULL); - } -#line 1877 "y.tab.c" - break; - - case 21: -#line 382 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), (yyvsp[-2].node)); - } -#line 1885 "y.tab.c" - break; - - case 22: -#line 389 "Oberon.y" - { - if (Types_IsInteger(Trees_Type((yyvsp[0].node)))) { - if (IsInteger((yyvsp[0].node))) { - if (Trees_Integer((yyvsp[0].node)) <= 0) { - Oberon_PrintError("error: positive length expected: %" OBNC_INT_MOD "d", Trees_Integer((yyvsp[0].node))); - YYABORT; - } - } else { - Oberon_PrintError("error: fully evaluated constant expression expected as increment"); - YYABORT; - } - } else { - Oberon_PrintError("error: integer length expected"); - YYABORT; - } - } -#line 1906 "y.tab.c" - break; - - case 23: -#line 409 "Oberon.y" - { - recordDeclarationStack = Trees_Right(recordDeclarationStack); - (yyval.node) = Types_NewRecord(Types_RecordBaseType((yyvsp[-2].node)), (yyvsp[-1].node)); - } -#line 1915 "y.tab.c" - break; - - case 24: -#line 417 "Oberon.y" - { - (yyval.node) = Types_NewRecord((yyvsp[0].node), NULL); - if ((currentTypeIdentdef != NULL) && (Trees_Type(currentTypeIdentdef) == NULL)) { - Trees_SetType((yyval.node), currentTypeIdentdef); - } - recordDeclarationStack = Trees_NewNode(TREES_NOSYM, (yyval.node), recordDeclarationStack); - } -#line 1927 "y.tab.c" - break; - - case 25: -#line 428 "Oberon.y" - { - (yyval.node) = (yyvsp[-1].node); - } -#line 1935 "y.tab.c" - break; - - case 26: -#line 432 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 1943 "y.tab.c" - break; - - case 27: -#line 439 "Oberon.y" - { - const char *name; - Trees_Node symbol; - - (yyval.node) = NULL; - name = Trees_Name((yyvsp[0].node)); - symbol = Table_At(name); - if (symbol != NULL) { - if (Trees_Kind(symbol) == TREES_TYPE_KIND) { - if (symbol != currentTypeIdentdef) { - switch (Trees_Symbol(Types_Structure(symbol))) { - case POINTER: - if (Types_Same(Types_PointerBaseType(symbol), currentTypeIdentdef)) { - Oberon_PrintError("error: self-referring base type: %s", name); - YYABORT; - } - /*fall through*/ - case RECORD: - (yyval.node) = symbol; - break; - default: - Oberon_PrintError("error: record or pointer base type expected: %s", name); - YYABORT; - } - } else { - Oberon_PrintError("error: self-referring base type: %s", name); - YYABORT; - } - } else { - Oberon_PrintError("error: type name expected: %s", name); - YYABORT; - } - } else { - Oberon_PrintError("error: 11 undeclared identifier: %s", name); - YYABORT; - } - } -#line 1985 "y.tab.c" - break; - - case 28: -#line 480 "Oberon.y" - { - Trees_ReverseList(&(yyvsp[0].node)); /*correct order*/ - (yyval.node) = (yyvsp[0].node); - } -#line 1994 "y.tab.c" - break; - - case 29: -#line 485 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2002 "y.tab.c" - break; - - case 30: -#line 492 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_FIELD_LIST_SEQUENCE, (yyvsp[0].node), NULL); - } -#line 2010 "y.tab.c" - break; - - case 31: -#line 496 "Oberon.y" - { - Trees_Node currSeq, currList, currSeqList; - const char *seqIdentName, *listIdentName; - - currList = (yyvsp[0].node); - while (currList != NULL) { - listIdentName = Trees_Name(Trees_Left(currList)); - currSeq = (yyvsp[-2].node); - while (currSeq != NULL) { - currSeqList = Trees_Left(currSeq); - while (currSeqList != NULL) { - seqIdentName = Trees_Name(Trees_Left(currSeqList)); - if (strcmp(listIdentName, seqIdentName) == 0) { - Oberon_PrintError("error: redeclaration of field: %s", listIdentName); - YYABORT; - } - currSeqList = Trees_Right(currSeqList); - } - currSeq = Trees_Right(currSeq); - } - currList = Trees_Right(currList); - } - (yyval.node) = Trees_NewNode(TREES_FIELD_LIST_SEQUENCE, (yyvsp[0].node), (yyvsp[-2].node)); - } -#line 2039 "y.tab.c" - break; - - case 32: -#line 524 "Oberon.y" - { - Trees_Node type, tail, ident, p, directBaseType, baseTypeField, baseType; - - (yyval.node) = NULL; - type = ResolvedType((yyvsp[0].node), 0); - if (type != NULL) { - if (! ((type == currentTypeIdentdef) && ! Types_IsPointer(type))) { - Trees_ReverseList(&(yyvsp[-2].node)); /*correct order*/ - tail = (yyvsp[-2].node); - do { - ident = Trees_Left(tail); - p = (yyvsp[-2].node); - while ((p != tail) && (strcmp(Trees_Name(ident), Trees_Name(Trees_Left(p))) != 0)) { - p = Trees_Right(p); - } - if (p == tail) { - assert(recordDeclarationStack != NULL); - directBaseType = Types_RecordBaseType(Trees_Left(recordDeclarationStack)); - if (directBaseType != NULL) { - Types_GetFieldIdent(Trees_Name(ident), directBaseType, 0, &baseTypeField, &baseType); - } - if ((directBaseType == NULL) || (baseTypeField == NULL)) { - Trees_SetKind(TREES_FIELD_KIND, ident); - Trees_SetType(type, ident); - } else { - Oberon_PrintError("error: redeclaration of field: %s defined in %s", Trees_Name(ident), Trees_Name(baseType)); - YYABORT; - } - } else { - Oberon_PrintError("error: redeclaration of field: %s", Trees_Name(ident)); - YYABORT; - } - tail = Trees_Right(tail); - } while (tail != NULL); - - (yyval.node) = (yyvsp[-2].node); - } else { - Oberon_PrintError("error: recursive field type must be a pointer: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } else { - Oberon_PrintError("error: undeclared type: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } -#line 2089 "y.tab.c" - break; - - case 33: -#line 573 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_IDENT_LIST, (yyvsp[0].node), NULL); - } -#line 2097 "y.tab.c" - break; - - case 34: -#line 577 "Oberon.y" - { - Trees_Node reversedIdents; - - reversedIdents = Trees_NewNode(TREES_IDENT_LIST, (yyvsp[0].node), (yyvsp[-2].node)); - (yyval.node) = reversedIdents; - } -#line 2108 "y.tab.c" - break; - - case 35: -#line 587 "Oberon.y" - { - const char *baseTypeName; - Trees_Node declaredBaseType; - - (yyval.node) = NULL; - if (Trees_Symbol((yyvsp[0].node)) == IDENT) { - baseTypeName = Trees_Name((yyvsp[0].node)); - declaredBaseType = Table_At(baseTypeName); - if (declaredBaseType != NULL) { - if (Types_IsRecord(declaredBaseType)) { - (yyval.node) = Types_NewPointer(declaredBaseType); - } else { - Oberon_PrintError("error: record expected as pointer base type: %s", baseTypeName); - YYABORT; - } - } else if (currentTypeIdentdef != NULL) { - Trees_SetKind(TREES_TYPE_KIND, (yyvsp[0].node)); - Trees_SetType(Types_NewRecord(NULL, NULL), (yyvsp[0].node)); - (yyval.node) = Types_NewPointer((yyvsp[0].node)); - unresolvedPointerTypes = Trees_NewNode(TREES_NOSYM, (yyval.node), unresolvedPointerTypes); - } else { - Oberon_PrintError("error: undeclared type: %s", baseTypeName); - YYABORT; - } - } else if(Trees_Symbol((yyvsp[0].node)) == RECORD) { - (yyval.node) = Types_NewPointer((yyvsp[0].node)); - } else { - Oberon_PrintError("error: record expected as pointer base type"); - YYABORT; - } - } -#line 2144 "y.tab.c" - break; - - case 36: -#line 622 "Oberon.y" - { - if ((currentTypeIdentdef != NULL) && (Trees_Type(currentTypeIdentdef) == NULL)) { - Trees_SetType(Types_NewPointer(NULL), currentTypeIdentdef); /*incomplete type*/ - } - } -#line 2154 "y.tab.c" - break; - - case 37: -#line 631 "Oberon.y" - { - (yyval.node) = (yyvsp[0].node); - } -#line 2162 "y.tab.c" - break; - - case 38: -#line 638 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2170 "y.tab.c" - break; - - case 40: -#line 646 "Oberon.y" - { - (yyval.node) = Trees_NewLeaf(PROCEDURE); - } -#line 2178 "y.tab.c" - break; - - case 41: -#line 656 "Oberon.y" - { - Trees_Node type, identList, ident; - - type = ResolvedType((yyvsp[0].node), 0); - if (type != NULL) { - Trees_ReverseList(&(yyvsp[-2].node)); /*correct order*/ - identList = (yyvsp[-2].node); - do { - ident = Trees_Left(identList); - if (! (Trees_Exported(ident) && Trees_Local(ident))) { - if (! Table_LocallyDeclared(Trees_Name(ident))) { - Trees_SetKind(TREES_VARIABLE_KIND, ident); - Trees_SetType(type, ident); - Table_Put(ident); - } else { - Oberon_PrintError("error: redeclaration of identifier with the same name: %s", Trees_Name(ident)); - YYABORT; - } - } else { - Oberon_PrintError("error: cannot export local variable: %s", Trees_Name(ident)); - YYABORT; - } - identList = Trees_Right(identList); - } while (identList != NULL); - - Generate_VariableDeclaration((yyvsp[-2].node)); - } else { - Oberon_PrintError("error: 1 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - exit(EXIT_FAILURE); - } - } -#line 2214 "y.tab.c" - break; - - case 43: -#line 695 "Oberon.y" - { - Trees_Node expA, expB, typeA, typeB; - int op = (int) (yyvsp[-1].integer); - - expA = (yyvsp[-2].node); - expB = (yyvsp[0].node); - typeA = Trees_Type((yyvsp[-2].node)); - typeB = Trees_Type((yyvsp[0].node)); - - CheckIsValueExpression((yyvsp[-2].node)); - if (op == IS) { - if (IsDesignator((yyvsp[-2].node))) { - if (! (Types_IsRecord(typeA) && (Trees_Kind(BaseIdent((yyvsp[-2].node))) != TREES_VAR_PARAM_KIND))) { - expB = BaseIdent((yyvsp[0].node)); - typeB = BaseIdent((yyvsp[0].node)); - } else { - Oberon_PrintError("error: variable parameter expected as first operand of IS"); - YYABORT; - } - } else { - Oberon_PrintError("error: identifier expected as first operand of IS"); - YYABORT; - } - } else { - CheckIsValueExpression((yyvsp[0].node)); - } - if (Types_ExpressionCompatible(op, typeA, typeB)) { - (yyval.node) = ExpressionConstValue(op, expA, expB); - if ((yyval.node) == NULL) { - if (IsString(expA) && Types_IsChar(typeB)) { - expA = Trees_NewChar(Trees_String(expA)[0]); - } else if (Types_IsChar(typeA) && IsString(expB)) { - expB = Trees_NewChar(Trees_String(expB)[0]); - } - (yyval.node) = Trees_NewNode(op, expA, expB); - Trees_SetType(Trees_NewLeaf(TREES_BOOLEAN_TYPE), (yyval.node)); - } - } else { - Oberon_PrintError("error: incompatible types in relation \"%s\": %s, %s", - OperatorString(op), TypeString(typeA), TypeString(typeB)); - YYABORT; - } - } -#line 2262 "y.tab.c" - break; - - case 44: -#line 742 "Oberon.y" - { - (yyval.integer) = '='; - } -#line 2270 "y.tab.c" - break; - - case 45: -#line 746 "Oberon.y" - { - (yyval.integer) = NOT_EQ; - } -#line 2278 "y.tab.c" - break; - - case 46: -#line 750 "Oberon.y" - { - (yyval.integer) = '<'; - } -#line 2286 "y.tab.c" - break; - - case 47: -#line 754 "Oberon.y" - { - (yyval.integer) = LE; - } -#line 2294 "y.tab.c" - break; - - case 48: -#line 758 "Oberon.y" - { - (yyval.integer) = '>'; - } -#line 2302 "y.tab.c" - break; - - case 49: -#line 762 "Oberon.y" - { - (yyval.integer) = GE; - } -#line 2310 "y.tab.c" - break; - - case 50: -#line 766 "Oberon.y" - { - (yyval.integer) = IS; - } -#line 2318 "y.tab.c" - break; - - case 51: -#line 773 "Oberon.y" - { - int op = (int) (yyvsp[-1].integer); - (yyval.node) = (yyvsp[0].node); - if (op >= 0) { - CheckIsValueExpression((yyvsp[0].node)); - if (Types_ExpressionCompatible(op, Trees_Type((yyvsp[0].node)), NULL)) { - (yyval.node) = SimpleExpressionConstValue(op, (yyvsp[0].node), NULL); - if ((yyval.node) == NULL) { - (yyval.node) = Trees_NewNode(op, (yyvsp[0].node), NULL); - if (Types_IsByte(Trees_Type((yyvsp[0].node)))) { - Trees_SetType(Trees_NewLeaf(TREES_INTEGER_TYPE), (yyval.node)); - } else { - Trees_SetType(Trees_Type((yyvsp[0].node)), (yyval.node)); - } - } - } else { - Oberon_PrintError("error: incompatible type in unary operation \"%s\": %s", OperatorString(op), TypeString(Trees_Type((yyvsp[0].node)))); - YYABORT; - } - } - } -#line 2344 "y.tab.c" - break; - - case 52: -#line 795 "Oberon.y" - { - int op = (int) (yyvsp[-1].integer); - - (yyval.node) = NULL; - - CheckIsValueExpression((yyvsp[-2].node)); - CheckIsValueExpression((yyvsp[0].node)); - - if (Types_ExpressionCompatible(op, Trees_Type((yyvsp[-2].node)), Trees_Type((yyvsp[0].node)))) { - (yyval.node) = SimpleExpressionConstValue(op, (yyvsp[-2].node), (yyvsp[0].node)); - if ((yyval.node) == NULL) { - (yyval.node) = Trees_NewNode(op, (yyvsp[-2].node), (yyvsp[0].node)); - if (Types_IsByte(Trees_Type((yyvsp[-2].node))) || Types_IsByte(Trees_Type((yyvsp[0].node)))) { - Trees_SetType(Trees_NewLeaf(TREES_INTEGER_TYPE), (yyval.node)); - } else { - Trees_SetType(Trees_Type((yyvsp[-2].node)), (yyval.node)); - } - } - } else { - Oberon_PrintError("error: incompatible types in operation \"%s\": %s, %s", - OperatorString(op), TypeString(Trees_Type((yyvsp[-2].node))), TypeString(Trees_Type((yyvsp[0].node)))); - YYABORT; - } - assert((yyval.node) != NULL); - } -#line 2374 "y.tab.c" - break; - - case 53: -#line 824 "Oberon.y" - { - (yyval.integer) = '+'; - } -#line 2382 "y.tab.c" - break; - - case 54: -#line 828 "Oberon.y" - { - (yyval.integer) = '-'; - } -#line 2390 "y.tab.c" - break; - - case 55: -#line 832 "Oberon.y" - { - (yyval.integer) = -1; - } -#line 2398 "y.tab.c" - break; - - case 56: -#line 839 "Oberon.y" - { - (yyval.integer) = '+'; - } -#line 2406 "y.tab.c" - break; - - case 57: -#line 843 "Oberon.y" - { - (yyval.integer) = '-'; - } -#line 2414 "y.tab.c" - break; - - case 58: -#line 847 "Oberon.y" - { - (yyval.integer) = OR; - } -#line 2422 "y.tab.c" - break; - - case 60: -#line 855 "Oberon.y" - { - int op = (int) (yyvsp[-1].integer); - - (yyval.node) = NULL; - - CheckIsValueExpression((yyvsp[-2].node)); - CheckIsValueExpression((yyvsp[0].node)); - - if (Types_ExpressionCompatible(op, Trees_Type((yyvsp[-2].node)), Trees_Type((yyvsp[0].node)))) { - (yyval.node) = TermConstValue(op, (yyvsp[-2].node), (yyvsp[0].node)); - if ((yyval.node) == NULL) { - (yyval.node) = Trees_NewNode(op, (yyvsp[-2].node), (yyvsp[0].node)); - if (Types_IsByte(Trees_Type((yyvsp[-2].node))) || Types_IsByte(Trees_Type((yyvsp[0].node)))) { - Trees_SetType(Trees_NewLeaf(TREES_INTEGER_TYPE), (yyval.node)); - } else { - Trees_SetType(Trees_Type((yyvsp[-2].node)), (yyval.node)); - } - } - } else { - Oberon_PrintError("error: incompatible types in operation \"%s\": %s, %s", - OperatorString(op), TypeString(Trees_Type((yyvsp[-2].node))), TypeString(Trees_Type((yyvsp[0].node)))); - YYABORT; - } - - assert((yyval.node) != NULL); - } -#line 2453 "y.tab.c" - break; - - case 61: -#line 885 "Oberon.y" - { - (yyval.integer) = '*'; - } -#line 2461 "y.tab.c" - break; - - case 62: -#line 889 "Oberon.y" - { - (yyval.integer) = '/'; - } -#line 2469 "y.tab.c" - break; - - case 63: -#line 893 "Oberon.y" - { - (yyval.integer) = DIV; - } -#line 2477 "y.tab.c" - break; - - case 64: -#line 897 "Oberon.y" - { - (yyval.integer) = MOD; - } -#line 2485 "y.tab.c" - break; - - case 65: -#line 901 "Oberon.y" - { - (yyval.integer) = AND; - } -#line 2493 "y.tab.c" - break; - - case 67: -#line 909 "Oberon.y" - { - (yyval.node) = Trees_NewString((yyvsp[0].string)); - } -#line 2501 "y.tab.c" - break; - - case 68: -#line 913 "Oberon.y" - { - (yyval.node) = Trees_NewLeaf(NIL); - Trees_SetType(Trees_NewLeaf(TREES_NIL_TYPE), (yyval.node)); - } -#line 2510 "y.tab.c" - break; - - case 69: -#line 918 "Oberon.y" - { - (yyval.node) = Trees_NewBoolean(1); - } -#line 2518 "y.tab.c" - break; - - case 70: -#line 922 "Oberon.y" - { - (yyval.node) = Trees_NewBoolean(0); - } -#line 2526 "y.tab.c" - break; - - case 71: -#line 927 "Oberon.y" - { - const int isFunctionCall = 1; - Trees_Node designator, actualParameters, ident; - - (yyval.node) = NULL; - if (Trees_Symbol((yyvsp[0].node)) == TREES_PROCEDURE_CALL) { - designator = Trees_Left((yyvsp[0].node)); - actualParameters = Trees_Right((yyvsp[0].node)); - HandleProcedureCall(designator, actualParameters, isFunctionCall, &(yyval.node)); - } else { - ident = Trees_Left((yyvsp[0].node)); - if (Trees_Kind(ident) == TREES_CONSTANT_KIND) { - (yyval.node) = Trees_Value(ident); - } else { - (yyval.node) = (yyvsp[0].node); - } - } - assert((yyval.node) != NULL); - } -#line 2550 "y.tab.c" - break; - - case 72: -#line 947 "Oberon.y" - { - CheckIsValueExpression((yyvsp[-1].node)); - (yyval.node) = (yyvsp[-1].node); - } -#line 2559 "y.tab.c" - break; - - case 73: -#line 952 "Oberon.y" - { - (yyval.node) = NULL; - CheckIsValueExpression((yyvsp[0].node)); - if (Types_ExpressionCompatible(NOT, Trees_Type((yyvsp[0].node)), NULL)) { - if (IsBoolean((yyvsp[0].node))) { - (yyval.node) = Trees_NewBoolean(! Trees_Boolean((yyvsp[0].node))); - } else { - (yyval.node) = Trees_NewNode(NOT, (yyvsp[0].node), NULL); - Trees_SetType(Trees_NewLeaf(TREES_BOOLEAN_TYPE), (yyval.node)); - } - } else { - Oberon_PrintError("error: incompatible type in operation \"not\": %s", TypeString(Trees_Type((yyvsp[0].node)))); - YYABORT; - } - assert((yyval.node) != NULL); - } -#line 2580 "y.tab.c" - break; - - case 74: -#line 973 "Oberon.y" - { - Trees_Node designator, identType, actualParameters; - int parameterListFound; /*possibly empty*/ - - Trees_ReverseList(&(yyvsp[0].node)); /*correct order*/ - designator = Designator((yyvsp[-1].ident), (yyvsp[0].node)); - - identType = Trees_Type(BaseIdent(designator)); - SetSelectorTypes(identType, designator, ¶meterListFound); - if (parameterListFound) { - RemoveActualParameters(&designator, &actualParameters); - (yyval.node) = Trees_NewNode(TREES_PROCEDURE_CALL, designator, actualParameters); - } else { - (yyval.node) = designator; - } - } -#line 2601 "y.tab.c" - break; - - case 75: -#line 993 "Oberon.y" - { - Trees_Node curr; - - if ((Trees_Symbol((yyvsp[0].node)) == '[') && (Trees_Right((yyvsp[0].node)) != NULL)) { /*multi-dimensional element selector*/ - /*attatch last element selector node to $1*/ - Trees_ReverseList(&(yyvsp[0].node)); - (yyval.node) = (yyvsp[-1].node); - curr = (yyvsp[0].node); - do { - (yyval.node) = Trees_NewNode('[', Trees_Left(curr), (yyval.node)); - curr = Trees_Right(curr); - } while (curr != NULL); - Trees_ReverseList(&(yyval.node)); - } else { - (yyval.node) = Trees_NewNode(Trees_Symbol((yyvsp[0].node)), Trees_Left((yyvsp[0].node)), (yyvsp[-1].node)); - } - } -#line 2623 "y.tab.c" - break; - - case 76: -#line 1011 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2631 "y.tab.c" - break; - - case 77: -#line 1018 "Oberon.y" - { - Trees_Node field; - - field = Trees_NewIdent((yyvsp[0].ident)); - Trees_SetKind(TREES_FIELD_KIND, field); - (yyval.node) = Trees_NewNode('.', field, NULL); - } -#line 2643 "y.tab.c" - break; - - case 78: -#line 1026 "Oberon.y" - { - Trees_Node curr, exp; - - /*create one selector node per index*/ - (yyval.node) = NULL; - curr = (yyvsp[-1].node); /*NOTE: ExpList is reversed*/ - do { - exp = Trees_Left(curr); - if (Types_IsInteger(Trees_Type(exp))) { - (yyval.node) = Trees_NewNode('[', Trees_Left(curr), (yyval.node)); - } else { - Oberon_PrintError("error: integer array index expected"); - YYABORT; - } - curr = Trees_Right(curr); - } while (curr != NULL); - } -#line 2665 "y.tab.c" - break; - - case 79: -#line 1044 "Oberon.y" - { - (yyval.node) = Trees_NewNode('^', NULL, NULL); - } -#line 2673 "y.tab.c" - break; - - case 80: -#line 1049 "Oberon.y" - { - Trees_ReverseList(&(yyvsp[-1].node)); /*correct order*/ - (yyval.node) = Trees_NewNode('(', (yyvsp[-1].node), NULL); - } -#line 2682 "y.tab.c" - break; - - case 81: -#line 1054 "Oberon.y" - { - (yyval.node) = Trees_NewNode('(', NULL, NULL); - } -#line 2690 "y.tab.c" - break; - - case 82: -#line 1061 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_EXP_LIST, (yyvsp[0].node), NULL); - Trees_SetType(Trees_Type((yyvsp[0].node)), (yyval.node)); - } -#line 2699 "y.tab.c" - break; - - case 83: -#line 1066 "Oberon.y" - { - Trees_Node reversedList; - - reversedList = Trees_NewNode(TREES_EXP_LIST, (yyvsp[0].node), (yyvsp[-2].node)); - (yyval.node) = reversedList; - Trees_SetType(Trees_Type((yyvsp[0].node)), (yyval.node)); - } -#line 2711 "y.tab.c" - break; - - case 91: -#line 1087 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2719 "y.tab.c" - break; - - case 92: -#line 1094 "Oberon.y" - { - Trees_Node designator, ident, designatorType, exp; - - CheckIsValueExpression((yyvsp[0].node)); - switch (Trees_Symbol((yyvsp[-2].node))) { - case TREES_DESIGNATOR: - designator = (yyvsp[-2].node); - exp = (yyvsp[0].node); - ident = BaseIdent((yyvsp[-2].node)); - designatorType = Trees_Type((yyvsp[-2].node)); - switch (Trees_Kind(ident)) { - case TREES_VARIABLE_KIND: - case TREES_VALUE_PARAM_KIND: - case TREES_VAR_PARAM_KIND: - if (Writable((yyvsp[-2].node))) { - ValidateAssignment(exp, designatorType, ASSIGNMENT_CONTEXT, 0); - if (Types_IsChar(designatorType) && IsString(exp)) { - exp = Trees_NewChar(Trees_String(exp)[0]); - } - } else { - Oberon_PrintError("error: assignment to read-only variable"); - YYABORT; - } - break; - default: - Oberon_PrintError("error: assignment to non-variable"); - YYABORT; - } - (yyval.node) = Trees_NewNode(BECOMES, designator, exp); - break; - case TREES_PROCEDURE_CALL: - Oberon_PrintError("error: unexpected procedure call in assignment target"); - YYABORT; - break; - default: - assert(0); - } - } -#line 2762 "y.tab.c" - break; - - case 93: -#line 1137 "Oberon.y" - { - const int isFunctionCall = 0; - Trees_Node designator, actualParameters; - - if (Trees_Symbol((yyvsp[0].node)) == TREES_PROCEDURE_CALL) { - designator = Trees_Left((yyvsp[0].node)); - actualParameters = Trees_Right((yyvsp[0].node)); - } else { - designator = (yyvsp[0].node); - actualParameters = NULL; - } - HandleProcedureCall(designator, actualParameters, isFunctionCall, &(yyval.node)); - assert((yyval.node) != NULL); - } -#line 2781 "y.tab.c" - break; - - case 94: -#line 1155 "Oberon.y" - { - Trees_ReverseList(&(yyvsp[0].node)); /*correct order*/ - (yyval.node) = (yyvsp[0].node); - } -#line 2790 "y.tab.c" - break; - - case 95: -#line 1163 "Oberon.y" - { - if ((yyvsp[0].node) == NULL) { - (yyval.node) = NULL; - } else { - (yyval.node) = Trees_NewNode(TREES_STATEMENT_SEQUENCE, (yyvsp[0].node), NULL); - } - } -#line 2802 "y.tab.c" - break; - - case 96: -#line 1171 "Oberon.y" - { - if ((yyvsp[0].node) != NULL) { - (yyval.node) = Trees_NewNode(TREES_STATEMENT_SEQUENCE, (yyvsp[0].node), (yyvsp[-2].node)); - } else { - (yyval.node) = (yyvsp[-2].node); - } - } -#line 2814 "y.tab.c" - break; - - case 97: -#line 1182 "Oberon.y" - { - Trees_Node currElsif, currExp, currThen, currStmt; - - if ((yyvsp[-2].node) == NULL) { - (yyval.node) = Trees_NewNode(IF, (yyvsp[-5].node), Trees_NewNode(THEN, (yyvsp[-3].node), (yyvsp[-1].node))); - } else { - /*correct order of elsif nodes*/ - (yyval.node) = (yyvsp[-1].node); - currElsif = (yyvsp[-2].node); - do { - currExp = Trees_Left(currElsif); - currThen = Trees_Right(currElsif); - currStmt = Trees_Left(currThen); - (yyval.node) = Trees_NewNode(ELSIF, currExp, Trees_NewNode(THEN, currStmt, (yyval.node))); - currElsif = Trees_Right(currThen); - } while (currElsif != NULL); - (yyval.node) = Trees_NewNode(IF, (yyvsp[-5].node), Trees_NewNode(THEN, (yyvsp[-3].node), (yyval.node))); - } - } -#line 2838 "y.tab.c" - break; - - case 98: -#line 1205 "Oberon.y" - { - CheckIsValueExpression((yyvsp[0].node)); - if (Types_IsBoolean(Trees_Type((yyvsp[0].node)))) { - (yyval.node) = (yyvsp[0].node); - } else { - Oberon_PrintError("error: boolean expression expected"); - YYABORT; - } - } -#line 2852 "y.tab.c" - break; - - case 99: -#line 1218 "Oberon.y" - { - (yyval.node) = Trees_NewNode(ELSIF, (yyvsp[-2].node), Trees_NewNode(THEN, (yyvsp[0].node), (yyvsp[-4].node))); - } -#line 2860 "y.tab.c" - break; - - case 100: -#line 1222 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2868 "y.tab.c" - break; - - case 101: -#line 1229 "Oberon.y" - { - (yyval.node) = Trees_NewNode(ELSE, (yyvsp[0].node), NULL); - } -#line 2876 "y.tab.c" - break; - - case 102: -#line 1233 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2884 "y.tab.c" - break; - - case 103: -#line 1240 "Oberon.y" - { - Trees_Node expType, caseVariable; - - if ((yyvsp[-1].node) != NULL) { - Trees_ReverseList(&(yyvsp[-1].node)); /*correct order*/ - } - assert(caseLabelsStack != NULL); - caseLabelsStack = Trees_Right(caseLabelsStack); - expType = Trees_Type((yyvsp[-3].node)); - if (Types_IsRecord(expType) || Types_IsPointer(expType)) { - /*reset original type*/ - caseVariable = Trees_Left((yyvsp[-3].node)); - Trees_SetType(Trees_Type((yyvsp[-3].node)), caseVariable); - caseExpressionStack = Trees_Right(caseExpressionStack); - } - (yyval.node) = Trees_NewNode(CASE, (yyvsp[-3].node), (yyvsp[-1].node)); - } -#line 2906 "y.tab.c" - break; - - case 104: -#line 1261 "Oberon.y" - { - Trees_Node typeStruct, caseVariable; - - CheckIsValueExpression((yyvsp[0].node)); - typeStruct = Types_Structure(Trees_Type((yyvsp[0].node))); - switch (Trees_Symbol(typeStruct)) { - case RECORD: - /*fall through*/ - case POINTER: - if (IsDesignator((yyvsp[0].node)) && (FirstSelector((yyvsp[0].node)) == NULL)) { - caseVariable = BaseIdent((yyvsp[0].node)); - if (! Types_IsRecord(typeStruct) || (Trees_Kind(caseVariable) == TREES_VAR_PARAM_KIND)) { - (yyval.node) = (yyvsp[0].node); - } else { - Oberon_PrintError("error: record CASE expression must be a variable parameter"); - YYABORT; - } - } else { - Oberon_PrintError("error: non-integral CASE expression must be a variable"); - YYABORT; - } - /*fall through*/ - case TREES_INTEGER_TYPE: - /*fall through*/ - case TREES_CHAR_TYPE: - caseExpressionStack = Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), caseExpressionStack); - caseLabelsStack = Trees_NewNode(TREES_NOSYM, NULL, caseLabelsStack); - (yyval.node) = (yyvsp[0].node); - break; - default: - Oberon_PrintError("error: invalid type of CASE expression"); - YYABORT; - } - } -#line 2945 "y.tab.c" - break; - - case 105: -#line 1299 "Oberon.y" - { - if ((yyvsp[0].node) != NULL) { - (yyval.node) = Trees_NewNode(TREES_CASE_REP, (yyvsp[0].node), NULL); - } else { - (yyval.node) = NULL; - } - } -#line 2957 "y.tab.c" - break; - - case 106: -#line 1307 "Oberon.y" - { - if ((yyvsp[0].node) != NULL) { - if ((yyvsp[-2].node) != NULL) { - (yyval.node) = Trees_NewNode(TREES_CASE_REP, (yyvsp[0].node), (yyvsp[-2].node)); - } else { - (yyval.node) = Trees_NewNode(TREES_CASE_REP, (yyvsp[0].node), NULL); - } - } else { - (yyval.node) = NULL; - } - } -#line 2973 "y.tab.c" - break; - - case 107: -#line 1322 "Oberon.y" - { - Trees_ReverseList(&(yyvsp[-2].node)); /*correct order*/ - (yyval.node) = Trees_NewNode(TREES_CASE, (yyvsp[-2].node), (yyvsp[0].node)); - } -#line 2982 "y.tab.c" - break; - - case 108: -#line 1327 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 2990 "y.tab.c" - break; - - case 109: -#line 1334 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_CASE_LABEL_LIST, (yyvsp[0].node), NULL); - } -#line 2998 "y.tab.c" - break; - - case 110: -#line 1338 "Oberon.y" - { - switch (Trees_Symbol((yyvsp[0].node))) { - case INTEGER: - case TREES_CHAR_CONSTANT: - case DOTDOT: - (yyval.node) = Trees_NewNode(TREES_CASE_LABEL_LIST, (yyvsp[0].node), (yyvsp[-2].node)); - break; - default: - Oberon_PrintError("error: unexpected list of type name case labels"); - YYABORT; - } - } -#line 3015 "y.tab.c" - break; - - case 111: -#line 1354 "Oberon.y" - { - (yyval.node) = (yyvsp[0].node); - CheckCaseLabelUniqueness((yyvsp[0].node)); - assert(caseLabelsStack != NULL); - caseLabelsStack = Trees_NewNode(TREES_NOSYM, - Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), Trees_Left(caseLabelsStack)), - Trees_Right(caseLabelsStack)); - } -#line 3028 "y.tab.c" - break; - - case 112: -#line 1363 "Oberon.y" - { - const int rangeLenMax = 255; - int leftSym, rightSym; - OBNC_INTEGER rangeMin, rangeMax; - - leftSym = Trees_Symbol((yyvsp[-2].node)); - rightSym = Trees_Symbol((yyvsp[0].node)); - if (leftSym == rightSym) { - switch (leftSym) { - case INTEGER: - rangeMin = Trees_Integer((yyvsp[-2].node)); - rangeMax = Trees_Integer((yyvsp[0].node)); - if (rangeMin <= rangeMax) { - if (rangeMax - rangeMin > rangeLenMax) { - Oberon_PrintError("warning: maximum range length of %d exceeded", rangeLenMax); - YYABORT; - } - } else { - Oberon_PrintError("error: left integer must be less than right integer in case range"); - YYABORT; - } - break; - case TREES_CHAR_CONSTANT: - if (Trees_Char((yyvsp[-2].node)) >= Trees_Char((yyvsp[0].node))) { - Oberon_PrintError("error: left string must be less than right string in case range"); - YYABORT; - } - break; - default: - Oberon_PrintError("error: case label ranges must contain integers or single-character strings"); - YYABORT; - } - } else { - Oberon_PrintError("error: case labels in a range must have the same type"); - YYABORT; - } - (yyval.node) = Trees_NewNode(DOTDOT, (yyvsp[-2].node), (yyvsp[0].node)); - CheckCaseLabelUniqueness((yyval.node)); - assert(caseLabelsStack != NULL); - caseLabelsStack = Trees_NewNode(TREES_NOSYM, - Trees_NewNode(TREES_NOSYM, (yyval.node), Trees_Left(caseLabelsStack)), - Trees_Right(caseLabelsStack)); - } -#line 3076 "y.tab.c" - break; - - case 113: -#line 1410 "Oberon.y" - { - if (Types_IsInteger(Trees_Type(Trees_Left(caseExpressionStack)))) { - (yyval.node) = Trees_NewInteger((yyvsp[0].integer)); - } else { - Oberon_PrintError("error: unexpected integer case label"); - YYABORT; - } - } -#line 3089 "y.tab.c" - break; - - case 114: -#line 1419 "Oberon.y" - { - if (Types_IsChar(Trees_Type(Trees_Left(caseExpressionStack)))) { - if (strlen((yyvsp[0].string)) <= 1) { - (yyval.node) = Trees_NewChar((yyvsp[0].string)[0]); - } else { - Oberon_PrintError("error: single-character string expected: \"%s\"", (yyvsp[0].string)); - YYABORT; - } - } else { - Oberon_PrintError("error: unexpected string case label: \"%s\"", (yyvsp[0].string)); - YYABORT; - } - } -#line 3107 "y.tab.c" - break; - - case 115: -#line 1433 "Oberon.y" - { - Trees_Node caseExp, constValue, caseVariable; - - (yyval.node) = Table_At(Trees_Name((yyvsp[0].node))); - if ((yyval.node) != NULL) { - caseExp = Trees_Left(caseExpressionStack); - switch (Trees_Symbol(Types_Structure(Trees_Type(caseExp)))) { - case TREES_INTEGER_TYPE: - if (Trees_Kind((yyval.node)) == TREES_CONSTANT_KIND) { - constValue = Trees_Value((yyval.node)); - if (Trees_Symbol(constValue) == INTEGER) { - if (Trees_Integer(constValue) >= 0) { - (yyval.node) = constValue; - } else { - Oberon_PrintError("error: non-negative case label expected: %" OBNC_INT_MOD "d", Trees_Integer(constValue)); - YYABORT; - } - } else { - Oberon_PrintError("error: integer case label expected"); - YYABORT; - } - } else { - Oberon_PrintError("error: constant identifier expected: %s", Trees_Name((yyval.node))); - YYABORT; - } - break; - case TREES_CHAR_TYPE: - if (Trees_Kind((yyval.node)) == TREES_CONSTANT_KIND) { - constValue = Trees_Value((yyval.node)); - if (Trees_Symbol(constValue) == STRING) { - if (Types_StringLength(Trees_Type(constValue)) <= 1) { - (yyval.node) = Trees_NewChar(Trees_String(constValue)[0]); - } else { - Oberon_PrintError("error: single-character string expected: %s", Trees_String(constValue)); - YYABORT; - } - } else { - Oberon_PrintError("error: character case label expected"); - YYABORT; - } - } else { - Oberon_PrintError("error: constant identifier expected: %s", Trees_Name((yyval.node))); - YYABORT; - } - break; - case RECORD: - if (Types_IsType((yyval.node)) && Types_IsRecord((yyval.node))) { - if (Types_Extends(Trees_Type(caseExp), (yyval.node))) { - caseVariable = Trees_Left(caseExp); - Trees_SetType((yyval.node), caseVariable); - } else { - Oberon_PrintError("error: case label is not an extension of %s: %s", Trees_Name(Trees_Type(caseExp)), Trees_Name((yyval.node))); - YYABORT; - } - } else { - Oberon_PrintError("error: record type case label expected"); - YYABORT; - } - break; - case POINTER: - if (Types_IsType((yyval.node)) && Types_IsPointer((yyval.node))) { - if (Types_Extends(Trees_Type(caseExp), (yyval.node))) { - caseVariable = Trees_Left(caseExp); - Trees_SetType((yyval.node), caseVariable); - } else { - Oberon_PrintError("error: case label is not an extension of %s: %s", Trees_Name(Trees_Type(caseExp)), Trees_Name((yyval.node))); - YYABORT; - } - } else { - Oberon_PrintError("error: pointer type case label expected"); - YYABORT; - } - break; - default: - assert(0); - } - } else { - Oberon_PrintError("error: 2 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } -#line 3193 "y.tab.c" - break; - - case 116: -#line 1518 "Oberon.y" - { - (yyval.node) = Trees_NewNode(WHILE, (yyvsp[-4].node), Trees_NewNode(DO, (yyvsp[-2].node), (yyvsp[-1].node))); - } -#line 3201 "y.tab.c" - break; - - case 117: -#line 1525 "Oberon.y" - { - (yyval.node) = Trees_NewNode(ELSIF, (yyvsp[-2].node), Trees_NewNode(THEN, (yyvsp[0].node), (yyvsp[-4].node))); - } -#line 3209 "y.tab.c" - break; - - case 118: -#line 1529 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3217 "y.tab.c" - break; - - case 119: -#line 1536 "Oberon.y" - { - CheckIsValueExpression((yyvsp[0].node)); - (yyval.node) = NULL; - if (Types_IsBoolean(Trees_Type((yyvsp[0].node)))) { - (yyval.node) = Trees_NewNode(REPEAT, (yyvsp[-2].node), (yyvsp[0].node)); - } else { - Oberon_PrintError("error: boolean expression expected"); - YYABORT; - } - } -#line 3232 "y.tab.c" - break; - - case 120: -#line 1551 "Oberon.y" - { - Trees_Node byExp; - - if ((yyvsp[-3].node) != NULL) { - byExp = (yyvsp[-3].node); - } else { - byExp = Trees_NewInteger(1); - } - (yyval.node) = Trees_NewNode(FOR, - (yyvsp[-6].node), - Trees_NewNode(TO, - (yyvsp[-4].node), - Trees_NewNode(BY, byExp, (yyvsp[-1].node)))); - } -#line 3251 "y.tab.c" - break; - - case 121: -#line 1569 "Oberon.y" - { - Trees_Node ctrlVar, ctrlVarType; - - CheckIsValueExpression((yyvsp[0].node)); - ctrlVar = Table_At((yyvsp[-2].ident)); - if (ctrlVar != NULL) { - ctrlVarType = Trees_Type(ctrlVar); - if (Types_IsInteger(ctrlVarType)) { - if (Types_IsInteger(Trees_Type((yyvsp[0].node)))) { - (yyval.node) = Trees_NewNode(BECOMES, ctrlVar, (yyvsp[0].node)); - } else { - Oberon_PrintError("error: integer expression expected as initial value"); - YYABORT; - } - } else { - Oberon_PrintError("error: integer control variable expected: %s", (yyvsp[-2].ident)); - YYABORT; - } - } else { - Oberon_PrintError("error: undeclared control variable: %s", (yyvsp[-2].ident)); - YYABORT; - } - } -#line 3279 "y.tab.c" - break; - - case 122: -#line 1595 "Oberon.y" - { - CheckIsValueExpression((yyvsp[0].node)); - if (! Types_IsInteger(Trees_Type((yyvsp[0].node)))) { - Oberon_PrintError("error: integer expression expected as upper limit"); - YYABORT; - } - } -#line 3291 "y.tab.c" - break; - - case 123: -#line 1606 "Oberon.y" - { - if (Types_IsInteger(Trees_Type((yyvsp[0].node)))) { - if (IsInteger((yyvsp[0].node))) { - if (Trees_Integer((yyvsp[0].node)) == 0) { - Oberon_PrintError("warning: steps by zero leads to infinite loop"); - } - (yyval.node) = (yyvsp[0].node); - } else { - Oberon_PrintError("error: fully evaluated constant expression expected as increment"); - YYABORT; - } - } else { - Oberon_PrintError("error: integer increment expected"); - YYABORT; - } - } -#line 3312 "y.tab.c" - break; - - case 124: -#line 1623 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3320 "y.tab.c" - break; - - case 125: -#line 1633 "Oberon.y" - { - Trees_Node procIdent, procType, resultType, procStatements, returnExp; - const char *procName; - - procIdent = (yyvsp[-6].node); - procName = Trees_Name(procIdent); - procType = Trees_Type((yyvsp[-6].node)); - resultType = Types_ResultType(procType); - procStatements = (yyvsp[-3].node); - returnExp = (yyvsp[-2].node); - - if (strcmp(procName, (yyvsp[0].ident)) == 0) { - if (resultType == NULL) { - if (returnExp != NULL) { - Oberon_PrintError("error: unexpected return expression"); - YYABORT; - } - } else { - if (returnExp != NULL) { - CheckIsValueExpression(returnExp); - ValidateAssignment(returnExp, resultType, PROC_RESULT_CONTEXT, 0); - if ((Trees_Symbol(returnExp) == STRING) && Types_IsChar(resultType)) { - returnExp = Trees_NewChar(Trees_String(returnExp)[0]); - } - } else { - Oberon_PrintError("error: return expression expected"); - YYABORT; - } - } - if (procStatements != NULL) { - Generate_ProcedureStatements(procStatements); - } - if (returnExp != NULL) { - Generate_ReturnClause(returnExp); - } - if (procedureDeclarationStack != NULL) { - procedureDeclarationStack = Trees_Right(procedureDeclarationStack); - } - Generate_ProcedureEnd(procIdent); - CheckUnusedIdentifiers(); - Table_CloseScope(); - } else { - Oberon_PrintError("error: expected procedure name: %s", procName); - YYABORT; - } - } -#line 3371 "y.tab.c" - break; - - case 126: -#line 1683 "Oberon.y" - { - Trees_Node paramList, param; - - (yyval.node) = NULL; - Trees_SetType((yyvsp[0].node), (yyvsp[-1].node)); - - paramList = Types_Parameters((yyvsp[0].node)); - while (paramList != NULL) { - param = Trees_Left(paramList); - Table_Put(param); - paramList = Trees_Right(paramList); - } - - procedureDeclarationStack = Trees_NewNode(TREES_NOSYM, (yyvsp[-1].node), procedureDeclarationStack); - Generate_ProcedureHeading((yyvsp[-1].node)); - (yyval.node) = (yyvsp[-1].node); - } -#line 3393 "y.tab.c" - break; - - case 127: -#line 1704 "Oberon.y" - { - if (! (Trees_Exported((yyvsp[0].node)) && Trees_Local((yyvsp[0].node)))) { - Trees_SetKind(TREES_PROCEDURE_KIND, (yyvsp[0].node)); - Table_Put((yyvsp[0].node)); - Table_OpenScope(); - } else { - Oberon_PrintError("error: cannot export local procedure: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - (yyval.node) = (yyvsp[0].node); - } -#line 3409 "y.tab.c" - break; - - case 128: -#line 1719 "Oberon.y" - { - (yyval.node) = (yyvsp[0].node); - } -#line 3417 "y.tab.c" - break; - - case 129: -#line 1723 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3425 "y.tab.c" - break; - - case 130: -#line 1730 "Oberon.y" - { - (yyval.node) = (yyvsp[0].node); - } -#line 3433 "y.tab.c" - break; - - case 131: -#line 1734 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3441 "y.tab.c" - break; - - case 137: -#line 1755 "Oberon.y" - { - Trees_Node unresolvedPointerType, undeclaredBaseType; - - if (unresolvedPointerTypes != NULL) { - unresolvedPointerType = Trees_Left(unresolvedPointerTypes); - undeclaredBaseType = Types_PointerBaseType(unresolvedPointerType); - Oberon_PrintError("error: undeclared pointer base type: %s", Trees_Name(undeclaredBaseType)); - YYABORT; - } - } -#line 3456 "y.tab.c" - break; - - case 138: -#line 1766 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3464 "y.tab.c" - break; - - case 139: -#line 1773 "Oberon.y" - { - unresolvedPointerTypes = NULL; - } -#line 3472 "y.tab.c" - break; - - case 148: -#line 1800 "Oberon.y" - { - (yyval.node) = Types_NewProcedure((yyvsp[-2].node), (yyvsp[0].node)); - } -#line 3480 "y.tab.c" - break; - - case 149: -#line 1807 "Oberon.y" - { - Trees_ReverseList(&(yyvsp[0].node)); /*correct order*/ - (yyval.node) = (yyvsp[0].node); - } -#line 3489 "y.tab.c" - break; - - case 150: -#line 1812 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3497 "y.tab.c" - break; - - case 151: -#line 1819 "Oberon.y" - { - (yyval.node) = (yyvsp[0].node); - Trees_ReverseList(&(yyval.node)); - } -#line 3506 "y.tab.c" - break; - - case 152: -#line 1824 "Oberon.y" - { - Trees_Node p, p1; - const char *paramName, *paramName1; - - /*make sure no parameter is repeated*/ - p = (yyvsp[0].node); - while (p != NULL) { - paramName = Trees_Name(Trees_Left(p)); - p1 = (yyvsp[-2].node); - while (p1 != NULL) { - paramName1 = Trees_Name(Trees_Left(p1)); - if (strcmp(paramName1, paramName) == 0) { - Oberon_PrintError("error: repeated parameter: %s", paramName); - YYABORT; - } - p1 = Trees_Right(p1); - } - p = Trees_Right(p); - } - - /*make one list of the two lists*/ - (yyval.node) = (yyvsp[-2].node); - p = (yyvsp[0].node); - do { - (yyval.node) = Trees_NewNode(TREES_IDENT_LIST, Trees_Left(p), (yyval.node)); - p = Trees_Right(p); - } while (p != NULL); - /*$$ in reversed order*/ - } -#line 3540 "y.tab.c" - break; - - case 153: -#line 1857 "Oberon.y" - { - (yyval.node) = ResolvedType((yyvsp[0].node), 0); - if ((yyval.node) != NULL) { - if (Trees_Symbol((yyval.node)) == IDENT) { - if (Trees_Kind((yyval.node)) != TREES_TYPE_KIND) { - Oberon_PrintError("error: type name expected as result type: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - if (! Types_Scalar((yyval.node))) { - Oberon_PrintError("error: scalar result type expected: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } - } else { - Oberon_PrintError("error: 3 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - YYABORT; - } - } -#line 3563 "y.tab.c" - break; - - case 154: -#line 1876 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3571 "y.tab.c" - break; - - case 155: -#line 1883 "Oberon.y" - { - Trees_Node curr, ident; - - Trees_ReverseList(&(yyvsp[-2].node)); /*correct order*/ - curr = (yyvsp[-2].node); - do { - ident = Trees_Left(curr); - Trees_SetKind((int) (yyvsp[-3].integer), ident); - Trees_SetType((yyvsp[0].node), ident); - Trees_SetLocal(ident); - curr = Trees_Right(curr); - } while (curr != NULL); - - (yyval.node) = (yyvsp[-2].node); - } -#line 3591 "y.tab.c" - break; - - case 156: -#line 1902 "Oberon.y" - { - (yyval.integer) = TREES_VAR_PARAM_KIND; - } -#line 3599 "y.tab.c" - break; - - case 157: -#line 1906 "Oberon.y" - { - (yyval.integer) = TREES_VALUE_PARAM_KIND; - } -#line 3607 "y.tab.c" - break; - - case 158: -#line 1913 "Oberon.y" - { - (yyval.node) = Trees_NewNode(TREES_IDENT_LIST, Trees_NewIdent((yyvsp[0].ident)), NULL); - } -#line 3615 "y.tab.c" - break; - - case 159: -#line 1917 "Oberon.y" - { - Trees_Node curr; - const char *identName; - - /*make sure no name is repeated*/ - curr = (yyvsp[-2].node); - while (curr != NULL) { - identName = Trees_Name(Trees_Left(curr)); - if (strcmp(identName, (yyvsp[0].ident)) == 0) { - Oberon_PrintError("error: repeated identifier: %s", identName); - YYABORT; - } - curr = Trees_Right(curr); - } - - (yyval.node) = Trees_NewNode(TREES_IDENT_LIST, Trees_NewIdent((yyvsp[0].ident)), (yyvsp[-2].node)); - } -#line 3637 "y.tab.c" - break; - - case 160: -#line 1938 "Oberon.y" - { - (yyval.node) = ResolvedType((yyvsp[0].node), 0); - if ((yyval.node) != NULL) { - while ((yyvsp[-1].node) != NULL) { - (yyval.node) = Types_NewArray(NULL, (yyval.node)); - (yyvsp[-1].node) = Trees_Right((yyvsp[-1].node)); - } - } else { - Oberon_PrintError("error: 4 undeclared identifier: %s", Trees_Name((yyvsp[0].node))); - exit(EXIT_FAILURE); - } - } -#line 3654 "y.tab.c" - break; - - case 161: -#line 1954 "Oberon.y" - { - (yyval.node) = Trees_NewNode(ARRAY, NULL, (yyvsp[-2].node)); - } -#line 3662 "y.tab.c" - break; - - case 162: -#line 1958 "Oberon.y" - { - (yyval.node) = NULL; - } -#line 3670 "y.tab.c" - break; - - case 163: -#line 1968 "Oberon.y" - { - const char *symfilePath; - - if (strcmp((yyvsp[-1].ident), inputModuleName) == 0) { - CheckUnusedIdentifiers(); - Generate_ModuleEnd(); - Generate_Close(); - - symfilePath = Util_String(".obnc/%s.sym", inputModuleName); - if (parseMode == OBERON_ENTRY_POINT_MODE) { - if (Files_Exists(symfilePath)) { - Files_Remove(symfilePath); - } - } else { - ExportSymbolTable(symfilePath); - } - YYACCEPT; - } else { - Oberon_PrintError("error: expected identifier %s", inputModuleName); - YYABORT; - } - } -#line 3697 "y.tab.c" - break; - - case 164: -#line 1995 "Oberon.y" - { - if (strcmp((yyvsp[0].ident), inputModuleName) == 0) { - if (parseMode != OBERON_IMPORT_LIST_MODE) { - Generate_ModuleHeading(); - } - } else { - Oberon_PrintError("error: module name does not match filename: %s", (yyvsp[0].ident)); - YYABORT; - } - } -#line 3712 "y.tab.c" - break; - - case 165: -#line 2009 "Oberon.y" - { - if (parseMode == OBERON_IMPORT_LIST_MODE) { - YYACCEPT; - } - } -#line 3722 "y.tab.c" - break; - - case 166: -#line 2015 "Oberon.y" - { - if (parseMode == OBERON_IMPORT_LIST_MODE) { - YYACCEPT; - } - } -#line 3732 "y.tab.c" - break; - - case 167: -#line 2024 "Oberon.y" - { - const char *impfilePath; - Trees_Node moduleAndDirPath, module, p; - FILE *impFile; - const char *name; - - if ((yyvsp[-1].node) != NULL) { - Trees_ReverseList(&(yyvsp[-1].node)); /*correct order*/ - if (parseMode == OBERON_IMPORT_LIST_MODE) { - while ((yyvsp[-1].node) != NULL) { - name = Trees_Name(Trees_Left((yyvsp[-1].node))); - puts(name); - (yyvsp[-1].node) = Trees_Right((yyvsp[-1].node)); - } - } else { - if (parseMode == OBERON_NORMAL_MODE) { - impfilePath = Util_String(".obnc/%s.imp", inputModuleName); - impFile = Files_Exists(impfilePath)? Files_Old(impfilePath, FILES_WRITE): Files_New(impfilePath); - p = (yyvsp[-1].node); - do { - moduleAndDirPath = Trees_Left(p); - module = Trees_Left(moduleAndDirPath); - name = Trees_UnaliasedName(module); - fprintf(impFile, "%s\n", name); - p = Trees_Right(p); - } while (p != NULL); - Files_Close(&impFile); - } - Generate_ImportList((yyvsp[-1].node)); - } - } - } -#line 3769 "y.tab.c" - break; - - case 168: -#line 2060 "Oberon.y" - { - if ((yyvsp[0].node) != NULL) { - (yyval.node) = Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), NULL); - } else { - (yyval.node) = NULL; - } - } -#line 3781 "y.tab.c" - break; - - case 169: -#line 2068 "Oberon.y" - { - if ((yyvsp[0].node) != NULL) { - (yyval.node) = Trees_NewNode(TREES_NOSYM, (yyvsp[0].node), (yyvsp[-2].node)); - } else { - (yyval.node) = (yyvsp[-2].node); - } - } -#line 3793 "y.tab.c" - break; - - case 170: -#line 2079 "Oberon.y" - { - static Maps_Map importedModules = NULL; - const char *module, *qualifier, *symbolFileDir, *symbolFileName, *moduleDirPath; - Trees_Node qualifierSym, moduleIdent; - - if (importedModules == NULL) { - importedModules = Maps_New(); - } - if ((yyvsp[0].ident) != NULL) { - module = (yyvsp[0].ident); - qualifier = (yyvsp[-1].ident); - } else { - module = (yyvsp[-1].ident); - qualifier = (yyvsp[-1].ident); - } - (yyval.node) = NULL; - if (strcmp(module, inputModuleName) != 0) { - if (! Maps_HasKey(module, importedModules)) { - Maps_Put(module, NULL, &importedModules); - qualifierSym = Table_At(qualifier); - if (qualifierSym == NULL) { - qualifierSym = Trees_NewIdent(qualifier); - if ((yyvsp[0].ident) != NULL) { - Trees_SetUnaliasedName(module, qualifierSym); - } - Trees_SetKind(TREES_QUALIFIER_KIND, qualifierSym); - Table_Put(qualifierSym); - - if (strcmp(module, "SYSTEM") == 0) { - if (parseMode != OBERON_IMPORT_LIST_MODE) { - Table_ImportSystem(qualifier); - } - } else if (parseMode == OBERON_IMPORT_LIST_MODE) { - (yyval.node) = Trees_NewIdent(module); - } else { - moduleDirPath = ModulePaths_Directory(module, ".", 0); - if (moduleDirPath != NULL) { - /*import identifiers into the symbol table*/ - symbolFileDir = Util_String("%s/.obnc", moduleDirPath); - if (! Files_Exists(symbolFileDir)) { - symbolFileDir = Util_String("%s", moduleDirPath); - } - symbolFileName = Util_String("%s/%s.sym", symbolFileDir, module); - if (Files_Exists(symbolFileName)) { - Table_Import(symbolFileName, module, qualifier); - } else { - Oberon_PrintError("error: symbol file not found for module %s: %s", module, symbolFileName); - YYABORT; - } - - moduleIdent = Trees_NewIdent(module); - Trees_SetKind(TREES_QUALIFIER_KIND, moduleIdent); - (yyval.node) = Trees_NewNode(TREES_NOSYM, moduleIdent, Trees_NewString(moduleDirPath)); - } else { - Oberon_PrintError("error: imported module not found: %s", module); - YYABORT; - } - } - } else { - Oberon_PrintError("error: qualifier already used: %s", qualifier); - YYABORT; - } - } else { - Oberon_PrintError("error: module already imported: %s", module); - YYABORT; - } - } else { - Oberon_PrintError("error: a module cannot import itself"); - YYABORT; - } - } -#line 3869 "y.tab.c" - break; - - case 171: -#line 2154 "Oberon.y" - { - (yyval.ident) = (yyvsp[0].ident); - } -#line 3877 "y.tab.c" - break; - - case 172: -#line 2158 "Oberon.y" - { - (yyval.ident) = NULL; - } -#line 3885 "y.tab.c" - break; - - case 173: -#line 2165 "Oberon.y" - { - Generate_ModuleStatements((yyvsp[0].node)); - } -#line 3893 "y.tab.c" - break; - - -#line 3897 "y.tab.c" - - default: break; - } - /* User semantic actions sometimes alter yychar, and that requires - that yytoken be updated with the new translation. We take the - approach of translating immediately before every use of yytoken. - One alternative is translating here after every semantic action, - but that translation would be missed if the semantic action invokes - YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or - if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an - incorrect destructor might then be invoked immediately. In the - case of YYERROR or YYBACKUP, subsequent parser actions might lead - to an incorrect destructor call or verbose syntax error message - before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); - - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - /* Now 'shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - { - const int yylhs = yyr1[yyn] - YYNTOKENS; - const int yyi = yypgoto[yylhs] + *yyssp; - yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp - ? yytable[yyi] - : yydefgoto[yylhs]); - } - - goto yynewstate; - - -/*--------------------------------------. -| yyerrlab -- here on detecting error. | -`--------------------------------------*/ -yyerrlab: - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval); - yychar = YYEMPTY; - } - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*---------------------------------------------------. -| yyerrorlab -- error raised explicitly by YYERROR. | -`---------------------------------------------------*/ -yyerrorlab: - /* Pacify compilers when the user code never invokes YYERROR and the - label yyerrorlab therefore never appears in user code. */ - if (0) - YYERROR; - - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - YYPOPSTACK (yylen); - yylen = 0; - YY_STACK_PRINT (yyss, yyssp); - yystate = *yyssp; - goto yyerrlab1; - - -/*-------------------------------------------------------------. -| yyerrlab1 -- common code for both syntax error and YYERROR. | -`-------------------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - - yydestruct ("Error: popping", - yystos[yystate], yyvsp); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } - - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END - - - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - - -#if !defined yyoverflow || YYERROR_VERBOSE -/*-------------------------------------------------. -| yyexhaustedlab -- memory exhaustion comes here. | -`-------------------------------------------------*/ -yyexhaustedlab: - yyerror (YY_("memory exhausted")); - yyresult = 2; - /* Fall through. */ -#endif - - -/*-----------------------------------------------------. -| yyreturn -- parsing is finished, return the result. | -`-----------------------------------------------------*/ -yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); - } - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[+*yyssp], yyvsp); - YYPOPSTACK (1); - } -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif - return yyresult; -} -#line 2170 "Oberon.y" - - -void Oberon_Init(void) -{ - if (! initialized) { - initialized = 1; - Error_Init(); - Files_Init(); - Generate_Init(); - ModulePaths_Init(); - Table_Init(); - } -} - - -void Oberon_Parse(const char inputFile[], int mode) -{ - const char *impFile; - FILE *fp; - int error; - - assert(initialized); - inputFilename = inputFile; - parseMode = mode; - inputModuleName = Paths_SansSuffix(Paths_Basename(inputFile)); - - yyin = fopen(inputFile, "r"); - if (yyin != NULL) { - if (mode != OBERON_IMPORT_LIST_MODE) { - Generate_Open(inputFile, mode == OBERON_ENTRY_POINT_MODE); - - impFile = Util_String(".obnc/%s.imp", inputModuleName); - if (parseMode == OBERON_NORMAL_MODE) { - if (! Files_Exists(impFile)) { - fp = Files_New(impFile); - Files_Close(&fp); - } - } else { - assert(parseMode == OBERON_ENTRY_POINT_MODE); - if (Files_Exists(impFile)) { - Files_Remove(impFile); - } - } - } - error = yyparse(); - if (error) { - exit(EXIT_FAILURE); - } - } else { - Error_Handle(Util_String("error: cannot open file: %s: %s", inputFile, strerror(errno))); - } -} - - -void Oberon_PrintError(const char format[], ...) -{ - va_list ap; - - assert(initialized); - fprintf(stderr, "obnc-compile: %s:%d: ", inputFilename, yylineno); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - fputc('\n', stderr); -} - - -void yyerror(const char msg[]) -{ - Oberon_PrintError("%s", msg); -} - - -static void PrintError(int line, const char format[], ...) - __attribute__ ((format (printf, 2, 3))); - -static void PrintError(int line, const char format[], ...) -{ - va_list ap; - - fprintf(stderr, "obnc-compile: %s:%d: ", inputFilename, line); - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - fputc('\n', stderr); -} - - -static char *IdentKindString(int kind) -{ - char *result; - - switch (kind) { - case TREES_CONSTANT_KIND: - result = Util_String("constant"); - break; - case TREES_TYPE_KIND: - result = Util_String("type"); - break; - case TREES_VARIABLE_KIND: - result = Util_String("variable"); - break; - case TREES_PROCEDURE_KIND: - result = Util_String("procedure"); - break; - case TREES_QUALIFIER_KIND: - result = Util_String("module"); - break; - default: - result = Util_String("identifier"); - } - return result; -} - - -static void CheckUnusedIdentifiers(void) -{ - Trees_Node unusedIdents, ident; - int kind; - - unusedIdents = Table_UnusedIdentifiers(); - while (unusedIdents != NULL) { - ident = Trees_Left(unusedIdents); - kind = Trees_Kind(ident); - if (! Trees_Exported(ident) - && (kind != TREES_VALUE_PARAM_KIND) - && (kind != TREES_VAR_PARAM_KIND)) { - PrintError(Trees_LineNumber(ident), "note: unused %s: %s", IdentKindString(Trees_Kind(ident)), Trees_UnaliasedName(ident)); - } - unusedIdents = Trees_Right(unusedIdents); - } -} - - -/*constant predicate functions*/ - -static int IsBoolean(Trees_Node node) -{ - return (Trees_Symbol(node) == TRUE) || (Trees_Symbol(node) == FALSE); -} - - -static int IsChar(Trees_Node node) -{ - return Trees_Symbol(node) == TREES_CHAR_CONSTANT; -} - - -static int IsInteger(Trees_Node node) -{ - return Trees_Symbol(node) == INTEGER; -} - - -static int IsReal(Trees_Node node) -{ - return Trees_Symbol(node) == REAL; -} - - -static int IsString(Trees_Node node) -{ - return Trees_Symbol(node) == STRING; -} - - -/*functions for type declaration productions*/ - -static Trees_Node ResolvedType(Trees_Node type, int isTypeDecl) -{ - Trees_Node result, identDef, typeStruct; - const char *name; - - result = NULL; - if (Trees_Symbol(type) == IDENT) { - name = Trees_Name(type); - identDef = Table_At(name); - if (identDef != NULL) { - if (Trees_Kind(identDef) == TREES_TYPE_KIND) { - typeStruct = Types_Structure(identDef); - if (typeStruct != NULL) { - if (Types_Basic(Trees_Type(identDef)) && ! isTypeDecl) { - result = Trees_Type(identDef); - } else { - result = identDef; - } - } else { - Oberon_PrintError("error: unresolved type: %s", name); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: type expected: %s", name); - exit(EXIT_FAILURE); - } - } - } else { - result = type; - } - return result; -} - - -static void ResolvePointerTypes(Trees_Node baseType) -{ - const char *baseTypeName; - Trees_Node prev, curr, currPointerType, currBaseType; - - assert(Trees_Symbol(baseType) == IDENT); - baseTypeName = Trees_Name(baseType); - - prev = NULL; - curr = unresolvedPointerTypes; - while (curr != NULL) { - currPointerType = Trees_Left(curr); - currBaseType = Types_PointerBaseType(currPointerType); - if (strcmp(Trees_Name(currBaseType), baseTypeName) == 0) { - if (Types_IsRecord(baseType)) { - Trees_SetUsed(baseType); - /*update pointer base type*/ - Types_SetPointerBaseType(baseType, currPointerType); - /*delete current node*/ - if (curr == unresolvedPointerTypes) { - unresolvedPointerTypes = Trees_Right(curr); - } else { - Trees_SetRight(Trees_Right(curr), prev); - } - } else { - Oberon_PrintError("error: record type expected in declaration of pointer base type: %s", baseTypeName); - exit(EXIT_FAILURE); - } - } - prev = curr; - curr = Trees_Right(curr); - } -} - - -static const char *TypeString(Trees_Node type) -{ - const char *result = Util_String("%s", ""); - - assert(Types_IsType(type)); - - switch (Trees_Symbol(Types_Structure(type))) { - case TREES_STRING_TYPE: - switch (Types_StringLength(type)) { - case 0: - result = Util_String("empty string"); - break; - case 1: - result = Util_String("single-char string"); - break; - default: - result = Util_String("multi-char string"); - } - break; - case TREES_BOOLEAN_TYPE: - result = Util_String("BOOLEAN"); - break; - case TREES_CHAR_TYPE: - result = Util_String("CHAR"); - break; - case TREES_INTEGER_TYPE: - result = Util_String("INTEGER"); - break; - case TREES_REAL_TYPE: - result = Util_String("REAL"); - break; - case TREES_BYTE_TYPE: - result = Util_String("BYTE"); - break; - case ARRAY: - if (Types_IsOpenArray(type)) { - result = Util_String("open array type"); - } else { - if (Trees_Symbol(type) != IDENT) { - result = Util_String("anonymous "); - } - result = Util_String("array type"); - } - break; - case RECORD: - if (Trees_Symbol(type) != IDENT) { - result = Util_String("anonymous "); - } - result = Util_String("record type"); - break; - case POINTER: - if (Trees_Symbol(type) != IDENT) { - result = Util_String("anonymous "); - } - result = Util_String("pointer type"); - break; - case PROCEDURE: - if (Trees_Symbol(type) != IDENT) { - result = Util_String("anonymous "); - } - result = Util_String("procedure type"); - break; - case TREES_NIL_TYPE: - result = Util_String("NIL"); - break; - default: - assert(0); - } - if (Trees_Symbol(type) == IDENT) { - result = Util_String("%s (%s)", Trees_Name(type), result); - } - return result; -} - - -/*functions for expression productions*/ - -static int IsDesignator(Trees_Node exp) -{ - return Trees_Symbol(exp) == TREES_DESIGNATOR; -} - - -static int IsValueExpression(Trees_Node exp) -{ - int result = 1; - - if (IsDesignator(exp)) { - switch (Trees_Kind(BaseIdent(exp))) { - case TREES_CONSTANT_KIND: - case TREES_FIELD_KIND: - case TREES_VARIABLE_KIND: - case TREES_PROCEDURE_KIND: - case TREES_VALUE_PARAM_KIND: - case TREES_VAR_PARAM_KIND: - break; - default: - result = 0; - } - } - return result; -} - - -static void CheckIsValueExpression(Trees_Node exp) -{ - if (! IsValueExpression(exp)) { - Oberon_PrintError("error: value expected: %s", Trees_Name(BaseIdent(exp))); - exit(EXIT_FAILURE); - } -} - - -static Trees_Node Designator(const char identName[], Trees_Node selectorList) -{ - Trees_Node identSym, qualidentSym, designator, qualidentSelectorList; - const char *qualidentName; - - /*set qualident name, symbol and selector list*/ - qualidentSym = NULL; - qualidentSelectorList = NULL; - identSym = Table_At(identName); - if ((identSym == NULL) && (procedureDeclarationStack != NULL) - && (strcmp(identName, Trees_Name(Trees_Left(procedureDeclarationStack))) == 0)) { - qualidentSym = Trees_Left(procedureDeclarationStack); - qualidentSelectorList = selectorList; - } else { - if (identSym != NULL) { - if (Trees_Kind(identSym) == TREES_QUALIFIER_KIND) { - if ((selectorList != NULL) && (Trees_Symbol(selectorList) == '.')) { - qualidentName = Util_String("%s.%s", identName, Trees_Name(Trees_Left(selectorList))); - qualidentSym = Table_At(qualidentName); - qualidentSelectorList = Trees_Right(selectorList); - if (qualidentSym == NULL) { - Oberon_PrintError("error: 5 undeclared identifier: %s", qualidentName); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: '.' expected after qualifier: %s", identName); - exit(EXIT_FAILURE); - } - } else { - qualidentSym = identSym; - qualidentSelectorList = selectorList; - } - - } else { - Oberon_PrintError("error: 6 undeclared identifier: %s", identName); - exit(EXIT_FAILURE); - } - } - assert(qualidentSym != NULL); - - designator = Trees_NewNode(TREES_DESIGNATOR, qualidentSym, qualidentSelectorList); - - return designator; -} - - -static Trees_Node BaseIdent(Trees_Node designator) -{ - assert(Trees_Symbol(designator) == TREES_DESIGNATOR); - - return Trees_Left(designator); -} - - -static Trees_Node FirstSelector(Trees_Node designator) -{ - assert(Trees_Symbol(designator) == TREES_DESIGNATOR); - - return Trees_Right(designator); -} - - -static void SetSelectorTypes(Trees_Node identType, Trees_Node designator, int *parameterListFound) -{ - Trees_Node currType, currTypeStruct, currSelector, prevSelector, indexExp, lengthNode, pointerNode, expList, extendedType, symbol, varField, typeField, fieldBaseType; - OBNC_INTEGER length, index; - const char *fieldName; - - currType = identType; - currSelector = FirstSelector(designator); - prevSelector = designator; - *parameterListFound = 0; - while ((currSelector != NULL) && ! *parameterListFound) { - currTypeStruct = Types_Structure(currType); - switch (Trees_Symbol(currSelector)) { - case '[': - if ((currTypeStruct != NULL) && (Trees_Symbol(currTypeStruct) == ARRAY)) { - indexExp = Trees_Left(currSelector); - lengthNode = Types_ArrayLength(currTypeStruct); - if ((lengthNode != NULL) && (Trees_Symbol(indexExp) == INTEGER)) { - length = Trees_Integer(lengthNode); - index = Trees_Integer(indexExp); - if ((index < 0) || (index >= length)) { - Oberon_PrintError("error: invalid array index: %" OBNC_INT_MOD "d not between 0 and %" OBNC_INT_MOD "d", index, (OBNC_INTEGER) (length - 1)); - exit(EXIT_FAILURE); - } - } - Trees_SetType(currType, currSelector); - currType = Types_ElementType(currTypeStruct); - } else { - Oberon_PrintError("error: array variable expected in element selector"); - exit(EXIT_FAILURE); - } - break; - case '.': - if (currType != NULL) { - switch (Trees_Symbol(currTypeStruct)) { - case POINTER: - pointerNode = Trees_NewNode('^', NULL, currSelector); - Trees_SetType(currType, pointerNode); - Trees_SetRight(pointerNode, prevSelector); - currType = Types_PointerBaseType(currTypeStruct); - /*fall through*/ - case RECORD: - Trees_SetType(currType, currSelector); - varField = Trees_Left(currSelector); - fieldName = Trees_Name(varField); - Types_GetFieldIdent(fieldName, currType, Trees_Imported(BaseIdent(designator)), &typeField, &fieldBaseType); - if (typeField != NULL) { - if (Trees_Exported(typeField)) { - Trees_SetExported(varField); - } - currType = Trees_Type(typeField); - } else { - Oberon_PrintError("error: undeclared field: %s", fieldName); - exit(EXIT_FAILURE); - } - break; - default: - Oberon_PrintError("error: record variable expected in field selector"); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: record variable expected in field selector"); - exit(EXIT_FAILURE); - } - break; - case '^': - if ((currType != NULL) && (Trees_Symbol(currTypeStruct) == POINTER)) { - Trees_SetType(currType, currSelector); - currType = Types_PointerBaseType(currTypeStruct); - } else { - Oberon_PrintError("error: pointer variable expected in pointer dereference"); - exit(EXIT_FAILURE); - } - break; - case '(': - if (Types_IsProcedure(currTypeStruct)) { - *parameterListFound = 1; - } else if (Types_IsRecord(currTypeStruct) || Types_IsPointer(currTypeStruct)) { - /*type guard*/ - expList = Trees_Left(currSelector); - if (Trees_Right(expList) == NULL) { - if ((Trees_Symbol(Trees_Left(expList)) == TREES_DESIGNATOR) - && (Trees_Right(Trees_Left(expList)) == NULL)) { - extendedType = Trees_Left(Trees_Left(expList)); - symbol = Table_At(Trees_Name(extendedType)); - if (symbol != NULL) { - if (Trees_Kind(symbol) == TREES_TYPE_KIND) { - if ((Types_IsRecord(currType) && Types_IsRecord(Trees_Type(symbol)) - && (Trees_Kind(BaseIdent(designator)) == TREES_VAR_PARAM_KIND)) - || (Types_IsPointer(currType) && Types_IsPointer(Trees_Type(symbol)))) { - if (Types_Extends(currType, Trees_Type(symbol))) { - Trees_SetLeft(extendedType, currSelector); - Trees_SetType(extendedType, currSelector); - currType = extendedType; - } else { - Oberon_PrintError("error: extended type expected: %s", Trees_Name(extendedType)); - exit(EXIT_FAILURE); - } - } else { - if (Types_IsRecord(currType)) { - if (Trees_Kind(BaseIdent(designator)) != TREES_VAR_PARAM_KIND) { - Oberon_PrintError("error: variable parameter expected in type guard"); - } else { - Oberon_PrintError("error: record type expected in type guard: %s", Trees_Name(extendedType)); - } - exit(EXIT_FAILURE); - } else { - Oberon_PrintError("error: pointer type expected in type guard: %s", Trees_Name(extendedType)); - exit(EXIT_FAILURE); - } - } - } else { - Oberon_PrintError("error: type name expected: %s", Trees_Name(extendedType)); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: 7 undeclared identifier: %s", Trees_Name(extendedType)); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: identifier expected in type guard"); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: unexpected comma in type guard"); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: unexpected parenthesis in designator which is not a record, pointer or procedure"); - exit(EXIT_FAILURE); - } - break; - default: - assert(0); - } - prevSelector = currSelector; - currSelector = Trees_Right(currSelector); - } - - if (currSelector == NULL) { - Trees_SetType(currType, designator); - } else { - Oberon_PrintError("error: unexpected selector after procedure call"); - exit(EXIT_FAILURE); - } -} - - -static void RemoveActualParameters(Trees_Node *designator, Trees_Node *actualParameters) -{ - Trees_Node currSelector; - - currSelector = FirstSelector(*designator); - assert(currSelector != NULL); - if (Trees_Right(currSelector) == NULL) { - *actualParameters = Trees_Left(currSelector); - Trees_SetRight(NULL, *designator); - } else { - while (Trees_Right(Trees_Right(currSelector)) != NULL) { - currSelector = Trees_Right(currSelector); - } - *actualParameters = Trees_Left(Trees_Right(currSelector)); - Trees_SetRight(NULL, currSelector); - } -} - - -static int IsConstExpression(Trees_Node exp) -{ - int result = 0; - - assert(exp != NULL); - switch (Trees_Symbol(exp)) { - case TRUE: - case FALSE: - case STRING: - case TREES_CHAR_CONSTANT: - case INTEGER: - case REAL: - case NIL: - case TREES_SIZE_PROC: /*type sizes cannot always be evaluated in the Oberon-to-C translation*/ - result = 1; - break; - case IDENT: - case TREES_DESIGNATOR: - case TREES_ADR_PROC: - case TREES_BIT_PROC: - result = 0; - break; - default: - result = ((Trees_Left(exp) == NULL) || IsConstExpression(Trees_Left(exp))) - && ((Trees_Right(exp) == NULL) || IsConstExpression(Trees_Right(exp))); - } - return result; -} - - -static Trees_Node ExpressionConstValue(int relation, Trees_Node expA, Trees_Node expB) -{ - Trees_Node result = NULL; - - switch (relation) { - case '=': - switch (Trees_Symbol(expA)) { - case TRUE: - case FALSE: - if (IsBoolean(expB)) { - result = Trees_NewLeaf((Trees_Symbol(expA) == Trees_Symbol(expB))? TRUE: FALSE); - } - break; - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) == Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) == Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) == Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) == Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] == Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) == 0)? TRUE: FALSE); - } - break; - } - break; - case NOT_EQ: - switch (Trees_Symbol(expA)) { - case TRUE: - case FALSE: - if (IsBoolean(expB)) { - result = Trees_NewLeaf((Trees_Symbol(expA) != Trees_Symbol(expB))? TRUE: FALSE); - } - break; - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) != Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) != Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) != Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) != Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] != Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) != 0)? TRUE: FALSE); - } - break; - } - break; - case '<': - switch (Trees_Symbol(expA)) { - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) < Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) < Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) < Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) < Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] < Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) < 0)? TRUE: FALSE); - } - break; - } - break; - case LE: - switch (Trees_Symbol(expA)) { - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) <= Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) <= Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) <= Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) <= Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] <= Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) <= 0)? TRUE: FALSE); - } - break; - } - break; - case '>': - switch (Trees_Symbol(expA)) { - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) > Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) > Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) > Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) > Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] > Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) > 0)? TRUE: FALSE); - } - break; - } - break; - case GE: - switch (Trees_Symbol(expA)) { - case TREES_CHAR_CONSTANT: - if (IsString(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) >= Trees_String(expB)[0])? TRUE: FALSE); - } else if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_Char(expA) >= Trees_Char(expB))? TRUE: FALSE); - } - break; - case INTEGER: - if (IsInteger(expB)) { - result = Trees_NewLeaf((Trees_Integer(expA) >= Trees_Integer(expB))? TRUE: FALSE); - } - break; - case REAL: - if (IsReal(expB)) { - result = Trees_NewLeaf((Trees_Real(expA) >= Trees_Real(expB))? TRUE: FALSE); - } - break; - case STRING: - if (IsChar(expB)) { - result = Trees_NewLeaf((Trees_String(expA)[0] >= Trees_Char(expB))? TRUE: FALSE); - } else if (IsString(expB)) { - result = Trees_NewLeaf((strcmp(Trees_String(expA), Trees_String(expB)) >= 0)? TRUE: FALSE); - } - break; - } - break; - } - if (result != NULL) { - Trees_SetType(Trees_NewLeaf(TREES_BOOLEAN_TYPE), result); - } - - return result; -} - - -static Trees_Node SimpleExpressionConstValue(int operator, Trees_Node expA, Trees_Node expB) -{ - Trees_Node result = NULL; - - switch (operator) { - case '+': - switch (Trees_Symbol(expA)) { - case INTEGER: - if (expB == NULL) { - result = expA; - } else if (IsInteger(expB)) { - Range_CheckIntSum(Trees_Integer(expA), Trees_Integer(expB)); - result = Trees_NewInteger(Trees_Integer(expA) + Trees_Integer(expB)); - } - break; - case REAL: - if (expB == NULL) { - result = expA; - } else if (IsReal(expB)) { - Range_CheckRealSum(Trees_Real(expA), Trees_Real(expB)); - result = Trees_NewReal(Trees_Real(expA) + Trees_Real(expB)); - } - break; - } - break; - case '-': - switch (Trees_Symbol(expA)) { - case INTEGER: - if (expB == NULL) { - Range_CheckIntDiff(0, Trees_Integer(expA)); - result = Trees_NewInteger(-Trees_Integer(expA)); - } else if (IsInteger(expB)) { - Range_CheckIntDiff(Trees_Integer(expA), Trees_Integer(expB)); - result = Trees_NewInteger(Trees_Integer(expA) - Trees_Integer(expB)); - } - break; - case REAL: - if (expB == NULL) { - Range_CheckRealDiff(0.0, Trees_Real(expA)); - result = Trees_NewReal(-Trees_Real(expA)); - } else if (IsReal(expB)) { - Range_CheckRealDiff(Trees_Real(expA), Trees_Real(expB)); - result = Trees_NewReal(Trees_Real(expA) - Trees_Real(expB)); - } - break; - } - break; - case OR: - if (IsBoolean(expA) && IsBoolean(expB)) { - result = (Trees_Symbol(expA) == TRUE)? expA: expB; - } - break; - } - - return result; -} - - -static Trees_Node TermConstValue(int operator, Trees_Node expA, Trees_Node expB) -{ - Trees_Node result = NULL; - - switch (operator) { - case '*': - switch (Trees_Symbol(expA)) { - case INTEGER: - if (IsInteger(expB)) { - Range_CheckIntProd(Trees_Integer(expA), Trees_Integer(expB)); - result = Trees_NewInteger(Trees_Integer(expA) * Trees_Integer(expB)); - } - break; - case REAL: - if (IsReal(expB)) { - Range_CheckRealProd(Trees_Real(expA), Trees_Real(expB)); - result = Trees_NewReal(Trees_Real(expA) * Trees_Real(expB)); - } - break; - } - break; - case '/': - switch (Trees_Symbol(expA)) { - case REAL: - if (IsReal(expA) && IsReal(expB)) { - if (Trees_Real(expB) != 0) { - result = Trees_NewReal(Trees_Real(expA) / Trees_Real(expB)); - } else { - Oberon_PrintError("warning: division by zero"); - } - } - break; - } - break; - case DIV: - if (IsInteger(expA) && IsInteger(expB)) { - if (Trees_Integer(expB) > 0) { - result = Trees_NewInteger(OBNC_DIV(Trees_Integer(expA), Trees_Integer(expB))); - } else { - Oberon_PrintError("error: positive divisor expected in DIV expression: %" OBNC_INT_MOD "d", Trees_Integer(expB)); - exit(EXIT_FAILURE); - } - } - break; - case MOD: - if (IsInteger(expA) && IsInteger(expB)) { - if (Trees_Integer(expB) > 0) { - result = Trees_NewInteger(OBNC_MOD(Trees_Integer(expA), Trees_Integer(expB))); - } else { - Oberon_PrintError("error: positive divisor expected in MOD expression: %" OBNC_INT_MOD "d", Trees_Integer(expB)); - exit(EXIT_FAILURE); - } - } - break; - case AND: - if (IsBoolean(expA) && IsBoolean(expB)) { - if (Trees_Symbol(expA) == TRUE) { - result = expB; - } else { - result = expA; - } - } - break; - } - - return result; -} - - -static const char *DesignatorString(Trees_Node designator) -{ - const char *baseName, *result; - - assert(IsDesignator(designator)); - - baseName = Trees_Name(BaseIdent(designator)); - if (FirstSelector(designator) != NULL) { - result = Util_String("%s...", baseName); - } else { - result = Util_String("%s", baseName); - } - return result; -} - - -static const char *OperatorString(int operator) -{ - const char *result = ""; - - switch (operator) { - case '+': - result = "+"; - break; - case '-': - result = "-"; - break; - case '*': - result = "*"; - break; - case '/': - result = "/"; - break; - case DIV: - result = "DIV"; - break; - case MOD: - result = "MOD"; - break; - case OR: - result = "OR"; - break; - case AND: - result = "AND"; - break; - case NOT: - result = "not"; - break; - case '=': - result = "="; - break; - case NOT_EQ: - result = "#"; - break; - case '<': - result = "<"; - break; - case LE: - result = "<="; - break; - case '>': - result = ">"; - break; - case GE: - result = ">="; - break; - case IS: - result = "IS"; - break; - default: - assert(0); - } - return result; -} - - -/*functions for statement productions*/ - -static int Writable(Trees_Node designator) -{ - Trees_Node ident, type; - int kind, result; - - assert(IsDesignator(designator)); - - ident = BaseIdent(designator); - kind = Trees_Kind(ident); - type = Trees_Type(ident); - result = ((kind == TREES_VARIABLE_KIND) && ! Trees_Imported(ident)) - || (kind == TREES_VAR_PARAM_KIND) - || ((kind == TREES_VALUE_PARAM_KIND) && ! Types_IsArray(type) && ! Types_IsRecord(type)); - return result; -} - - -static const char *AssignmentErrorContext(int context, int paramPos) -{ - const char *result; - - switch (context) { - case ASSIGNMENT_CONTEXT: - result = Util_String("assignment"); - break; - case PARAM_SUBST_CONTEXT: - assert(paramPos >= 0); - result = Util_String("substitution of parameter %d", paramPos + 1); - break; - case PROC_RESULT_CONTEXT: - result = Util_String("return clause"); - break; - default: - assert(0); - } - return result; -} - - -static void ValidateAssignment(Trees_Node expression, Trees_Node targetType, int context, int paramPos) -{ - const char *errorContext; - - assert(expression != NULL); - assert(targetType != NULL); - assert(context >= 0); - assert(paramPos >= 0); - if (Types_AssignmentCompatible(expression, targetType)) { - if (Types_IsByte(targetType) && IsInteger(expression)) { - Range_CheckByte(Trees_Integer(expression)); - } - } else { - errorContext = AssignmentErrorContext(context, paramPos); - if (IsString(expression) && Types_IsCharacterArray(targetType) && !Types_IsOpenArray(targetType)) { - Oberon_PrintError("error: string too long in %s: %" OBNC_INT_MOD "d + 1 > %" OBNC_INT_MOD "d", errorContext, Types_StringLength(Trees_Type(expression)), Trees_Integer(Types_ArrayLength(targetType))); - exit(EXIT_FAILURE); - } else if (Types_IsPredeclaredProcedure(Trees_Type(expression)) - && Types_IsProcedure(targetType)) { - Oberon_PrintError("error: non-predeclared procedure expected in %s", errorContext); - exit(EXIT_FAILURE); - } else { - Oberon_PrintError("error: incompatible types in %s: %s -> %s", - errorContext, TypeString(Trees_Type(expression)), TypeString(targetType)); - exit(EXIT_FAILURE); - } - } -} - - -static void ValidateActualParameter(Trees_Node actualParam, Trees_Node formalParam, int paramPos, Trees_Node procDesignator) -{ - Trees_Node formalType, actualType; - - formalType = Trees_Type(formalParam); - actualType = Trees_Type(actualParam); - - if ((Trees_Kind(formalParam) == TREES_VALUE_PARAM_KIND) - || (IsDesignator(actualParam) && Writable(actualParam))) { - if (Types_IsOpenArray(formalType)) { - if (! Types_ArrayCompatible(actualType, formalType)) { - Oberon_PrintError("error: array incompatible types in substitution of parameter %d in %s: %s -> %s", paramPos + 1, DesignatorString(procDesignator), TypeString(actualType), TypeString(formalType)); - exit(EXIT_FAILURE); - } - } else if (Trees_Kind(formalParam) == TREES_VALUE_PARAM_KIND) { - if (! Types_AssignmentCompatible(actualParam, formalType)) { - if (Types_IsString(actualType) && Types_IsCharacterArray(formalType)) { - Oberon_PrintError("error: string too long in substitution of parameter %d: %" OBNC_INT_MOD "d + 1 > %" OBNC_INT_MOD "d", paramPos + 1, Types_StringLength(actualType), Trees_Integer(Types_ArrayLength(formalType))); - } else { - Oberon_PrintError("error: assignment incompatible types in substitution of parameter %d in %s: %s -> %s", paramPos + 1, DesignatorString(procDesignator), TypeString(actualType), TypeString(formalType)); - } - exit(EXIT_FAILURE); - } - } else if (Trees_Kind(formalParam) == TREES_VAR_PARAM_KIND) { - if (Types_IsRecord(formalType)) { - if (Types_IsRecord(actualType)) { - if (! Types_Extends(formalType, actualType)) { - Oberon_PrintError("error: incompatible record types in substitution of parameter %d in %s: %s -> %s", paramPos + 1, DesignatorString(procDesignator), TypeString(actualType), TypeString(formalType)); - exit(EXIT_FAILURE); - } - } else { - Oberon_PrintError("error: record expected in substitution of parameter %d in %s: %s -> %s", paramPos + 1, DesignatorString(procDesignator), TypeString(actualType), TypeString(formalType)); - exit(EXIT_FAILURE); - } - } else { - if (! Types_Same(actualType, formalType)) { - Oberon_PrintError("error: same types expected in substitution of parameter %d in %s: %s -> %s", paramPos + 1, DesignatorString(procDesignator), TypeString(actualType), TypeString(formalType)); - exit(EXIT_FAILURE); - } - } - } - } else { - Oberon_PrintError("error: writable variable expected in substitution of parameter %d in %s", - paramPos + 1, DesignatorString(procDesignator)); - exit(EXIT_FAILURE); - } -} - - -static void ValidateProcedureCall(Trees_Node expList, Trees_Node fpList, Trees_Node procDesignator) -{ - Trees_Node exp, formalParam, fpType; - int pos; - - pos = 0; - while ((expList != NULL) && (fpList != NULL)) { - exp = Trees_Left(expList); - CheckIsValueExpression(exp); - formalParam = Trees_Left(fpList); - fpType = Trees_Type(formalParam); - ValidateActualParameter(exp, formalParam, pos, procDesignator); - - if (Types_IsChar(fpType) && (Trees_Symbol(exp) == STRING)) { - Trees_SetLeft(Trees_NewChar(Trees_String(exp)[0]), expList); - } - expList = Trees_Right(expList); - fpList = Trees_Right(fpList); - pos++; - } - if ((expList == NULL) && (fpList != NULL)) { - Oberon_PrintError("error: too few actual parameters in procedure call: %s", DesignatorString(procDesignator)); - exit(EXIT_FAILURE); - } else if ((expList != NULL) && (fpList == NULL)) { - Oberon_PrintError("error: too many actual parameters in procedure call: %s", DesignatorString(procDesignator)); - exit(EXIT_FAILURE); - } -} - - -static void ValidateProcedureKind(const char procName[], int functionCallExpected, int isFunctionCall) -{ - if (isFunctionCall && ! functionCallExpected) { - Oberon_PrintError("error: function procedure expected: %s", procName); - exit(EXIT_FAILURE); - } else if (! isFunctionCall && functionCallExpected) { - Oberon_PrintError("error: proper procedure expected: %s", procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateParameterCount(const char procName[], int min, int max, int actual) -{ - assert(min >= 0); - assert(min <= max); - assert(actual >= 0); - - if ((actual < min) || (actual > max)) { - if (min == max) { - Oberon_PrintError("error: %d parameter(s) expected: %s", min, procName); - } else { - Oberon_PrintError("error: %d or %d parameters expected: %s", min, max, procName); - } - exit(EXIT_FAILURE); - } -} - - -static void ValidateTypeParameter(const char procName[], Trees_Node param, int pos) -{ - if (! (IsDesignator(param) && (Trees_Kind(BaseIdent(param)) == TREES_TYPE_KIND))) { - Oberon_PrintError("error: type identifier expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateValueParameter(const char procName[], Trees_Node param, int pos) -{ - if (! IsValueExpression(param)) { - Oberon_PrintError("error: expression expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateVariableParameter(const char procName[], Trees_Node param, int pos) -{ - if (! IsDesignator(param)) { - Oberon_PrintError("error: variable expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } else if (! Writable(param)) { - Oberon_PrintError("error: writable variable expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateScalarParameter(const char procName[], Trees_Node paramType, int pos) -{ - assert(Types_IsType(paramType)); - - if (! Types_Scalar(paramType)) { - Oberon_PrintError("error: scalar type expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateIntegerParameter(const char procName[], Trees_Node param, int pos) -{ - if (! Types_IsInteger(Trees_Type(param))) { - Oberon_PrintError("error: integer expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static void ValidateRealParameter(const char procName[], Trees_Node param, int pos) -{ - if (! Types_IsReal(Trees_Type(param))) { - Oberon_PrintError("error: parameter of type REAL expected in substitution of parameter %d: %s", pos + 1, procName); - exit(EXIT_FAILURE); - } -} - - -static OBNC_INTEGER TypeSize(Trees_Node type) -{ - OBNC_INTEGER result = 0; - - switch (Trees_Symbol(Types_Structure(type))) { - case TREES_BOOLEAN_TYPE: - result = sizeof (int); - break; - case TREES_CHAR_TYPE: - result = sizeof (char); - break; - case TREES_INTEGER_TYPE: - result = sizeof (OBNC_INTEGER); - break; - case TREES_REAL_TYPE: - result = sizeof (OBNC_REAL); - break; - case TREES_BYTE_TYPE: - result = sizeof (unsigned char); - break; - case ARRAY: - result = Trees_Integer(Types_ArrayLength(type)) * TypeSize(Types_ElementType(type)); - break; - case RECORD: - case POINTER: - case PROCEDURE: - /*cannot be calculated in the Oberon-to-C translation*/ - break; - default: - assert(0); - } - return result; -} - - -static Trees_Node PredeclaredProcedureAST(const char procName[], Trees_Node expList, int isFunctionCall) -{ - static const struct { const char *name; int symbol; } symbols[] = { - {"Abs", TREES_ABS_PROC}, - {"AsChar", TREES_CHR_PROC}, - {"AsInt", TREES_ORD_PROC}, - {"AsReal", TREES_FLT_PROC}, - {"Assert", TREES_ASSERT_PROC}, - {"Decrement", TREES_DEC_PROC}, - {"Floor", TREES_FLOOR_PROC}, - {"Increment", TREES_INC_PROC}, - {"Length", TREES_LEN_PROC}, - {"New", TREES_NEW_PROC}, - - {"ADR", TREES_ADR_PROC}, - {"SIZE", TREES_SIZE_PROC}, - {"BIT", TREES_BIT_PROC}, - {"GET", TREES_GET_PROC}, - {"PUT", TREES_PUT_PROC}, - {"COPY", TREES_COPY_PROC}, - {"VAL", TREES_VAL_PROC}}; - - int paramCount, pos, symbol; - Trees_Node curr, resultType, result; - Trees_Node param[3], paramTypes[3]; - const char *unqualProcName; - - /*set actual parameters*/ - paramCount = 0; - curr = expList; - while ((paramCount < LEN(param)) && (curr != NULL)) { - param[paramCount] = Trees_Left(curr); - paramTypes[paramCount] = Trees_Type(Trees_Left(curr)); - paramCount++; - curr = Trees_Right(curr); - } - - /*find procedure symbol*/ - unqualProcName = strchr(procName, '.'); - if (unqualProcName != NULL) { - unqualProcName++; - } else { - unqualProcName = procName; - } - pos = 0; - while ((pos < LEN(symbols)) && (strcmp(symbols[pos].name, unqualProcName) != 0)) { - pos++; - } - assert(pos < LEN(symbols)); - symbol = symbols[pos].symbol; - - /*validate parameters and build syntax tree*/ - result = NULL; - resultType = NULL; - switch (symbol) { - case TREES_ABS_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - switch (Trees_Symbol(Types_Structure(paramTypes[0]))) { - case TREES_INTEGER_TYPE: - if (IsInteger(param[0])) { - result = Trees_NewInteger(OBNC_ABS_INT(Trees_Integer(param[0]))); - } - break; - case TREES_REAL_TYPE: - if (IsReal(param[0])) { - result = Trees_NewReal(OBNC_ABS_FLT(Trees_Real(param[0]))); - } - break; - case TREES_BYTE_TYPE: - /*do nothing*/ - break; - default: - Oberon_PrintError("error: numeric parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - if (result == NULL) { - resultType = paramTypes[0]; - } - break; - case TREES_LEN_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - if (Types_IsArray(paramTypes[0])) { - if (! Types_IsOpenArray(paramTypes[0])) { - result = Types_ArrayLength(paramTypes[0]); - } else { - resultType = Trees_NewLeaf(TREES_INTEGER_TYPE); - } - } else { - Oberon_PrintError("error: array parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_FLOOR_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateRealParameter(procName, param[0], 0); - if (IsReal(param[0])) { - OBNC_REAL x = Trees_Real(param[0]); - Range_CheckFLOOR(x); - result = Trees_NewInteger(OBNC_FLOOR(x)); - } else { - resultType = Trees_NewLeaf(TREES_INTEGER_TYPE); - } - break; - case TREES_FLT_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - if (IsInteger(param[0])) { - result = Trees_NewReal(OBNC_FLT(Trees_Integer(param[0]))); - } else { - resultType = Trees_NewLeaf(TREES_REAL_TYPE); - } - break; - case TREES_ORD_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - switch (Trees_Symbol(Types_Structure(paramTypes[0]))) { - case TREES_CHAR_TYPE: - /*do nothing*/ - break; - case TREES_STRING_TYPE: - if (Types_StringLength(paramTypes[0]) <= 1) { - result = Trees_NewInteger((unsigned char) Trees_String(param[0])[0]); - } else { - Oberon_PrintError("error: single-character string parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_BOOLEAN_TYPE: - if (Trees_Symbol(param[0]) == TRUE) { - result = Trees_NewInteger(1); - } else if (Trees_Symbol(param[0]) == FALSE) { - result = Trees_NewInteger(0); - } - break; - default: - Oberon_PrintError("error: character parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - if (result == NULL) { - resultType = Trees_NewLeaf(TREES_INTEGER_TYPE); - } - break; - case TREES_CHR_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - if (IsInteger(param[0])) { - OBNC_INTEGER i = Trees_Integer(param[0]); - Range_CheckCHR(i); - result = Trees_NewChar(OBNC_CHR(i)); - } else { - resultType = Trees_NewLeaf(TREES_CHAR_TYPE); - } - break; - case TREES_INC_PROC: /*fall through*/ - case TREES_DEC_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 1, 2, paramCount); - ValidateVariableParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - if (paramCount == 2) { - ValidateIntegerParameter(procName, param[1], 1); - } - break; - case TREES_ASSERT_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateValueParameter(procName, param[0], 0); - if (! Types_IsBoolean(paramTypes[0])) { - Oberon_PrintError("error: boolean parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_NEW_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateVariableParameter(procName, param[0], 0); - if (! Types_IsPointer(paramTypes[0])) { - Oberon_PrintError("error: pointer parameter expected: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_ADR_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateVariableParameter(procName, param[0], 0); - resultType = Trees_NewLeaf(TREES_INTEGER_TYPE); - break; - case TREES_SIZE_PROC: - { - OBNC_INTEGER size; - - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 1, 1, paramCount); - ValidateTypeParameter(procName, param[0], 0); - size = TypeSize(Trees_Type(BaseIdent(param[0]))); - if (size > 0) { - result = Trees_NewInteger(size); - } else { - resultType = Trees_NewLeaf(TREES_INTEGER_TYPE); - } - } - break; - case TREES_BIT_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 2, 2, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - ValidateValueParameter(procName, param[1], 1); - ValidateIntegerParameter(procName, param[1], 1); - if (IsInteger(param[1])) { - Range_CheckBIT(Trees_Integer(param[1])); - } - resultType = Trees_NewLeaf(TREES_BOOLEAN_TYPE); - break; - case TREES_GET_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 2, 2, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - ValidateVariableParameter(procName, param[1], 1); - if (! Types_Basic(paramTypes[1])) { - Oberon_PrintError("error: variable of basic type expected in substitution of parameter 2: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_PUT_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 2, 2, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - ValidateValueParameter(procName, param[1], 1); - if (! Types_Basic(paramTypes[1]) && ! Types_IsSingleCharString(paramTypes[1])) { - Oberon_PrintError("error: expression of basic type expected in substitution of parameter 2: %s", procName); - exit(EXIT_FAILURE); - } - break; - case TREES_COPY_PROC: - ValidateProcedureKind(procName, 0, isFunctionCall); - ValidateParameterCount(procName, 3, 3, paramCount); - ValidateValueParameter(procName, param[0], 0); - ValidateIntegerParameter(procName, param[0], 0); - ValidateValueParameter(procName, param[1], 1); - ValidateIntegerParameter(procName, param[1], 1); - ValidateValueParameter(procName, param[2], 2); - ValidateIntegerParameter(procName, param[2], 2); - if (IsInteger(param[2]) && (Trees_Integer(param[2]) < 0)) { - Oberon_PrintError("warning: non-negative count expected in %s: %" OBNC_INT_MOD "d", procName, Trees_Integer(param[2])); - } - break; - case TREES_VAL_PROC: - ValidateProcedureKind(procName, 1, isFunctionCall); - ValidateParameterCount(procName, 2, 2, paramCount); - ValidateTypeParameter(procName, param[0], 0); - ValidateScalarParameter(procName, paramTypes[0], 0); - ValidateValueParameter(procName, param[1], 1); - ValidateScalarParameter(procName, paramTypes[1], 1); - resultType = paramTypes[0]; - if (IsConstExpression(param[1])) { - result = param[1]; - Trees_SetType(resultType, result); - } - break; - default: - assert(0); - } - - if (result == NULL) { - result = Trees_NewNode(symbol, expList, NULL); - if (isFunctionCall) { - assert(resultType != NULL); - Trees_SetType(resultType, result); - } - } - return result; -} - - -static void HandleProcedureCall(Trees_Node designator, Trees_Node expList, int isFunctionCall, Trees_Node *ast) -{ - Trees_Node ident, designatorTypeStruct, fpList, resultType; - - ident = BaseIdent(designator); - if (Types_IsPredeclaredProcedure(Trees_Type(ident))) { - *ast = PredeclaredProcedureAST(Trees_Name(ident), expList, isFunctionCall); - if (*ast == NULL) { - Oberon_PrintError("error: procedure expected"); - exit(EXIT_FAILURE); - } - } else { - /*handle non-predeclared procedure*/ - designatorTypeStruct = Types_Structure(Trees_Type(designator)); - if (Types_IsProcedure(designatorTypeStruct)) { - fpList =Types_Parameters(designatorTypeStruct); - resultType = Types_ResultType(designatorTypeStruct); - ValidateProcedureCall(expList, fpList, designator); - *ast = Trees_NewNode(TREES_PROCEDURE_CALL, designator, expList); - if (isFunctionCall) { - if (resultType != NULL) { - Trees_SetType(resultType, *ast); - } else { - Oberon_PrintError("error: function procedure expected: %s", Trees_Name(ident)); - exit(EXIT_FAILURE); - } - } else if (resultType != NULL) { - Oberon_PrintError("error: proper procedure expected: %s", Trees_Name(ident)); - exit(EXIT_FAILURE); - } - } - } - assert(*ast != NULL); -} - - -static void CheckIntegerLabelDisjointness(Trees_Node rangeA, Trees_Node rangeB) -{ - OBNC_INTEGER aMin, aMax, bMin, bMax; - - if (Trees_Symbol(rangeA) == DOTDOT) { - aMin = Trees_Integer(Trees_Left(rangeA)); - aMax = Trees_Integer(Trees_Right(rangeA)); - } else { - aMin = Trees_Integer(rangeA); - aMax = Trees_Integer(rangeA); - } - if (Trees_Symbol(rangeB) == DOTDOT) { - bMin = Trees_Integer(Trees_Left(rangeB)); - bMax = Trees_Integer(Trees_Right(rangeB)); - } else { - bMin = Trees_Integer(rangeB); - bMax = Trees_Integer(rangeB); - } - - if ((aMin >= bMin) && (aMin <= bMax)) { - Oberon_PrintError("error: case label defined twice: %" OBNC_INT_MOD "d", aMin); - exit(EXIT_FAILURE); - } else if ((bMin >= aMin) && (bMin <= aMax)) { - Oberon_PrintError("error: case label defined twice: %" OBNC_INT_MOD "d", bMin); - exit(EXIT_FAILURE); - } -} - - -static void CheckCharLabelDisjointness(Trees_Node rangeA, Trees_Node rangeB) -{ - char aMin, aMax, bMin, bMax; - int hasRepeatedLabel, repeatedLabel; - - if (Trees_Symbol(rangeA) == DOTDOT) { - aMin = Trees_Char(Trees_Left(rangeA)); - aMax = Trees_Char(Trees_Right(rangeA)); - } else { - aMin = Trees_Char(rangeA); - aMax = Trees_Char(rangeA); - } - if (Trees_Symbol(rangeB) == DOTDOT) { - bMin = Trees_Char(Trees_Left(rangeB)); - bMax = Trees_Char(Trees_Right(rangeB)); - } else { - bMin = Trees_Char(rangeB); - bMax = Trees_Char(rangeB); - } - - if ((aMin >= bMin) && (aMin <= bMax)) { - hasRepeatedLabel = 1; - repeatedLabel = aMin; - } else if ((bMin >= aMin) && (bMin <= aMax)) { - hasRepeatedLabel = 1; - repeatedLabel = bMin; - } else { - hasRepeatedLabel = 0; - } - if (hasRepeatedLabel) { - if (isprint(repeatedLabel)) { - Oberon_PrintError("error: case label defined twice: \"%c\"", repeatedLabel); - } else { - Oberon_PrintError("error: case label defined twice: 0%XX", repeatedLabel); - } - exit(EXIT_FAILURE); - } -} - - -static void CheckCaseLabelUniqueness(Trees_Node newLabelRange) -{ - int labelSymbol; - Trees_Node labelList, definedLabelRange; - - if (Trees_Symbol(newLabelRange) == DOTDOT) { - labelSymbol = Trees_Symbol(Trees_Left(newLabelRange)); - } else { - labelSymbol = Trees_Symbol(newLabelRange); - } - - labelList = Trees_Left(caseLabelsStack); - while (labelList != NULL) { - definedLabelRange = Trees_Left(labelList); - switch (labelSymbol) { - case INTEGER: - CheckIntegerLabelDisjointness(definedLabelRange, newLabelRange); - break; - case TREES_CHAR_CONSTANT: - CheckCharLabelDisjointness(definedLabelRange, newLabelRange); - break; - case IDENT: - if (Types_Same(definedLabelRange, newLabelRange)) { - Oberon_PrintError("error: type case label defined twice: %s", Trees_Name(newLabelRange)); - exit(EXIT_FAILURE); - } - break; - default: - assert(0); - } - labelList = Trees_Right(labelList); - } -} - - -/*functions for module productions*/ - -static void ExportSymbolTable(const char symfilePath[]) -{ - const char *tempSymfilePath; - - if (! Files_Exists(".obnc")) { - Files_CreateDir(".obnc"); - } - tempSymfilePath = Util_String(".obnc/%s.sym.%d", inputModuleName, getpid()); - Table_Export(tempSymfilePath); - Files_Move(tempSymfilePath, symfilePath); -} diff --git a/src/y.tab.h b/src/y.tab.h deleted file mode 100644 index 25f59a6..0000000 --- a/src/y.tab.h +++ /dev/null @@ -1,171 +0,0 @@ -/* A Bison parser, made by GNU Bison 3.5.1. */ - -/* Bison interface for Yacc-like parsers in C - - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, - Inc. - - 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 3 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, see . */ - -/* As a special exception, you may create a larger work that contains - part or all of the Bison parser skeleton and distribute that work - under terms of your choice, so long as that work isn't itself a - parser generator using the skeleton or a modified version thereof - as a parser skeleton. Alternatively, if you modify or redistribute - the parser skeleton itself, you may (at your option) remove this - special exception, which will cause the skeleton and the resulting - Bison output files to be licensed under the GNU General Public - License without this special exception. - - This special exception was added by the Free Software Foundation in - version 2.2 of Bison. */ - -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ - -#ifndef YY_YY_Y_TAB_H_INCLUDED -# define YY_YY_Y_TAB_H_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - TOKEN_START = 258, - AND = 259, - ARRAY = 260, - BEGIN_ = 261, - BY = 262, - CASE = 263, - CONST = 264, - DIV = 265, - DO = 266, - ELSE = 267, - ELSIF = 268, - END = 269, - FALSE = 270, - FOR = 271, - IF = 272, - IMPORT = 273, - IS = 274, - MOD = 275, - MODULE = 276, - NIL = 277, - NOT = 278, - OF = 279, - OR = 280, - POINTER = 281, - PROCEDURE = 282, - RECORD = 283, - REPEAT = 284, - RETURN = 285, - THEN = 286, - TO = 287, - TRUE = 288, - TYPE = 289, - UNTIL = 290, - VAR = 291, - WHILE = 292, - BECOMES = 293, - DOTDOT = 294, - GE = 295, - LE = 296, - NOT_EQ = 297, - IDENT = 298, - INTEGER = 299, - REAL = 300, - STRING = 301, - TOKEN_END = 302 - }; -#endif -/* Tokens. */ -#define TOKEN_START 258 -#define AND 259 -#define ARRAY 260 -#define BEGIN_ 261 -#define BY 262 -#define CASE 263 -#define CONST 264 -#define DIV 265 -#define DO 266 -#define ELSE 267 -#define ELSIF 268 -#define END 269 -#define FALSE 270 -#define FOR 271 -#define IF 272 -#define IMPORT 273 -#define IS 274 -#define MOD 275 -#define MODULE 276 -#define NIL 277 -#define NOT 278 -#define OF 279 -#define OR 280 -#define POINTER 281 -#define PROCEDURE 282 -#define RECORD 283 -#define REPEAT 284 -#define RETURN 285 -#define THEN 286 -#define TO 287 -#define TRUE 288 -#define TYPE 289 -#define UNTIL 290 -#define VAR 291 -#define WHILE 292 -#define BECOMES 293 -#define DOTDOT 294 -#define GE 295 -#define LE 296 -#define NOT_EQ 297 -#define IDENT 298 -#define INTEGER 299 -#define REAL 300 -#define STRING 301 -#define TOKEN_END 302 - -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -union YYSTYPE -{ -#line 107 "Oberon.y" - - const char *ident; - OBNC_INTEGER integer; - OBNC_REAL real; - const char *string; - Trees_Node node; - -#line 159 "y.tab.h" - -}; -typedef union YYSTYPE YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif - - -extern YYSTYPE yylval; - -int yyparse (void); - -#endif /* !YY_YY_Y_TAB_H_INCLUDED */ -- 2.49.0