From 987a086daecf446b68b316dd074dbaca0aac56dd Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Tue, 25 Feb 2025 01:43:22 -0500 Subject: [PATCH 01/31] added initial block rules --- grammar.y | 7 + lex.yy.c | 2100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ runner | Bin 0 -> 31656 bytes runner.c | 2 +- 4 files changed, 2108 insertions(+), 1 deletion(-) create mode 100644 lex.yy.c create mode 100755 runner diff --git a/grammar.y b/grammar.y index 591d80a..0acc0c9 100644 --- a/grammar.y +++ b/grammar.y @@ -53,5 +53,12 @@ %token RELEASE 614 %token COMMENT 700 %% +B : '{' E '}'; //Braced Expressions can have braces removed to get regular expressions +D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations +E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment +Maybe_D : D + | ; //Either D or not +l : A ';' l; + | ; //a declaration list can either be empty or be an assignment followed by a semi-colon and another list %% diff --git a/lex.yy.c b/lex.yy.c new file mode 100644 index 0000000..c4dad48 --- /dev/null +++ b/lex.yy.c @@ -0,0 +1,2100 @@ +#line 2 "lex.yy.c" + +#line 4 "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 */ + +#define yywrap() (/*CONSTCOND*/1) +#define YY_SKIP_YYWRAP +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 50 +#define YY_END_OF_BUFFER 51 +/* 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_accept[147] = + { 0, + 0, 0, 51, 49, 47, 46, 48, 24, 49, 20, + 25, 49, 36, 37, 18, 16, 30, 17, 27, 19, + 32, 29, 28, 21, 22, 45, 45, 38, 39, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 40, 26, + 41, 0, 34, 0, 0, 0, 0, 31, 32, 23, + 45, 45, 45, 13, 45, 45, 45, 45, 45, 6, + 45, 45, 45, 45, 45, 45, 45, 33, 0, 0, + 0, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 0, 0, 0, + 35, 0, 45, 45, 45, 8, 45, 45, 45, 45, + + 44, 45, 45, 45, 7, 42, 9, 45, 0, 35, + 0, 0, 45, 45, 45, 45, 43, 45, 45, 45, + 45, 45, 5, 0, 45, 45, 45, 45, 45, 45, + 45, 45, 11, 3, 2, 45, 45, 45, 1, 14, + 15, 45, 12, 10, 4, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 6, 1, 1, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, + 22, 23, 1, 1, 24, 25, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 26, 27, 28, 1, 24, 1, 29, 24, 30, 31, + + 32, 33, 34, 35, 36, 24, 24, 37, 24, 38, + 39, 40, 24, 41, 42, 43, 44, 45, 46, 47, + 48, 24, 49, 50, 51, 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[52] = + { 0, + 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, + 1, 1, 1, 4, 4, 1, 1, 1, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, + 1 + } ; + +static const flex_int16_t yy_base[156] = + { 0, + 0, 0, 203, 204, 204, 204, 204, 204, 46, 204, + 204, 175, 189, 204, 204, 204, 204, 177, 204, 204, + 181, 176, 204, 204, 204, 0, 158, 204, 204, 22, + 161, 18, 25, 23, 151, 162, 22, 158, 204, 204, + 204, 52, 204, 53, 183, 51, 55, 204, 173, 204, + 0, 151, 158, 0, 159, 145, 143, 148, 146, 0, + 140, 145, 34, 149, 136, 139, 142, 204, 63, 165, + 69, 139, 134, 133, 141, 140, 129, 140, 137, 131, + 135, 134, 121, 126, 131, 130, 124, 71, 73, 75, + 204, 81, 128, 127, 129, 0, 116, 124, 112, 120, + + 0, 124, 111, 110, 0, 0, 0, 118, 86, 204, + 88, 90, 120, 106, 117, 108, 0, 109, 112, 101, + 97, 103, 0, 92, 102, 97, 95, 108, 72, 69, + 75, 63, 0, 0, 0, 58, 51, 34, 0, 0, + 0, 27, 0, 0, 0, 204, 104, 108, 58, 112, + 116, 120, 124, 128, 132 + } ; + +static const flex_int16_t yy_def[156] = + { 0, + 146, 1, 146, 146, 146, 146, 146, 146, 147, 146, + 146, 148, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 149, 149, 146, 146, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 146, 146, + 146, 147, 146, 146, 146, 146, 150, 146, 146, 146, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 146, 150, 151, + 152, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 150, 153, 154, + 146, 152, 149, 149, 149, 149, 149, 149, 149, 149, + + 149, 149, 149, 149, 149, 149, 149, 149, 155, 146, + 153, 154, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 155, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 0, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static const flex_int16_t yy_nxt[256] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 4, 26, 27, 28, 4, 29, 30, 31, + 26, 32, 33, 26, 26, 34, 26, 35, 26, 26, + 36, 26, 37, 26, 26, 38, 26, 26, 39, 40, + 41, 43, 53, 58, 56, 60, 64, 43, 42, 45, + 61, 51, 65, 54, 57, 70, 71, 145, 59, 66, + 81, 144, 44, 88, 71, 82, 83, 45, 44, 91, + 92, 88, 71, 110, 111, 88, 71, 143, 45, 142, + 42, 110, 92, 45, 141, 42, 70, 89, 146, 111, + + 88, 71, 70, 89, 42, 42, 140, 42, 45, 139, + 138, 45, 69, 69, 69, 69, 70, 70, 70, 70, + 90, 90, 90, 90, 109, 109, 109, 109, 112, 112, + 112, 112, 124, 124, 124, 124, 137, 136, 135, 134, + 133, 132, 131, 130, 129, 128, 127, 126, 125, 123, + 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, + 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, + 98, 97, 96, 95, 94, 93, 89, 87, 86, 85, + 84, 80, 79, 78, 77, 76, 75, 74, 73, 72, + 49, 68, 67, 63, 62, 55, 52, 50, 49, 48, + + 47, 46, 146, 3, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static const flex_int16_t yy_chk[256] = + { 0, + 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, 9, 30, 33, 32, 34, 37, 42, 44, 46, + 34, 149, 37, 30, 32, 47, 47, 142, 33, 37, + 63, 138, 9, 69, 69, 63, 63, 46, 42, 71, + 71, 88, 88, 89, 89, 90, 90, 137, 46, 136, + 44, 92, 92, 46, 132, 44, 109, 109, 111, 111, + + 112, 112, 124, 124, 147, 147, 131, 147, 148, 130, + 129, 148, 150, 150, 150, 150, 151, 151, 151, 151, + 152, 152, 152, 152, 153, 153, 153, 153, 154, 154, + 154, 154, 155, 155, 155, 155, 128, 127, 126, 125, + 122, 121, 120, 119, 118, 116, 115, 114, 113, 108, + 104, 103, 102, 100, 99, 98, 97, 95, 94, 93, + 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, + 77, 76, 75, 74, 73, 72, 70, 67, 66, 65, + 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, + 49, 45, 38, 36, 35, 31, 27, 22, 21, 18, + + 13, 12, 3, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "lexicalStructure.lex" +/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */ +/* so we placed the citation here. */ +/* definitions */ +#line 8 "lexicalStructure.lex" + #include + #include "typedefs.h" + int line_number = 1, column_number = 1; + #ifndef DEBUG + #define DEBUG 0 + #endif +#line 561 "lex.yy.c" +#line 22 "lexicalStructure.lex" + /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ + /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ +#line 565 "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 + + 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 26 "lexicalStructure.lex" + + +#line 785 "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_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 204 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = 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 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 28 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} + YY_BREAK +case 2: +YY_RULE_SETUP +#line 29 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 30 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 31 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 33 "lexicalStructure.lex" +{if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 34 "lexicalStructure.lex" +{if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 35 "lexicalStructure.lex" +{if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 36 "lexicalStructure.lex" +{if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 37 "lexicalStructure.lex" +{if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 38 "lexicalStructure.lex" +{if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 39 "lexicalStructure.lex" +{if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 40 "lexicalStructure.lex" +{if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 41 "lexicalStructure.lex" +{if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 43 "lexicalStructure.lex" +{if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 44 "lexicalStructure.lex" +{if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 46 "lexicalStructure.lex" +{if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 47 "lexicalStructure.lex" +{if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 48 "lexicalStructure.lex" +{if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 49 "lexicalStructure.lex" +{if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 50 "lexicalStructure.lex" +{if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 51 "lexicalStructure.lex" +{if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 52 "lexicalStructure.lex" +{if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 53 "lexicalStructure.lex" +{if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 54 "lexicalStructure.lex" +{if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 55 "lexicalStructure.lex" +{if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 56 "lexicalStructure.lex" +{if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 57 "lexicalStructure.lex" +{if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 59 "lexicalStructure.lex" +{if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 60 "lexicalStructure.lex" +{if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 61 "lexicalStructure.lex" +{if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 62 "lexicalStructure.lex" +{if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 64 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 65 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 66 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} + YY_BREAK +case 35: +/* rule 35 can match eol */ +YY_RULE_SETUP +#line 67 "lexicalStructure.lex" +{if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 69 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 70 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 72 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 73 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 75 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 76 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 78 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 79 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 80 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 82 "lexicalStructure.lex" +{if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} + YY_BREAK +case 46: +/* rule 46 can match eol */ +YY_RULE_SETUP +#line 84 "lexicalStructure.lex" +{line_number++; column_number = 1;} + YY_BREAK +case 47: +YY_RULE_SETUP +#line 85 "lexicalStructure.lex" +{column_number++;} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 86 "lexicalStructure.lex" +{column_number++;} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 87 "lexicalStructure.lex" +{column_number++; return 1999;} + YY_BREAK +case 50: +YY_RULE_SETUP +#line 89 "lexicalStructure.lex" +ECHO; + YY_BREAK +#line 1094 "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. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + 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); + + 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); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + 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; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 146); + + 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 = file ? (isatty( fileno(file) ) > 0) : 0; + + 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; + +/* 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; + + /* 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 89 "lexicalStructure.lex" + + diff --git a/runner b/runner new file mode 100755 index 0000000000000000000000000000000000000000..6fa219f4df413b87ee586177c95df0f39c987b44 GIT binary patch literal 31656 zcmeHw3w%>my6;NqrWGj-NNjmYK%PQNQBY8k@(2b6tO|&u7($!Uj%`xY1gKgC3QEqV zilYZ{yyqPCI!BMManz&eI8IR{ywozH;=3wpVsWg9PJKY`|67lpy|<0`-1|Fo&hOq| zSG)6l>wB%&x1M_^`$o^aIav+|Q=tbtkMY<^f>J6OiFzf$SSg#r^6)v7ox*y8oQ9GFr$fsQ5;D zrGjrS=(+s_T|u)R)s1th;5%!ru(vGtgAyt|sxH!VOFg&LQ?Nr;go3I*sZQvcBJJ5> z33wC~wChz#Jv*E&)R=;l28ByMja2;Kq*o^OHeD#}*x{A3dS6xVQt-yz(5GaeZ_PlzI0OBq40P&WU6t#s4D>!|NH=)) zuoi@_?2vzSMK8!er(wG*`Pmuh&t#xKpMgFkL;j~{kY56NUpA1r>wqAraR_GEa89v) zT!$#hm)PWQlk`#>o%wv_tNp&p>Y%@-`q}`itgZN9Xp=g9vh64f836|G2 z5QK3S4hZ8Afx+^cfIl1vhgl^)LSa&*7-YlcRiHw;0{H+f81f-c{z!Ew$O5aYVSH7% zIuc;z!d!K|KN4wRlwlfn&SdA$n>%xs@ATp`CK>4I#gmzD?!x&#q!CzAT^|XA7tWtm z6AA_v`j^)Pkj{$QP*9fFCq%mxL~UkatjWTkgMSic{j<}}aT<@Z*nU_c|D^ELZCfxr z^5XT(HM^Py`0Ho4v?l=GdU-y`X{wsuzWgCSv$#zONr*=C~id0&XJ zgo)l)(g<{z=mSjjP7~cckShNr+cfs7p!}5RYCI;M@>8PI*s8)9X+H-9>H{j2nCNOw zA>I@do#qP_N=@v{{6%nx2L?39Pcca}k&|L%FHSk|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[PATCH 02/31] added more symbol table functions --- grammar.y | 3 ++- runner.c | 3 ++- symbol_table.c | 31 +++++++++++++++++++++++++++++++ symbol_table.h | 10 +++++----- test_keywords.st | 0 test_operators.st | 0 test_real_alpha_2.st | 0 7 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 test_keywords.st create mode 100644 test_operators.st create mode 100644 test_real_alpha_2.st diff --git a/grammar.y b/grammar.y index 0acc0c9..d930f2a 100644 --- a/grammar.y +++ b/grammar.y @@ -4,6 +4,7 @@ // Prologue %{ #include + #include "symbol_table.c" %} %token ID 101 @@ -53,7 +54,7 @@ %token RELEASE 614 %token COMMENT 700 %% -B : '{' E '}'; //Braced Expressions can have braces removed to get regular expressions +B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment Maybe_D : D diff --git a/runner.c b/runner.c index 435cd24..a2be6b6 100644 --- a/runner.c +++ b/runner.c @@ -81,7 +81,8 @@ int run(FILE *alpha) { } if(token == 1999){ printf("On line number %d and column number %d we have an invalid character:%s\n",line_number,column_number,yytext); - return -1;} + //return -1; +} column_number += yyleng; } diff --git a/symbol_table.c b/symbol_table.c index e87ebd8..2a7729f 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -101,6 +101,37 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr){ } } +SymbolTable * getParent(SymbolTable* st){ + return st->ParentScope; + } + +ListOfTable * getChildren(SymbolTable* st){ + return st->Children_Scope; + } +SymbolTable * getFirstChild(ListOfTable * lt){ + return lt->table; + } +ListOfTable * getRestOfChildren(ListOfTable * lt){ + return lt->next; + } +TableNode * getFirstEntry(SymbolTable * st){ + return st->entries; + } +TableNode * getNextEntry(TableNode * tn){ + return tn->next; + } +char * getType(TableNode * tn){ + return tn->theType; + } +char * getName(TableNode * tn){ + return tn->theName; + } +int getLine(SymbolTable * st){ + return st->line; + } +int getColumn(SymbolTable *st){ + return st->column; + } //uncomment the below main function along with the headers above for a simple standalone test of table and entry creation /* diff --git a/symbol_table.h b/symbol_table.h index 57ae1bc..0d30f59 100644 --- a/symbol_table.h +++ b/symbol_table.h @@ -17,11 +17,11 @@ typedef struct TableNode{ }TableNode; typedef struct SymbolTable{ - TableNode* entries; - struct SymbolTable* Parent_Scope; - struct ListOfTable* Children_Scope; - int Line_Number; - int Column_Number; + TableNode* entries; + struct SymbolTable* Parent_Scope; + struct ListOfTable* Children_Scope; + int Line_Number; + int Column_Number; }SymbolTable; diff --git a/test_keywords.st b/test_keywords.st new file mode 100644 index 0000000..e69de29 diff --git a/test_operators.st b/test_operators.st new file mode 100644 index 0000000..e69de29 diff --git a/test_real_alpha_2.st b/test_real_alpha_2.st new file mode 100644 index 0000000..e69de29 From 046ccf194b8e75a7e306a68f12f5e59c062a9b14 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Wed, 26 Feb 2025 12:52:29 -0500 Subject: [PATCH 03/31] edited symbol table functions --- grammar.y | 22 +++++++++++++++------- lex.yy.c | 11 +++++------ symbol_table.c | 6 +++--- test_keywords.st | 0 test_operators.st | 0 test_real_alpha_2.st | 0 6 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 test_keywords.st delete mode 100644 test_operators.st delete mode 100644 test_real_alpha_2.st diff --git a/grammar.y b/grammar.y index d930f2a..172058c 100644 --- a/grammar.y +++ b/grammar.y @@ -54,12 +54,20 @@ %token RELEASE 614 %token COMMENT 700 %% -B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions -D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations -E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment -Maybe_D : D - | ; //Either D or not -l : A ';' l; - | ; //a declaration list can either be empty or be an assignment followed by a semi-colon and another list + +start: /*empty for now*/ + ; +// B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions +// D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations +// E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment +// Maybe_D : D +// | ; //Either D or not +//l : A ';' l; +// | ; //a declaration list can either be empty or be an assignment followed by a semi-colon and another list %% + +int main() { + return yyparse(); +} + diff --git a/lex.yy.c b/lex.yy.c index c4dad48..49b4eed 100644 --- a/lex.yy.c +++ b/lex.yy.c @@ -1,6 +1,5 @@ -#line 2 "lex.yy.c" -#line 4 "lex.yy.c" +#line 3 "lex.yy.c" #define YY_INT_ALIGNED short int @@ -557,11 +556,11 @@ char *yytext; #ifndef DEBUG #define DEBUG 0 #endif -#line 561 "lex.yy.c" +#line 560 "lex.yy.c" #line 22 "lexicalStructure.lex" /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ -#line 565 "lex.yy.c" +#line 564 "lex.yy.c" #define INITIAL 0 @@ -781,7 +780,7 @@ YY_DECL #line 26 "lexicalStructure.lex" -#line 785 "lex.yy.c" +#line 784 "lex.yy.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1090,7 +1089,7 @@ YY_RULE_SETUP #line 89 "lexicalStructure.lex" ECHO; YY_BREAK -#line 1094 "lex.yy.c" +#line 1093 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); diff --git a/symbol_table.c b/symbol_table.c index 2a7729f..11ba544 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -102,7 +102,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr){ } SymbolTable * getParent(SymbolTable* st){ - return st->ParentScope; + return st->Parent_Scope; } ListOfTable * getChildren(SymbolTable* st){ @@ -127,10 +127,10 @@ char * getName(TableNode * tn){ return tn->theName; } int getLine(SymbolTable * st){ - return st->line; + return st->Line_Number; } int getColumn(SymbolTable *st){ - return st->column; + return st->Column_Number; } //uncomment the below main function along with the headers above for a simple standalone test of table and entry creation diff --git a/test_keywords.st b/test_keywords.st deleted file mode 100644 index e69de29..0000000 diff --git a/test_operators.st b/test_operators.st deleted file mode 100644 index e69de29..0000000 diff --git a/test_real_alpha_2.st b/test_real_alpha_2.st deleted file mode 100644 index e69de29..0000000 From 3ce8cbae59a3d6568f36ad2cbfbf7eed2f8c26f1 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Wed, 26 Feb 2025 15:57:08 -0500 Subject: [PATCH 04/31] Parser compiles from .y and .lex files --- grammar.y | 10 +- lex.yy.c | 2099 ------------------------------------------ lexicalStructure.lex | 1 + parser | Bin 0 -> 36568 bytes 4 files changed, 8 insertions(+), 2102 deletions(-) delete mode 100644 lex.yy.c create mode 100755 parser diff --git a/grammar.y b/grammar.y index 172058c..2bd520d 100644 --- a/grammar.y +++ b/grammar.y @@ -5,8 +5,10 @@ %{ #include #include "symbol_table.c" + extern int yylex(void); + void yyerror(const char *err); %} - +/* %token ID 101 %token T_INTEGER 201 %token T_ADDRESS 202 @@ -52,7 +54,7 @@ %token DOT 612 %token RESERVE 613 %token RELEASE 614 -%token COMMENT 700 +%token COMMENT 700 */ %% start: /*empty for now*/ @@ -67,7 +69,9 @@ start: /*empty for now*/ %% +void yyerror(const char *err) { + fprintf(stderr, "Error: %s\n", err); +} int main() { return yyparse(); } - diff --git a/lex.yy.c b/lex.yy.c deleted file mode 100644 index 49b4eed..0000000 --- a/lex.yy.c +++ /dev/null @@ -1,2099 +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 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP -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 50 -#define YY_END_OF_BUFFER 51 -/* 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_accept[147] = - { 0, - 0, 0, 51, 49, 47, 46, 48, 24, 49, 20, - 25, 49, 36, 37, 18, 16, 30, 17, 27, 19, - 32, 29, 28, 21, 22, 45, 45, 38, 39, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 40, 26, - 41, 0, 34, 0, 0, 0, 0, 31, 32, 23, - 45, 45, 45, 13, 45, 45, 45, 45, 45, 6, - 45, 45, 45, 45, 45, 45, 45, 33, 0, 0, - 0, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 0, 0, 0, - 35, 0, 45, 45, 45, 8, 45, 45, 45, 45, - - 44, 45, 45, 45, 7, 42, 9, 45, 0, 35, - 0, 0, 45, 45, 45, 45, 43, 45, 45, 45, - 45, 45, 5, 0, 45, 45, 45, 45, 45, 45, - 45, 45, 11, 3, 2, 45, 45, 45, 1, 14, - 15, 45, 12, 10, 4, 0 - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 1, 1, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, - 22, 23, 1, 1, 24, 25, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 26, 27, 28, 1, 24, 1, 29, 24, 30, 31, - - 32, 33, 34, 35, 36, 24, 24, 37, 24, 38, - 39, 40, 24, 41, 42, 43, 44, 45, 46, 47, - 48, 24, 49, 50, 51, 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[52] = - { 0, - 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, - 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, - 1, 1, 1, 4, 4, 1, 1, 1, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, - 1 - } ; - -static const flex_int16_t yy_base[156] = - { 0, - 0, 0, 203, 204, 204, 204, 204, 204, 46, 204, - 204, 175, 189, 204, 204, 204, 204, 177, 204, 204, - 181, 176, 204, 204, 204, 0, 158, 204, 204, 22, - 161, 18, 25, 23, 151, 162, 22, 158, 204, 204, - 204, 52, 204, 53, 183, 51, 55, 204, 173, 204, - 0, 151, 158, 0, 159, 145, 143, 148, 146, 0, - 140, 145, 34, 149, 136, 139, 142, 204, 63, 165, - 69, 139, 134, 133, 141, 140, 129, 140, 137, 131, - 135, 134, 121, 126, 131, 130, 124, 71, 73, 75, - 204, 81, 128, 127, 129, 0, 116, 124, 112, 120, - - 0, 124, 111, 110, 0, 0, 0, 118, 86, 204, - 88, 90, 120, 106, 117, 108, 0, 109, 112, 101, - 97, 103, 0, 92, 102, 97, 95, 108, 72, 69, - 75, 63, 0, 0, 0, 58, 51, 34, 0, 0, - 0, 27, 0, 0, 0, 204, 104, 108, 58, 112, - 116, 120, 124, 128, 132 - } ; - -static const flex_int16_t yy_def[156] = - { 0, - 146, 1, 146, 146, 146, 146, 146, 146, 147, 146, - 146, 148, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 149, 149, 146, 146, 149, - 149, 149, 149, 149, 149, 149, 149, 149, 146, 146, - 146, 147, 146, 146, 146, 146, 150, 146, 146, 146, - 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 146, 150, 151, - 152, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 150, 153, 154, - 146, 152, 149, 149, 149, 149, 149, 149, 149, 149, - - 149, 149, 149, 149, 149, 149, 149, 149, 155, 146, - 153, 154, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 155, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 0, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static const flex_int16_t yy_nxt[256] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 4, 26, 27, 28, 4, 29, 30, 31, - 26, 32, 33, 26, 26, 34, 26, 35, 26, 26, - 36, 26, 37, 26, 26, 38, 26, 26, 39, 40, - 41, 43, 53, 58, 56, 60, 64, 43, 42, 45, - 61, 51, 65, 54, 57, 70, 71, 145, 59, 66, - 81, 144, 44, 88, 71, 82, 83, 45, 44, 91, - 92, 88, 71, 110, 111, 88, 71, 143, 45, 142, - 42, 110, 92, 45, 141, 42, 70, 89, 146, 111, - - 88, 71, 70, 89, 42, 42, 140, 42, 45, 139, - 138, 45, 69, 69, 69, 69, 70, 70, 70, 70, - 90, 90, 90, 90, 109, 109, 109, 109, 112, 112, - 112, 112, 124, 124, 124, 124, 137, 136, 135, 134, - 133, 132, 131, 130, 129, 128, 127, 126, 125, 123, - 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, - 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, - 98, 97, 96, 95, 94, 93, 89, 87, 86, 85, - 84, 80, 79, 78, 77, 76, 75, 74, 73, 72, - 49, 68, 67, 63, 62, 55, 52, 50, 49, 48, - - 47, 46, 146, 3, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static const flex_int16_t yy_chk[256] = - { 0, - 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, 9, 30, 33, 32, 34, 37, 42, 44, 46, - 34, 149, 37, 30, 32, 47, 47, 142, 33, 37, - 63, 138, 9, 69, 69, 63, 63, 46, 42, 71, - 71, 88, 88, 89, 89, 90, 90, 137, 46, 136, - 44, 92, 92, 46, 132, 44, 109, 109, 111, 111, - - 112, 112, 124, 124, 147, 147, 131, 147, 148, 130, - 129, 148, 150, 150, 150, 150, 151, 151, 151, 151, - 152, 152, 152, 152, 153, 153, 153, 153, 154, 154, - 154, 154, 155, 155, 155, 155, 128, 127, 126, 125, - 122, 121, 120, 119, 118, 116, 115, 114, 113, 108, - 104, 103, 102, 100, 99, 98, 97, 95, 94, 93, - 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, - 77, 76, 75, 74, 73, 72, 70, 67, 66, 65, - 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, - 49, 45, 38, 36, 35, 31, 27, 22, 21, 18, - - 13, 12, 3, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "lexicalStructure.lex" -/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */ -/* so we placed the citation here. */ -/* definitions */ -#line 8 "lexicalStructure.lex" - #include - #include "typedefs.h" - int line_number = 1, column_number = 1; - #ifndef DEBUG - #define DEBUG 0 - #endif -#line 560 "lex.yy.c" -#line 22 "lexicalStructure.lex" - /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ - /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ -#line 564 "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 - - 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 26 "lexicalStructure.lex" - - -#line 784 "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_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 204 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = 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 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 28 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} - YY_BREAK -case 2: -YY_RULE_SETUP -#line 29 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} - YY_BREAK -case 3: -YY_RULE_SETUP -#line 30 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} - YY_BREAK -case 4: -YY_RULE_SETUP -#line 31 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} - YY_BREAK -case 5: -YY_RULE_SETUP -#line 33 "lexicalStructure.lex" -{if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} - YY_BREAK -case 6: -YY_RULE_SETUP -#line 34 "lexicalStructure.lex" -{if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} - YY_BREAK -case 7: -YY_RULE_SETUP -#line 35 "lexicalStructure.lex" -{if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} - YY_BREAK -case 8: -YY_RULE_SETUP -#line 36 "lexicalStructure.lex" -{if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} - YY_BREAK -case 9: -YY_RULE_SETUP -#line 37 "lexicalStructure.lex" -{if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} - YY_BREAK -case 10: -YY_RULE_SETUP -#line 38 "lexicalStructure.lex" -{if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} - YY_BREAK -case 11: -YY_RULE_SETUP -#line 39 "lexicalStructure.lex" -{if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} - YY_BREAK -case 12: -YY_RULE_SETUP -#line 40 "lexicalStructure.lex" -{if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 41 "lexicalStructure.lex" -{if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} - YY_BREAK -case 14: -YY_RULE_SETUP -#line 43 "lexicalStructure.lex" -{if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} - YY_BREAK -case 15: -YY_RULE_SETUP -#line 44 "lexicalStructure.lex" -{if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} - YY_BREAK -case 16: -YY_RULE_SETUP -#line 46 "lexicalStructure.lex" -{if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} - YY_BREAK -case 17: -YY_RULE_SETUP -#line 47 "lexicalStructure.lex" -{if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} - YY_BREAK -case 18: -YY_RULE_SETUP -#line 48 "lexicalStructure.lex" -{if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} - YY_BREAK -case 19: -YY_RULE_SETUP -#line 49 "lexicalStructure.lex" -{if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} - YY_BREAK -case 20: -YY_RULE_SETUP -#line 50 "lexicalStructure.lex" -{if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} - YY_BREAK -case 21: -YY_RULE_SETUP -#line 51 "lexicalStructure.lex" -{if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} - YY_BREAK -case 22: -YY_RULE_SETUP -#line 52 "lexicalStructure.lex" -{if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} - YY_BREAK -case 23: -YY_RULE_SETUP -#line 53 "lexicalStructure.lex" -{if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} - YY_BREAK -case 24: -YY_RULE_SETUP -#line 54 "lexicalStructure.lex" -{if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} - YY_BREAK -case 25: -YY_RULE_SETUP -#line 55 "lexicalStructure.lex" -{if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} - YY_BREAK -case 26: -YY_RULE_SETUP -#line 56 "lexicalStructure.lex" -{if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} - YY_BREAK -case 27: -YY_RULE_SETUP -#line 57 "lexicalStructure.lex" -{if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} - YY_BREAK -case 28: -YY_RULE_SETUP -#line 59 "lexicalStructure.lex" -{if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} - YY_BREAK -case 29: -YY_RULE_SETUP -#line 60 "lexicalStructure.lex" -{if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} - YY_BREAK -case 30: -YY_RULE_SETUP -#line 61 "lexicalStructure.lex" -{if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} - YY_BREAK -case 31: -YY_RULE_SETUP -#line 62 "lexicalStructure.lex" -{if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} - YY_BREAK -case 32: -YY_RULE_SETUP -#line 64 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} - YY_BREAK -case 33: -YY_RULE_SETUP -#line 65 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} - YY_BREAK -case 34: -YY_RULE_SETUP -#line 66 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} - YY_BREAK -case 35: -/* rule 35 can match eol */ -YY_RULE_SETUP -#line 67 "lexicalStructure.lex" -{if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} - YY_BREAK -case 36: -YY_RULE_SETUP -#line 69 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} - YY_BREAK -case 37: -YY_RULE_SETUP -#line 70 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} - YY_BREAK -case 38: -YY_RULE_SETUP -#line 72 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} - YY_BREAK -case 39: -YY_RULE_SETUP -#line 73 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} - YY_BREAK -case 40: -YY_RULE_SETUP -#line 75 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} - YY_BREAK -case 41: -YY_RULE_SETUP -#line 76 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} - YY_BREAK -case 42: -YY_RULE_SETUP -#line 78 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} - YY_BREAK -case 43: -YY_RULE_SETUP -#line 79 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} - YY_BREAK -case 44: -YY_RULE_SETUP -#line 80 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} - YY_BREAK -case 45: -YY_RULE_SETUP -#line 82 "lexicalStructure.lex" -{if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} - YY_BREAK -case 46: -/* rule 46 can match eol */ -YY_RULE_SETUP -#line 84 "lexicalStructure.lex" -{line_number++; column_number = 1;} - YY_BREAK -case 47: -YY_RULE_SETUP -#line 85 "lexicalStructure.lex" -{column_number++;} - YY_BREAK -case 48: -YY_RULE_SETUP -#line 86 "lexicalStructure.lex" -{column_number++;} - YY_BREAK -case 49: -YY_RULE_SETUP -#line 87 "lexicalStructure.lex" -{column_number++; return 1999;} - YY_BREAK -case 50: -YY_RULE_SETUP -#line 89 "lexicalStructure.lex" -ECHO; - YY_BREAK -#line 1093 "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. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - 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); - - 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); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - 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; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 146); - - 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 = file ? (isatty( fileno(file) ) > 0) : 0; - - 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; - -/* 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; - - /* 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 89 "lexicalStructure.lex" - - diff --git a/lexicalStructure.lex b/lexicalStructure.lex index 64b2863..f4fb603 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -7,6 +7,7 @@ %{ #include #include "typedefs.h" + #include "grammar.tab.h" int line_number = 1, column_number = 1; #ifndef DEBUG #define DEBUG 0 diff --git a/parser b/parser new file mode 100755 index 0000000000000000000000000000000000000000..6d64eed3fbcd28afb96fef45560f8a51dc9797bd GIT binary patch literal 36568 zcmeHwd3;pW`S+P57s6%&W-uVjfPicX0Rh9NVHp^dB`k5PI82fWi6)senSsO-2@Vm) zOB8XVS}n9%ZL1Y6Dq5F-Ku}SFMMaBkROmY~)JDJ>sde7(bCx@It_khueSh!o_s5%? z&z(xj&mD$`c@bcT>q zQ1OlYvIU=6;I4}VT|u)R`6i=8@H47o;VJ2tEwcVfkI1B#CH1nTo`S8?5eh1Ql27Q& zl=iGpR*xxY)hm>GRyYSX=}?gJpkvudfByeTe%VrQ!%f1D6&{!MQ&8o%1bXC`|MW$_&7yr>W=*}A#j~z7suhZvko>#el1IbXiNrzG)Wfzx^fKxohYYaP(MAb&OJy;*Mvlcy#72^;w`E0`oYTg1^ld_-0LMV*kR>fVFxVe<`sKA<=*mgR)8O0 zIVn&I>Um{Vr02;;jv$r#+{oSIFY=W#Z)Fi|t|>3_d%;9W@@{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RMvvxXg!I(03k)Wul5w@?r?Qj%Wk~o3BcK_dZ5|rK1ZVumJt#0v0NaKR;T=((!*= z-t<+af%LL+xV0SLy^oS|18D2CqI^l3Ict6zP5oTF&{I*!((wc&vJlW;E;x9QvI5Vc z#w6U}m3xalq#&`fVn0jgQ(QXGbWFmGBNdpx(s@5kr?mj2eS9QJ_ZG_8zc3%xR7%(o z%K*kT6fU36MB!*4OGmh{bgVy0C>;Nb4!W;{rI*@vW2x8|phLj{B5C}RtogVE2`sq` z{YlaFW1&3Mm)p}HsX`kGzulDH`bSOayt@_u3{tw)X!FCis z)cq<2CrUb&*Zi=S-vcV$t5W*vewKopB!kLGzEk>gS&!%W#h$s+SNF#h%(6J#lEnW7 z;8`zo`6(kD>OPaa3^eYyseBZ?4YG9aN~P8PD+RN;HQ{4(`6U_u8A1Ex(fX_VX$q?A zTdV(6{U4P2v!p?Fe@;PlKaccD$LhZwpi#M$edGE;UPq|=mJs2Gwf%nvs#)J5^%Tq? zrsIwE-gwpz>AadEKJF zJxg#DRQH9Iyw!jErM`+Ewcnv&@B*bNpd&WP-a(qGsPxsovVzAg^|$8#CyV~dl_20y zkgiY7hl(FXqkRM_q8xUN`(zm Date: Thu, 27 Feb 2025 14:13:19 -0500 Subject: [PATCH 05/31] testing why grammar does not work --- calc.h | 48 +++++++++++++++++++++++++++++++++++++++++++ grammar.y | 17 +++++++++++---- lexicalStructure.lex | 2 +- parser | Bin 36568 -> 36592 bytes testGrammar.y | 41 ++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 calc.h create mode 100644 testGrammar.y diff --git a/calc.h b/calc.h new file mode 100644 index 0000000..2580e93 --- /dev/null +++ b/calc.h @@ -0,0 +1,48 @@ +/* Function type. */ +typedef double (func_t) (double); +/* Data type for links in the chain of symbols. */ +struct symrec +{ + char *name; /* name of symbol */ + int type; /* type of symbol: either VAR or FUN */ + union + { + double var; /* value of a VAR */ + func_t *fun; /* value of a FUN */ + } value; + struct symrec *next; /* link field */ +}; +typedef struct symrec symrec; + +/* The symbol table: a chain of 'struct symrec'. */ +extern symrec *sym_table; + +symrec *putsym (char const *name, int sym_type); +symrec *getsym (char const *name); +struct init +{ + char const *name; + func_t *fun; +}; +struct init const funs[] = +{ + { "atan", atan }, + { "cos", cos }, + { "exp", exp }, + { "ln", log }, + { "sin", sin }, + { "sqrt", sqrt }, + { 0, 0 }, +}; +/* The symbol table: a chain of 'struct symrec'. */ +symrec *sym_table; +/* Put functions in table. */ +static void +init_table (void) +{ + for (int i = 0; funs[i].name; i++) + { + symrec *ptr = putsym (funs[i].name, FUN); + ptr->value.fun = funs[i].fun; + } +} diff --git a/grammar.y b/grammar.y index 2bd520d..0b31edb 100644 --- a/grammar.y +++ b/grammar.y @@ -8,9 +8,9 @@ extern int yylex(void); void yyerror(const char *err); %} -/* + %token ID 101 -%token T_INTEGER 201 +%token T_INTEGER %token T_ADDRESS 202 %token T_BOOLEAN 203 %token T_CHARACTER 204 @@ -54,10 +54,19 @@ %token DOT 612 %token RESERVE 613 %token RELEASE 614 -%token COMMENT 700 */ +%token COMMENT 700 %% -start: /*empty for now*/ +input: /*empty for now*/ + OPTIONAL; + +OPTIONAL_OPTIONAL: + OPTIONAL + | OPTIONAL_OPTIONAL OPTIONAL {printf("expansion\n");}; + +OPTIONAL: + '[' {printf("success");} + |%empty ; // B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions // D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations diff --git a/lexicalStructure.lex b/lexicalStructure.lex index f4fb603..3bd0332 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -6,7 +6,7 @@ %option header-file="flex.h" %{ #include - #include "typedefs.h" + //#include "typedefs.h" #include "grammar.tab.h" int line_number = 1, column_number = 1; #ifndef DEBUG diff --git a/parser b/parser index 6d64eed3fbcd28afb96fef45560f8a51dc9797bd..432a493003aad234aab1cddeee6bf7bfb3b18924 100755 GI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u=fo@k;yiz5}SiH<;8-$a)I%bKViFsF$km&7O& znkXBP(?qiY=}oi_kkUji00zPj5CK0x5c~ks;kPtKxduN#GyDK8O||QmzU5V$+TA6a z-2Vn1M`_Dbg7;c6B6uPMNU8MX@>u-S<88wtDtWcf*WcJhO*=sAKk4gXf>v z!Pgo5CVVnwkDISI_&R*K#nZE6q&{{lW>Ndod1+U(xgP(PComEN%F=G+J64jm3tCDs zcrSXg&@v`HRnXlGuNj86nx7MrG!>T~dzKpffE*zY7a$cI{4hFSXi4*D%Lh*{Bigfu zwqmH@KN284Z}15eQIw)oFQ&0Y$@AU+kHxT&{tP45U-$oHar5WE%Tl=H-XU)OI`|ND z_>wWwKN^ak41NGzDq5qI<Mn;bi zuE|D(OuQknj-Sn;YipC`aTL7HA~({&bt&>fnze4U@_Y`xv@TD%l}R_&<;nXgZM{Xg zmqBCKCr3Va-?)s#!eO!6vuNk~yogQMAnf5UEx`GP`W$_~K1E(i@f%Xot{WkY@sZv% zY*OO6tHiGsR1X?_4sG6GiRfp{l6ykx4DDp9*{&%7=g{D4c? zmk(`oW|%VB4T>j|&cMZeV!N@Lg10&3RNApE#guPMbv~WhHk9hN1<7#~tfh4Pk23e5 z#nEIf#c!{bhn27pw`qAwX%D)fCHuK|M_B>+Rb=?hn /* For printf, etc. */ + #include /* For pow, used in the grammar. */ + #include "calc.h" /* Contains definition of 'symrec'. */ + int yylex (void); + void yyerror (char const *); +%} +%define api.value.type union /* Generate YYSTYPE from these types: */ +%token NUM /* Double precision number. */ +%token VAR FUN /* Symbol table pointer: variable/function. */ +%nterm exp +%precedence '=' +%left '-' '+' +%left '*' '/' +%precedence NEG /* negation--unary minus */ +%right '^' /* exponentiation */ +%% /* The grammar follows. */ +input: + %empty +| input line +; +line: + '\n' +| exp '\n' { printf ("%.10g\n", $1); } +| error '\n' { yyerrok; } +; +exp: + NUM +| VAR { $$ = $1->value.var; } +| VAR '=' exp { $$ = $3; $1->value.var = $3; } +| FUN '(' exp ')' { $$ = $1->value.fun ($3); } +| exp '+' exp { $$ = $1 + $3; } +| exp '-' exp { $$ = $1 - $3; } +| exp '*' exp { $$ = $1 * $3; } +| exp '/' exp { $$ = $1 / $3; } +| '-' exp %prec NEG { $$ = -$2; } +| exp '^' exp { $$ = pow ($1, $3); } +| '(' exp ')' { $$ = $2; } +; +/* End of grammar. */ +%% From c85540afdfbbd7b864c97d94b5e93fbd564869d1 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 27 Feb 2025 15:22:02 -0500 Subject: [PATCH 06/31] updated testing for parser --- grammar.y | 16 +- lex.yy.c | 2100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ parser | Bin 36592 -> 36592 bytes 3 files changed, 2108 insertions(+), 8 deletions(-) create mode 100644 lex.yy.c diff --git a/grammar.y b/grammar.y index 0b31edb..2015769 100644 --- a/grammar.y +++ b/grammar.y @@ -7,6 +7,8 @@ #include "symbol_table.c" extern int yylex(void); void yyerror(const char *err); + extern char* yytext; + extern int yychar; %} %token ID 101 @@ -59,15 +61,9 @@ input: /*empty for now*/ OPTIONAL; - -OPTIONAL_OPTIONAL: - OPTIONAL - | OPTIONAL_OPTIONAL OPTIONAL {printf("expansion\n");}; OPTIONAL: - '[' {printf("success");} - |%empty - ; + '[' {printf("success");}; // B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions // D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations // E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment @@ -82,5 +78,9 @@ void yyerror(const char *err) { fprintf(stderr, "Error: %s\n", err); } int main() { - return yyparse(); + int a; + while (a = yyparse()){ + printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar); + } + return 0; } diff --git a/lex.yy.c b/lex.yy.c new file mode 100644 index 0000000..dca4c08 --- /dev/null +++ b/lex.yy.c @@ -0,0 +1,2100 @@ + +#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 */ + +#define yywrap() (/*CONSTCOND*/1) +#define YY_SKIP_YYWRAP +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 50 +#define YY_END_OF_BUFFER 51 +/* 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_accept[147] = + { 0, + 0, 0, 51, 49, 47, 46, 48, 24, 49, 20, + 25, 49, 36, 37, 18, 16, 30, 17, 27, 19, + 32, 29, 28, 21, 22, 45, 45, 38, 39, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 40, 26, + 41, 0, 34, 0, 0, 0, 0, 31, 32, 23, + 45, 45, 45, 13, 45, 45, 45, 45, 45, 6, + 45, 45, 45, 45, 45, 45, 45, 33, 0, 0, + 0, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 0, 0, 0, + 35, 0, 45, 45, 45, 8, 45, 45, 45, 45, + + 44, 45, 45, 45, 7, 42, 9, 45, 0, 35, + 0, 0, 45, 45, 45, 45, 43, 45, 45, 45, + 45, 45, 5, 0, 45, 45, 45, 45, 45, 45, + 45, 45, 11, 3, 2, 45, 45, 45, 1, 14, + 15, 45, 12, 10, 4, 0 + } ; + +static const YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 6, 1, 1, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, + 22, 23, 1, 1, 24, 25, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, + 26, 27, 28, 1, 24, 1, 29, 24, 30, 31, + + 32, 33, 34, 35, 36, 24, 24, 37, 24, 38, + 39, 40, 24, 41, 42, 43, 44, 45, 46, 47, + 48, 24, 49, 50, 51, 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[52] = + { 0, + 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, + 1, 1, 1, 4, 4, 1, 1, 1, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, + 1 + } ; + +static const flex_int16_t yy_base[156] = + { 0, + 0, 0, 203, 204, 204, 204, 204, 204, 46, 204, + 204, 175, 189, 204, 204, 204, 204, 177, 204, 204, + 181, 176, 204, 204, 204, 0, 158, 204, 204, 22, + 161, 18, 25, 23, 151, 162, 22, 158, 204, 204, + 204, 52, 204, 53, 183, 51, 55, 204, 173, 204, + 0, 151, 158, 0, 159, 145, 143, 148, 146, 0, + 140, 145, 34, 149, 136, 139, 142, 204, 63, 165, + 69, 139, 134, 133, 141, 140, 129, 140, 137, 131, + 135, 134, 121, 126, 131, 130, 124, 71, 73, 75, + 204, 81, 128, 127, 129, 0, 116, 124, 112, 120, + + 0, 124, 111, 110, 0, 0, 0, 118, 86, 204, + 88, 90, 120, 106, 117, 108, 0, 109, 112, 101, + 97, 103, 0, 92, 102, 97, 95, 108, 72, 69, + 75, 63, 0, 0, 0, 58, 51, 34, 0, 0, + 0, 27, 0, 0, 0, 204, 104, 108, 58, 112, + 116, 120, 124, 128, 132 + } ; + +static const flex_int16_t yy_def[156] = + { 0, + 146, 1, 146, 146, 146, 146, 146, 146, 147, 146, + 146, 148, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 149, 149, 146, 146, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 146, 146, + 146, 147, 146, 146, 146, 146, 150, 146, 146, 146, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 146, 150, 151, + 152, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 150, 153, 154, + 146, 152, 149, 149, 149, 149, 149, 149, 149, 149, + + 149, 149, 149, 149, 149, 149, 149, 149, 155, 146, + 153, 154, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 155, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 0, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static const flex_int16_t yy_nxt[256] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 4, 26, 27, 28, 4, 29, 30, 31, + 26, 32, 33, 26, 26, 34, 26, 35, 26, 26, + 36, 26, 37, 26, 26, 38, 26, 26, 39, 40, + 41, 43, 53, 58, 56, 60, 64, 43, 42, 45, + 61, 51, 65, 54, 57, 70, 71, 145, 59, 66, + 81, 144, 44, 88, 71, 82, 83, 45, 44, 91, + 92, 88, 71, 110, 111, 88, 71, 143, 45, 142, + 42, 110, 92, 45, 141, 42, 70, 89, 146, 111, + + 88, 71, 70, 89, 42, 42, 140, 42, 45, 139, + 138, 45, 69, 69, 69, 69, 70, 70, 70, 70, + 90, 90, 90, 90, 109, 109, 109, 109, 112, 112, + 112, 112, 124, 124, 124, 124, 137, 136, 135, 134, + 133, 132, 131, 130, 129, 128, 127, 126, 125, 123, + 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, + 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, + 98, 97, 96, 95, 94, 93, 89, 87, 86, 85, + 84, 80, 79, 78, 77, 76, 75, 74, 73, 72, + 49, 68, 67, 63, 62, 55, 52, 50, 49, 48, + + 47, 46, 146, 3, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static const flex_int16_t yy_chk[256] = + { 0, + 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, 9, 30, 33, 32, 34, 37, 42, 44, 46, + 34, 149, 37, 30, 32, 47, 47, 142, 33, 37, + 63, 138, 9, 69, 69, 63, 63, 46, 42, 71, + 71, 88, 88, 89, 89, 90, 90, 137, 46, 136, + 44, 92, 92, 46, 132, 44, 109, 109, 111, 111, + + 112, 112, 124, 124, 147, 147, 131, 147, 148, 130, + 129, 148, 150, 150, 150, 150, 151, 151, 151, 151, + 152, 152, 152, 152, 153, 153, 153, 153, 154, 154, + 154, 154, 155, 155, 155, 155, 128, 127, 126, 125, + 122, 121, 120, 119, 118, 116, 115, 114, 113, 108, + 104, 103, 102, 100, 99, 98, 97, 95, 94, 93, + 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, + 77, 76, 75, 74, 73, 72, 70, 67, 66, 65, + 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, + 49, 45, 38, 36, 35, 31, 27, 22, 21, 18, + + 13, 12, 3, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, + 146, 146, 146, 146, 146 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "lexicalStructure.lex" +/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */ +/* so we placed the citation here. */ +/* definitions */ +#line 8 "lexicalStructure.lex" + #include + //#include "typedefs.h" + #include "grammar.tab.h" + int line_number = 1, column_number = 1; + #ifndef DEBUG + #define DEBUG 0 + #endif +#line 561 "lex.yy.c" +#line 23 "lexicalStructure.lex" + /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ + /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ +#line 565 "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 + + 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 27 "lexicalStructure.lex" + + +#line 785 "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_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 204 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = 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 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 29 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} + YY_BREAK +case 2: +YY_RULE_SETUP +#line 30 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} + YY_BREAK +case 3: +YY_RULE_SETUP +#line 31 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 32 "lexicalStructure.lex" +{if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 34 "lexicalStructure.lex" +{if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} + YY_BREAK +case 6: +YY_RULE_SETUP +#line 35 "lexicalStructure.lex" +{if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} + YY_BREAK +case 7: +YY_RULE_SETUP +#line 36 "lexicalStructure.lex" +{if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} + YY_BREAK +case 8: +YY_RULE_SETUP +#line 37 "lexicalStructure.lex" +{if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 38 "lexicalStructure.lex" +{if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 39 "lexicalStructure.lex" +{if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} + YY_BREAK +case 11: +YY_RULE_SETUP +#line 40 "lexicalStructure.lex" +{if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 41 "lexicalStructure.lex" +{if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} + YY_BREAK +case 13: +YY_RULE_SETUP +#line 42 "lexicalStructure.lex" +{if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} + YY_BREAK +case 14: +YY_RULE_SETUP +#line 44 "lexicalStructure.lex" +{if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} + YY_BREAK +case 15: +YY_RULE_SETUP +#line 45 "lexicalStructure.lex" +{if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} + YY_BREAK +case 16: +YY_RULE_SETUP +#line 47 "lexicalStructure.lex" +{if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} + YY_BREAK +case 17: +YY_RULE_SETUP +#line 48 "lexicalStructure.lex" +{if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} + YY_BREAK +case 18: +YY_RULE_SETUP +#line 49 "lexicalStructure.lex" +{if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} + YY_BREAK +case 19: +YY_RULE_SETUP +#line 50 "lexicalStructure.lex" +{if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} + YY_BREAK +case 20: +YY_RULE_SETUP +#line 51 "lexicalStructure.lex" +{if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} + YY_BREAK +case 21: +YY_RULE_SETUP +#line 52 "lexicalStructure.lex" +{if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} + YY_BREAK +case 22: +YY_RULE_SETUP +#line 53 "lexicalStructure.lex" +{if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} + YY_BREAK +case 23: +YY_RULE_SETUP +#line 54 "lexicalStructure.lex" +{if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} + YY_BREAK +case 24: +YY_RULE_SETUP +#line 55 "lexicalStructure.lex" +{if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} + YY_BREAK +case 25: +YY_RULE_SETUP +#line 56 "lexicalStructure.lex" +{if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} + YY_BREAK +case 26: +YY_RULE_SETUP +#line 57 "lexicalStructure.lex" +{if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} + YY_BREAK +case 27: +YY_RULE_SETUP +#line 58 "lexicalStructure.lex" +{if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} + YY_BREAK +case 28: +YY_RULE_SETUP +#line 60 "lexicalStructure.lex" +{if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} + YY_BREAK +case 29: +YY_RULE_SETUP +#line 61 "lexicalStructure.lex" +{if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} + YY_BREAK +case 30: +YY_RULE_SETUP +#line 62 "lexicalStructure.lex" +{if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} + YY_BREAK +case 31: +YY_RULE_SETUP +#line 63 "lexicalStructure.lex" +{if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} + YY_BREAK +case 32: +YY_RULE_SETUP +#line 65 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} + YY_BREAK +case 33: +YY_RULE_SETUP +#line 66 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} + YY_BREAK +case 34: +YY_RULE_SETUP +#line 67 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} + YY_BREAK +case 35: +/* rule 35 can match eol */ +YY_RULE_SETUP +#line 68 "lexicalStructure.lex" +{if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} + YY_BREAK +case 36: +YY_RULE_SETUP +#line 70 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} + YY_BREAK +case 37: +YY_RULE_SETUP +#line 71 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} + YY_BREAK +case 38: +YY_RULE_SETUP +#line 73 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} + YY_BREAK +case 39: +YY_RULE_SETUP +#line 74 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} + YY_BREAK +case 40: +YY_RULE_SETUP +#line 76 "lexicalStructure.lex" +{if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} + YY_BREAK +case 41: +YY_RULE_SETUP +#line 77 "lexicalStructure.lex" +{if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} + YY_BREAK +case 42: +YY_RULE_SETUP +#line 79 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} + YY_BREAK +case 43: +YY_RULE_SETUP +#line 80 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} + YY_BREAK +case 44: +YY_RULE_SETUP +#line 81 "lexicalStructure.lex" +{if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} + YY_BREAK +case 45: +YY_RULE_SETUP +#line 83 "lexicalStructure.lex" +{if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} + YY_BREAK +case 46: +/* rule 46 can match eol */ +YY_RULE_SETUP +#line 85 "lexicalStructure.lex" +{line_number++; column_number = 1;} + YY_BREAK +case 47: +YY_RULE_SETUP +#line 86 "lexicalStructure.lex" +{column_number++;} + YY_BREAK +case 48: +YY_RULE_SETUP +#line 87 "lexicalStructure.lex" +{column_number++;} + YY_BREAK +case 49: +YY_RULE_SETUP +#line 88 "lexicalStructure.lex" +{column_number++; return 1999;} + YY_BREAK +case 50: +YY_RULE_SETUP +#line 90 "lexicalStructure.lex" +ECHO; + YY_BREAK +#line 1094 "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. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc( (void *) b->yy_ch_buf, + (yy_size_t) (b->yy_buf_size + 2) ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + 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); + + 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); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + } + + 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; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = 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 >= 147 ) + yy_c = yy_meta[yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; + yy_is_jam = (yy_current_state == 146); + + 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 = file ? (isatty( fileno(file) ) > 0) : 0; + + 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; + +/* 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; + + /* 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 90 "lexicalStructure.lex" + + diff --git a/parser b/parser index 432a493003aad234aab1cddeee6bf7bfb3b18924..d8cc1d741f18e0e6e768cac2bbd19e597fd2efc8 100755 GIT binary patch delta 9604 zcmaJ_3s_ZE+TLfwMlcan4woYeq6jE*69N8oLzstI> zz0PiZO>KQmJ?v@nDv4M4Q^NY0V!bMZgjUI>n37HV*(THNe!Fr7=R)RCzxTVCeLL#g z=`+8W5^=G5dR_mwf4I@!ShmeA)<<0(!%pA2` z)OU3z! zq=wCt8EPHdFnM#Z2vkq$wgr1*F>?b;qd^o1E?LKPE7Jux5Rine<>i;wWPmkMny!Rbafbl#>bdPcBAvvZ4im2jBd z%>ikK5#gYOj|z{`-8`x?Qg}mk^GIR#>t?p;nVz~9ygUL)_S#Hm&_C{wdgj@Dq-a?XsFIFJ>*u?20^u90U-F>rCfA2wPFU) z+FPV!f(Tq=D0+BuWNY(T@q(_ zBCY|339c088NxNWhbxWpc;fc*apD6#n)K8&YkW}A(Q%L+Rn9wpK;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Me+qA&QPV7RQxCvAIO>alJj{>@=HS5qUBkp1#I7P+!Zo}SFCiVBZkIzK_>h6 z@>t9FQhiyf=Sy`rY#yT`P?Q$lR_hjsoa&htN1S0L1{MVA_*9h=clDBnQKGl+MP8DhFklD~J zk-9cZ*!NW24c9|KN#?Vw&&F9sbV}>GbPLF2Lsq_M*&`Q-dtT?_K&7awGuf9bqfI63 z*2)w$1}pKo(`<9;f=c7LS4@?Eluq$8ZDj>|oNxMAkxn{u>e;6GtPWh!T)`DF-}NcJ V)_J04t;|`!)@0gVSyvHZ`ab~#xXl0n From f355de059f6a8608b0c1edd2d66e42941628049e Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 27 Feb 2025 16:11:13 -0500 Subject: [PATCH 07/31] added some test files nothing is working t#34 --- library.alpha | 30 ++++++++++++++++++++++++++++++ simple.alpha | 4 ++++ 2 files changed, 34 insertions(+) create mode 100644 library.alpha create mode 100644 simple.alpha diff --git a/library.alpha b/library.alpha new file mode 100644 index 0000000..9bacd6c --- /dev/null +++ b/library.alpha @@ -0,0 +1,30 @@ +(* At compiler start-up your program should create symbol table entries for the four primitive types: + Boolean (1 byte) + character (1 byte) + integer (4 bytes) + address (8 bytes) +You should #include this file at the start of your alpha file. +Some useful types are defined below. +*) +type string: 1 -> character +type BooleanXBoolean: [Boolean: x, y] +type characterXcharacter: [character: x, y] +type integerXinteger: [integer: x, y] + +type Boolean2Boolean: Boolean -> Boolean +type integer2integer: integer -> integer +type character2integer: character -> integer +type Boolean2integer: Boolean -> integer +type string2integer: string -> integer +type integerXinteger2integer: integerXinteger -> integer +type integerXinteger2Boolean: integerXinteger -> Boolean +type characterXcharacter2Boolean: characterXcharacter -> Boolean +type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean +type integer2address: integer -> address +type address2integer: address -> integer +external function printInteger: integer2integer +external function printCharacter: character2integer +external function printBoolean: Boolean2integer +external function reserve: integer2address +external function release: address2integer +function entry: string2integer diff --git a/simple.alpha b/simple.alpha new file mode 100644 index 0000000..13f3c9f --- /dev/null +++ b/simple.alpha @@ -0,0 +1,4 @@ +#include "library.alpha" +entry(arg) := { + return 0; +} From 77596a9d96d29e46dcea21e591f19b08d44f2a9f Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 27 Feb 2025 17:02:17 -0500 Subject: [PATCH 08/31] got it to workgit add grammar.ygit add grammar.ygit add grammar.ygit add grammar.ygit add grammar.ygit add grammar.ygit add grammar.y! t#34 --- grammar.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammar.y b/grammar.y index 2015769..0ce008e 100644 --- a/grammar.y +++ b/grammar.y @@ -63,7 +63,7 @@ input: /*empty for now*/ OPTIONAL; OPTIONAL: - '[' {printf("success");}; + L_BRACKET {printf("success");}; // B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions // D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations // E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment @@ -76,7 +76,7 @@ OPTIONAL: void yyerror(const char *err) { fprintf(stderr, "Error: %s\n", err); -} +} int main() { int a; while (a = yyparse()){ From fad44e21ea5f6994c63175a933fb880dfea67c42 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 27 Feb 2025 17:58:01 -0500 Subject: [PATCH 09/31] added print table functionality to main in grammar.y with custom EOF input in '!' --- grammar.y | 22 ++++++++++++---------- parser | Bin 36592 -> 36648 bytes symbol_table.c | 10 ++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/grammar.y b/grammar.y index 0ce008e..c267eeb 100644 --- a/grammar.y +++ b/grammar.y @@ -8,7 +8,9 @@ extern int yylex(void); void yyerror(const char *err); extern char* yytext; - extern int yychar; + extern int yychar; + SymbolTable * st; + %} %token ID 101 @@ -59,28 +61,28 @@ %token COMMENT 700 %% -input: /*empty for now*/ +start: /*empty for now*/ OPTIONAL; OPTIONAL: L_BRACKET {printf("success");}; -// B : '{'{CreateScope(cur,line,column)} E '}'; //Braced Expressions can have braces removed to get regular expressions -// D : '[' l ']'; //Declaration Lists Brackets can be taken out to get a list of Declarations -// E : Maybe_D U; //An expression can start with an optional D followed by an undeclared segment -// Maybe_D : D -// | ; //Either D or not -//l : A ';' l; -// | ; //a declaration list can either be empty or be an assignment followed by a semi-colon and another list +// %% void yyerror(const char *err) { fprintf(stderr, "Error: %s\n", err); } + int main() { + st=CreateScope(NULL,1,1); int a; - while (a = yyparse()){ + while ((a = yyparse()) != EOF){ printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar); + if(yytext[0] == '!'){ + print_symbol_table(getAncestor(st),stdout); + break; + } } return 0; } diff --git a/parser b/parser index d8cc1d741f18e0e6e768cac2bbd19e597fd2efc8..3a559de4d69ab532788655642731e6d46596d7d6 100755 GIT binary patch delta 10114 zcmZu%3wTXe+TLd;I}$_^awIvTNstR7kwio!B*Bs6o`|@#E-9+Cw5Fuhzc?X+V<&A` zbs4nPnNgh5>d@)*sUqLPYZh8(~T@?Pe=X46_1lNck@|u<=OO!d z>P&UWf7q0PudDqBu=fU=?Kk~ajllHk+FP>~rMTfqVLRt>FGX=^cC>Zvb^I-hQ=Y)WkQQ~E8T;lB=IOqB6Y1N*&l|DJy_R5 zXDi-{Z42h`hkk5fTDCeXg?*70st!$|)L4C5LcrWv7_we+6~tF+u%EH2%me$}5F z%t-H~R`h3!(}x5u?cZ!dhd(fkI#W3tlo`W*O^=Q6fYNWjr@!Cf%3^1NqvQah>HIJ6 z{QG2Cf-r99T9H*K+B+OpFPVbZgGEI`w(JDC5>|j zB=Flk-EI*!Btd_Up;!Xv||(w-Es6@x?77yHp1nQpSr21kWtz=CEV-BcK< zm;41i@O+}U4fDz97IH7iJ#3r4kg+jVWmbo2+Mt<0ApuFY}A zecl4^(((EGeZQw3=i3}N^K8ZS!CzuT%3=C*1XXd)yNB2gttX~7P$9-KyA+D!t?+JO5M^Is&+gjmC+lorZzy=+9Pa9rC-S>$gE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@%h;^df%aX}I={`1cwg%A8N!`k06;&Ix}%%W`E3-mOzL~v^r2kpf9fUt z-xZ+L2)&nbqD{kfFwjsxDG;8nq26GT`GHBdWxA3!Q9n!lq}%|m6ZM#;z~sZ$<_88x z;4afe4OSv#X4w-Zo_&}fs67K~1ic%QvcPDmr?oj$Ia2S}W|J>uUDgB!`(P_|RXfr8 zwR(zp+uLPqos4~7`s`s#)|@Q;gMGV+CD<2~_E}qKDlL7zn_Bw$y027Lu6mX3TVL;? ze%Y7(UhnI@QZB|yc1j;%Dq-Fm6S{265vg2wjg5r*@@%2HFsszD(QY#BW8RzXCO_ub WJivR(8sT!3UEDmtParent_Scope, x); } + +SymbolTable * getAncestor(SymbolTable * table){ + if(table->Parent_Scope == NULL){ + //if table has no parent, return itself + return table; + } else { + //call function recursively to grab ancestor + return getAncestor(table->Parent_Scope); + } +} void print_symbol_table(SymbolTable *table, FILE *file_ptr){ if(table->Parent_Scope == NULL){ fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); From d609dd2dca2da6a5af3adad67a568e0dc307fb81 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 27 Feb 2025 20:03:50 -0500 Subject: [PATCH 10/31] added skeleton rules and grammar to bison file --- grammar.y | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++--- parser | Bin 36648 -> 40856 bytes 2 files changed, 119 insertions(+), 6 deletions(-) diff --git a/grammar.y b/grammar.y index c267eeb..adb4aa7 100644 --- a/grammar.y +++ b/grammar.y @@ -10,7 +10,8 @@ extern char* yytext; extern int yychar; SymbolTable * st; - + char* cur_value; + char* cur_type; %} %token ID 101 @@ -61,12 +62,122 @@ %token COMMENT 700 %% -start: /*empty for now*/ - OPTIONAL; +program: + prototype_or_definition_list; -OPTIONAL: - L_BRACKET {printf("success");}; +prototype_or_definition_list: + prototype prototype_or_definition_list + | definition prototype_or_definition_list + | prototype + | definition + ; +prototype: + L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; +definition: + TYPE ID COLON dblock + | TYPE ID COLON constant ARROW ID + | TYPE ID COLON ID ARROW ID + | ID parameter ASSIGN sblock + ; + +parameter: + L_PAREN ID R_PAREN + | AS L_PAREN idlist R_PAREN + ; + +idlist: + ID COMMA idlist + |ID + ; + +sblock: + L_BRACE {st = CreateScope(st,1,1);} statement_list {st = getParent(st);} R_BRACE + | L_BRACE {st = CreateScope(st,1,1);} dblock statement_list {st = getParent(st);} R_BRACE + ; + +dblock: + L_BRACKET declaration_list R_BRACKET; + +declaration_list: + declaration {CreateEntry(st,cur_type,cur_value);} SEMI_COLON declaration_list + | declaration {CreateEntry(st,cur_type,cur_value);} + ; + +declaration: + ID COLON ID {cur_value = strdup($1);cur_type = strdup($3);}; + +statement_list: + compound_statement statement_list + | compound_statement + | simple_statement SEMI_COLON statement_list + | simple_statement SEMI_COLON + ; + +compound_statement: + WHILE L_PAREN expression R_PAREN sblock + | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock + | sblock + ; + +simple_statement: + assignable ASSIGN expression + | RETURN expression + ; + +assignable: + ID + | assignable ablock + | assignable DOT ID + ; + +expression: + constant + | UnaryOperator expression + | assignable + | expression binaryOperator expression + | L_PAREN expression R_PAREN + | memOp assignable + ; + +ablock: + L_PAREN argument_list R_PAREN; + +argument_list: + expression COMMA argument_list + | expression + ; + +UnaryOperator: + SUB_OR_NEG + | NOT + ; + +memOp: + RESERVE + | RELEASE + ; + +binaryOperator: + ADD + | SUB_OR_NEG + | MUL + | DIV + | REM + | AND + | OR + | LESS_THAN + | EQUAL_TO + ; + +constant: + C_STRING + | C_INTEGER + | C_NULL + | C_CHARACTER + | C_TRUE + | C_FALSE + ; // %% @@ -75,11 +186,13 @@ void yyerror(const char *err) { } int main() { + cur_value[1] = ""; + cur_type[1] = ""; st=CreateScope(NULL,1,1); int a; while ((a = yyparse()) != EOF){ printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar); - if(yytext[0] == '!'){ + if(yytext[0] == '?'){ print_symbol_table(getAncestor(st),stdout); break; } diff --git a/parser b/parser index 3a559de4d69ab532788655642731e6d46596d7d6..05d2da9e80dd27dbbb7f6f3bb90bc8855f15ec55 100755 GIT binary patch delta 13761 zcmZ`=34Bw|svbm3yf)+-r-RXJR!$|0e;^pXuRT+~ns=CTgZ3E8ri z%a;0%_(0}zGg+^T49yf)nZhcwp1i3$9olmaH)=<+Nq#u~|BKlwVz!b1{gUu*U+i4{ z%J@%arj`3&+VI_UzqSuYyh=9flg(xX)tV>ic1r7X!7}B#6Q_Q*?ggUri&SJ7Sjc`k zOt*&0y5sC~E7|Iop?jAc^?OW-^;oQ+I?~{0BI}e)-CSn5n{my4CZ&&NM;a9q3GNiH zYarR3k`k&=V~7+bWj63W`g4$K1z+4i9`CfM(~9clb8427Z##WUKI&Xx7d=G#{iIW{ z6r(NuW$W`8ZAH2$xbTGwgCy8o7xKGIua|BLxh861fF#M%UC1#GHzfZF@`SP>ek^_%AYA%%_gP!*Km9*s_U=3x^v~`@y}ciKiqED9JkwjLixuUvNS9Y$NjFb$-05W9hR-@LbAiB>KaLX z_zSv|B+>X?UTR-S8b7K&$Wl7R<2Wk6Uhe=69QsB3o za{ci;Sr+k(X%NKWjvvw5H@$7YC&7`4(K4t>qa8;}9QRr9HG;&sQ!w5UgQ zlSoU{Y+W`#I(qmpeqIu(i93i!0{_6YrS z8a9l=fv76>YB=Bfv!;v7ALo=qSpr#A7UHw6*&flNOhbvLmb$%gqotb_sxlnx0D7X< zm|OZQg^-Tme&9CroNb$cYe7|durR9>27wn2ljCBgB@ndloqrn`|$k9?d$3Qb-l`%4jr__Kq&k z+9Nwqy}qVIRYIY~`ZlPFKP%PrX`6_dRM{fOuDQDeE8ztEqlEti?8p}75@@>68d~aD zDD=u}tL5cLgZ|IGRz10vtvnsyd(tXf`%1U>_g*`6k*(zx7~FhF4Z1`PRpU4b zK~(E4)`P#$7+T$fP&X=Rg`MGm)PGP-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NO(uu5A<1d`y_892}6G2Me&g2UrrYMGI6W_a^<@^zR`%%2S>e^_FC`O;*au)6;ZDiK z0(Rr&EH-L$7%SM29aJI@g%bAgh5?>Cw0W1ty?KKput@G9c78(?o4PSPs7wx68GCr+ z0JdObSfKe;jhmd_818vn-&~^iWU-qYGlR`X%dKH7cT=%i8O9#llo`CLjJFWaVYYiy ze(-`hLR>J1{R+{1Av|pf%iWwGY~H%Fm#}3J&1ZVS61IDDzUR9^+Cw5nGrO@lJIE;n zWhu+uGQfOB#4Q!=%)c^nh From 078b059d1c34eceb01a0819b1e722d7a8fb981f2 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 27 Feb 2025 20:28:39 -0500 Subject: [PATCH 11/31] parser compiling --- grammar.y | 11 ++++++++--- parser | Bin 40856 -> 40856 bytes 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/grammar.y b/grammar.y index adb4aa7..f9f14e8 100644 --- a/grammar.y +++ b/grammar.y @@ -14,7 +14,12 @@ char* cur_type; %} -%token ID 101 +%union { + int integ; + char * words; +} + +%token ID 101 %token T_INTEGER %token T_ADDRESS 202 %token T_BOOLEAN 203 @@ -186,8 +191,8 @@ void yyerror(const char *err) { } int main() { - cur_value[1] = ""; - cur_type[1] = ""; + cur_value = NULL; + cur_type = NULL; st=CreateScope(NULL,1,1); int a; while ((a = yyparse()) != EOF){ diff --git a/parser b/parser index 05d2da9e80dd27dbbb7f6f3bb90bc8855f15ec55..cb59b833bc9d5254ff75b3e6fa3d5e61bcbefe06 100755 GIT binary patch delta 8886 zcmZ`<3tUvyy5DQ49j{hIE6 z0~F1WKzDDYQK|bP0o}b_@&wS`9*n&167<)h>UFOHCLB1~@y8W~hz*gNOW05i;a{(U zX|h=o1B9Gwr3C?ZYK@j7xYm_lsfbC6YCUBzE{}>3s!3gALrYP2Dk7KUd(bt77 zNsn=Y@$^mR>|!uznNJO=8|#I%UZd@)3)A4$<%!UAudf3!b$2ZR*DeBzwfG6LZ%DsJ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5^&lvd`-sHSp(P{aLw^x zFdwkZiC}Od;6=a%fDD(-#=7_y1YQvg`apR06bt~Co`!*Xin9F-3;;iZe@Ls@MfI|RNa12ca>;444wDC{0V%ssD7OI_jg++>PQFJNn1ft#dQBVLhjk0@9Z_7&`G&Po#I~ zyE7Op10^iw_SA8FNOJP8IY2@kMLEM;Olzff;BNGz`Lt>2>XY0;Ka{^UE#0Ah$v>Z# zrrzRJU@zlwPo}GrcxUwGd@%aKya4@fUV?ry--iBsehB>+{NLzT@VM#e>Q>$v{R%!9 z{W@NNel#zc-b|g#-va&wKZt$|uR=eF$IeJsd+-kEJMw|(Tk>h>Q@DlxF8TO;HQa>JBkggu#9nc@*1JR!-omTL(OPyFcW`1`~-N;ujN^HDkm7H;C=J|Zn zqC{T4$eFyu=Fq)Gf8&9uN>gPQzq}|h*>{KDGdA}CZ{bNy{?g{6I>leH%`NA{JbQVr zC!RMib|zQcVIv0X<51$2S9ssz#N?7(sk_p)kzsRvd^WhhWJz*eJG_xLw}5W~_d>qp z_Of;7+T0p`6x@UO08D?)Y~95+cOX~2iRuqL*}GYNiSGk`fuHhbsIz$N;sI*k(qW71 zscH-#vn0K-C^49*j~O;bQWkJ)NrpO+f4pRlx`$^jO-x>U$K+;0vI!=q^GQoHuxhK( zuj2cbPC#w6uo9DR^b;{DX%Z;k+4A@DVctJSJAj zFSA6HW9;(H$$8j<^j9WgEy_T;2FMDbZhX4Qo From 046cb4b171e2e659193910deb749b63a8da29c88 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 28 Feb 2025 11:50:18 -0500 Subject: [PATCH 12/31] solved shift-reduce errors --- grammar.y | 26 ++++++++++++++++++++++---- parser | Bin 40856 -> 40856 bytes 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/grammar.y b/grammar.y index f9f14e8..ca54a25 100644 --- a/grammar.y +++ b/grammar.y @@ -18,6 +18,22 @@ int integ; char * words; } +//precedence order +%precedence RESERVE +%precedence RELEASE +%precedence DOT +%precedence SUB_OR_NEG +%precedence NOT +%left MUL +%left DIV +%left REM +%left ADD +//need subtraction only here +%left LESS_THAN +%left EQUAL_TO +%left AND +%left OR +%left ASSIGN %token ID 101 %token T_INTEGER @@ -50,7 +66,7 @@ %token COLON 508 %token COMMA 509 %token ARROW 510 -%token ADD 601 +/* %token ADD 601 %token SUB_OR_NEG 602 %token MUL 603 %token DIV 604 @@ -63,8 +79,10 @@ %token OR 611 %token DOT 612 %token RESERVE 613 -%token RELEASE 614 +%token RELEASE 614 */ %token COMMENT 700 + + %% program: @@ -140,7 +158,7 @@ expression: constant | UnaryOperator expression | assignable - | expression binaryOperator expression + | constant binaryOperator expression | L_PAREN expression R_PAREN | memOp assignable ; @@ -197,7 +215,7 @@ int main() { int a; while ((a = yyparse()) != EOF){ printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar); - if(yytext[0] == '?'){ + if(yytext[0] == '!'){ print_symbol_table(getAncestor(st),stdout); break; } diff --git a/parser b/parser index cb59b833bc9d5254ff75b3e6fa3d5e61bcbefe06..02e2648389b3dc49b093d9cc710c25095f792e19 100755 GIT binary patch delta 8853 zcmZ`<34B!5)qii2mjx0g6EaLD+e{KNla-K_Oh`xq3`|5IKmq~TWD{hOB@wXFF@_++ z14S>jP^rtOepW?Vn-;+$1O&o1EG;UV3bwTqf=XpEVB~%O^X|)LzrNq^-2b^}yXUU& z&P%rL*KOUe`$LczT$LlJPZcwWnZa{nd2LQ(xtJ*${O9m$Co+%jy9melFWTN%Ket!j z?lsfze7COpP{^6o#*Kbs_2Q()%i+-h;{4a!B1Q2yyK9~Q4y8Jp@ez1VQA^Qx6s7ecSX|~7pL2^NT^4uI zOsm5sH#AXC>wRG^S$GioopasVPj1-Up?$bZ?on4p%Mo;Kvn*|1s!o1QzAQC>Z zaK$GvG44oNT7rt&LM#igrpy>c4o#v*8cOm_Qsy8Ugl6AfnAd;wBpURqEt91PXd9Z` zdRgkFa77utpB4s#h16$QPWj z%Bih9cTu-hcOjQ|x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%|Vlj|8QI2INQNGN~@?88Hw-)8= z?7aMyIGXL=WE6j5pKVIgXtLQKo9;)a?%BN4eE3fd%Q#{v^fs3A*jzEM@rlRo@)4h4 sx1LY(Dlg)#m$Q`Z#bP8|yFJOP=l|i@y*uSk From d4b943b83840b34256287a005483a93ae282e6cd Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Fri, 28 Feb 2025 12:16:21 -0500 Subject: [PATCH 13/31] added an alpha file all on one line --- tests/test_real_alpha_file_oneline.alpha | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/test_real_alpha_file_oneline.alpha diff --git a/tests/test_real_alpha_file_oneline.alpha b/tests/test_real_alpha_file_oneline.alpha new file mode 100644 index 0000000..423b6e3 --- /dev/null +++ b/tests/test_real_alpha_file_oneline.alpha @@ -0,0 +1 @@ +type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); (* see types.alpha – reserve returns a value of type address, which can be assigned to array and record variables *) w.x := 5; w.y := 7; result := bar1(w); (* pass w (a rec type value) to bar1 *) result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *) return 0; } From 32e123beb715cab5f03c2773c4edba2f6e17796a Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Fri, 28 Feb 2025 12:21:36 -0500 Subject: [PATCH 14/31] forgot to remove the comments --- tests/test_real_alpha_file_oneline.alpha | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_real_alpha_file_oneline.alpha b/tests/test_real_alpha_file_oneline.alpha index 423b6e3..01f115e 100644 --- a/tests/test_real_alpha_file_oneline.alpha +++ b/tests/test_real_alpha_file_oneline.alpha @@ -1 +1 @@ -type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); (* see types.alpha – reserve returns a value of type address, which can be assigned to array and record variables *) w.x := 5; w.y := 7; result := bar1(w); (* pass w (a rec type value) to bar1 *) result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *) return 0; } +type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } From 2808a75dc9be9c397cd48f3c113566ef24b6729f Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 28 Feb 2025 14:03:53 -0500 Subject: [PATCH 15/31] edited some grammar rules. Still running into syntax errors --- .Makefile.swp | Bin 0 -> 12288 bytes Makefile | 7 + grammar.y | 42 +- lex.yy.c | 2100 ------------------------------------------------- parser | Bin 40856 -> 0 bytes 5 files changed, 38 insertions(+), 2111 deletions(-) create mode 100644 .Makefile.swp delete mode 100644 lex.yy.c delete mode 100755 parser diff --git a/.Makefile.swp b/.Makefile.swp new file mode 100644 index 0000000000000000000000000000000000000000..731dce035acfa5772ee102a56adbe2804c3e8404 GIT binary patch literal 12288 zcmeI2y>HV%7>5s72$T;&2PBpQiqryjN-0uhsY7W?RjEvTRst2rxqMK^w$2wIs`ywK zkeFD2e}KZk!hi$=A3H2;?0{7M02UbdonxnU;?M|*0rW1P*w1(6@Z-{^FZcJdpfEbBo7a0eLYCIc(eazQ!@T3#VVHM9F*iV<0Uy9y@B%D@$KVdQ z1TKO}V1Oea2R4J1?Kls-2T#Fma0{FV2f+aNv5m1e;5B##9)XA81}K9PxC|`N2fp?p zA3Ov#Fai3(x2Q6Bcfk_yz&w}&k&l0H zJ!#5hfDDiUGC&5%z~3{FlQnLX_#rb?EdIMJ?OM&2rm_oWC9Ba%8V{MuUrY{4uDHIM zKQK6bVR|Tu=}@C#t~t?Xjw@`>!hbntzM0I8P;oP_M5w~(ePK~FuKBVUnzkEM?6yn; zW2e*oK*;Dx%g%hA+tIxgw!08@y)cq}N@_NLo~|GI>|ubgS_@n;S5+v(%_zE~;N}Ul zo;m|(Jq+OEiBuWXJ*Su4-^)yy>Ap@KQ!WcnS9iu=6kdw&%T8+2PXiLl-C7qM*+hNV9>051q^kD^MW)#qx zhv6huIPq+Ck8!vatMGUW)t#N3o4ycPXjMHhsGC@F9MxNOZ1=R1bw|~uFcD%bS(Gdv z%@L!?&QECHsZ~kVNALSi*6LtQ0$YYcuBuL*!{X?gp;K{=uca84TjRWWQLy-mvBnve bTDLbhdK9V;P)}!pT8s{ASFG7t*>Tt}gkE>x literal 0 HcmV?d00001 diff --git a/Makefile b/Makefile index 05aff7a..8f3879c 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,13 @@ FLEX := flex LEX := lexicalStructure.lex EXE := alpha CFLAGS := +YACC := bison + +parser : lex.yy.c grammar.tab.c + $(CC) -o parser lex.yy.c grammar.tab.c + +grammar.tab.c: grammar.y + $(YACC) -d grammar.y compiler: lex.yy.c runner.o runner diff --git a/grammar.y b/grammar.y index ca54a25..e10b99f 100644 --- a/grammar.y +++ b/grammar.y @@ -12,6 +12,9 @@ SymbolTable * st; char* cur_value; char* cur_type; + int token_tracker; + extern int line_number; + extern int column_number; %} %union { @@ -100,6 +103,8 @@ prototype: definition: TYPE ID COLON dblock | TYPE ID COLON constant ARROW ID + | TYPE ID COLON types ARROW ID + | FUNCTION ID COLON ID | TYPE ID COLON ID ARROW ID | ID parameter ASSIGN sblock ; @@ -115,20 +120,22 @@ idlist: ; sblock: - L_BRACE {st = CreateScope(st,1,1);} statement_list {st = getParent(st);} R_BRACE - | L_BRACE {st = CreateScope(st,1,1);} dblock statement_list {st = getParent(st);} R_BRACE + L_BRACE /*{st = CreateScope(st,1,1);}*/ statement_list /*{st = getParent(st);}*/ R_BRACE + | L_BRACE /*{st = CreateScope(st,1,1);}*/ dblock statement_list /*{st = getParent(st);}*/ R_BRACE ; dblock: L_BRACKET declaration_list R_BRACKET; declaration_list: - declaration {CreateEntry(st,cur_type,cur_value);} SEMI_COLON declaration_list - | declaration {CreateEntry(st,cur_type,cur_value);} + declaration /*{CreateEntry(st,cur_type,cur_value);}*/ SEMI_COLON declaration_list + | declaration //{CreateEntry(st,cur_type,cur_value);} ; declaration: - ID COLON ID {cur_value = strdup($1);cur_type = strdup($3);}; + ID COLON ID //{cur_value = strdup($1);cur_type = strdup($3);} + | types COLON ID + ; statement_list: compound_statement statement_list @@ -201,22 +208,35 @@ constant: | C_TRUE | C_FALSE ; + +types: + T_STRING + | T_INTEGER + | T_ADDRESS + | T_CHARACTER + | T_BOOLEAN + ; // %% void yyerror(const char *err) { - fprintf(stderr, "Error: %s\n", err); + fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); } int main() { - cur_value = NULL; - cur_type = NULL; + //cur_value = NULL; + //cur_type = NULL; + + token_tracker = 1; st=CreateScope(NULL,1,1); int a; while ((a = yyparse()) != EOF){ - printf("%d = a: yytext = %s: yychar = %d\n", a, yytext, yychar); - if(yytext[0] == '!'){ - print_symbol_table(getAncestor(st),stdout); + token_tracker++; + //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); + if(yytext[0] == '\n'){ + FILE* f = fdopen(1,"w"); + print_symbol_table(getAncestor(st),f); + fclose(f); break; } } diff --git a/lex.yy.c b/lex.yy.c deleted file mode 100644 index dca4c08..0000000 --- a/lex.yy.c +++ /dev/null @@ -1,2100 +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 */ - -#define yywrap() (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP -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 50 -#define YY_END_OF_BUFFER 51 -/* 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_accept[147] = - { 0, - 0, 0, 51, 49, 47, 46, 48, 24, 49, 20, - 25, 49, 36, 37, 18, 16, 30, 17, 27, 19, - 32, 29, 28, 21, 22, 45, 45, 38, 39, 45, - 45, 45, 45, 45, 45, 45, 45, 45, 40, 26, - 41, 0, 34, 0, 0, 0, 0, 31, 32, 23, - 45, 45, 45, 13, 45, 45, 45, 45, 45, 6, - 45, 45, 45, 45, 45, 45, 45, 33, 0, 0, - 0, 45, 45, 45, 45, 45, 45, 45, 45, 45, - 45, 45, 45, 45, 45, 45, 45, 0, 0, 0, - 35, 0, 45, 45, 45, 8, 45, 45, 45, 45, - - 44, 45, 45, 45, 7, 42, 9, 45, 0, 35, - 0, 0, 45, 45, 45, 45, 43, 45, 45, 45, - 45, 45, 5, 0, 45, 45, 45, 45, 45, 45, - 45, 45, 11, 3, 2, 45, 45, 45, 1, 14, - 15, 45, 12, 10, 4, 0 - } ; - -static const YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 1, 1, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, - 22, 23, 1, 1, 24, 25, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 26, 27, 28, 1, 24, 1, 29, 24, 30, 31, - - 32, 33, 34, 35, 36, 24, 24, 37, 24, 38, - 39, 40, 24, 41, 42, 43, 44, 45, 46, 47, - 48, 24, 49, 50, 51, 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[52] = - { 0, - 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, - 1, 1, 1, 1, 1, 1, 1, 4, 1, 1, - 1, 1, 1, 4, 4, 1, 1, 1, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, - 1 - } ; - -static const flex_int16_t yy_base[156] = - { 0, - 0, 0, 203, 204, 204, 204, 204, 204, 46, 204, - 204, 175, 189, 204, 204, 204, 204, 177, 204, 204, - 181, 176, 204, 204, 204, 0, 158, 204, 204, 22, - 161, 18, 25, 23, 151, 162, 22, 158, 204, 204, - 204, 52, 204, 53, 183, 51, 55, 204, 173, 204, - 0, 151, 158, 0, 159, 145, 143, 148, 146, 0, - 140, 145, 34, 149, 136, 139, 142, 204, 63, 165, - 69, 139, 134, 133, 141, 140, 129, 140, 137, 131, - 135, 134, 121, 126, 131, 130, 124, 71, 73, 75, - 204, 81, 128, 127, 129, 0, 116, 124, 112, 120, - - 0, 124, 111, 110, 0, 0, 0, 118, 86, 204, - 88, 90, 120, 106, 117, 108, 0, 109, 112, 101, - 97, 103, 0, 92, 102, 97, 95, 108, 72, 69, - 75, 63, 0, 0, 0, 58, 51, 34, 0, 0, - 0, 27, 0, 0, 0, 204, 104, 108, 58, 112, - 116, 120, 124, 128, 132 - } ; - -static const flex_int16_t yy_def[156] = - { 0, - 146, 1, 146, 146, 146, 146, 146, 146, 147, 146, - 146, 148, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 149, 149, 146, 146, 149, - 149, 149, 149, 149, 149, 149, 149, 149, 146, 146, - 146, 147, 146, 146, 146, 146, 150, 146, 146, 146, - 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 146, 150, 151, - 152, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 150, 153, 154, - 146, 152, 149, 149, 149, 149, 149, 149, 149, 149, - - 149, 149, 149, 149, 149, 149, 149, 149, 155, 146, - 153, 154, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 155, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, - 149, 149, 149, 149, 149, 0, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static const flex_int16_t yy_nxt[256] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 4, 26, 27, 28, 4, 29, 30, 31, - 26, 32, 33, 26, 26, 34, 26, 35, 26, 26, - 36, 26, 37, 26, 26, 38, 26, 26, 39, 40, - 41, 43, 53, 58, 56, 60, 64, 43, 42, 45, - 61, 51, 65, 54, 57, 70, 71, 145, 59, 66, - 81, 144, 44, 88, 71, 82, 83, 45, 44, 91, - 92, 88, 71, 110, 111, 88, 71, 143, 45, 142, - 42, 110, 92, 45, 141, 42, 70, 89, 146, 111, - - 88, 71, 70, 89, 42, 42, 140, 42, 45, 139, - 138, 45, 69, 69, 69, 69, 70, 70, 70, 70, - 90, 90, 90, 90, 109, 109, 109, 109, 112, 112, - 112, 112, 124, 124, 124, 124, 137, 136, 135, 134, - 133, 132, 131, 130, 129, 128, 127, 126, 125, 123, - 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, - 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, - 98, 97, 96, 95, 94, 93, 89, 87, 86, 85, - 84, 80, 79, 78, 77, 76, 75, 74, 73, 72, - 49, 68, 67, 63, 62, 55, 52, 50, 49, 48, - - 47, 46, 146, 3, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static const flex_int16_t yy_chk[256] = - { 0, - 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, 9, 30, 33, 32, 34, 37, 42, 44, 46, - 34, 149, 37, 30, 32, 47, 47, 142, 33, 37, - 63, 138, 9, 69, 69, 63, 63, 46, 42, 71, - 71, 88, 88, 89, 89, 90, 90, 137, 46, 136, - 44, 92, 92, 46, 132, 44, 109, 109, 111, 111, - - 112, 112, 124, 124, 147, 147, 131, 147, 148, 130, - 129, 148, 150, 150, 150, 150, 151, 151, 151, 151, - 152, 152, 152, 152, 153, 153, 153, 153, 154, 154, - 154, 154, 155, 155, 155, 155, 128, 127, 126, 125, - 122, 121, 120, 119, 118, 116, 115, 114, 113, 108, - 104, 103, 102, 100, 99, 98, 97, 95, 94, 93, - 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, - 77, 76, 75, 74, 73, 72, 70, 67, 66, 65, - 64, 62, 61, 59, 58, 57, 56, 55, 53, 52, - 49, 45, 38, 36, 35, 31, 27, 22, 21, 18, - - 13, 12, 3, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146, 146, 146, 146, 146, 146, - 146, 146, 146, 146, 146 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "lexicalStructure.lex" -/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */ -/* so we placed the citation here. */ -/* definitions */ -#line 8 "lexicalStructure.lex" - #include - //#include "typedefs.h" - #include "grammar.tab.h" - int line_number = 1, column_number = 1; - #ifndef DEBUG - #define DEBUG 0 - #endif -#line 561 "lex.yy.c" -#line 23 "lexicalStructure.lex" - /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ - /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ -#line 565 "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 - - 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 27 "lexicalStructure.lex" - - -#line 785 "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_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 204 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = 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 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 29 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} - YY_BREAK -case 2: -YY_RULE_SETUP -#line 30 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} - YY_BREAK -case 3: -YY_RULE_SETUP -#line 31 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} - YY_BREAK -case 4: -YY_RULE_SETUP -#line 32 "lexicalStructure.lex" -{if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} - YY_BREAK -case 5: -YY_RULE_SETUP -#line 34 "lexicalStructure.lex" -{if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} - YY_BREAK -case 6: -YY_RULE_SETUP -#line 35 "lexicalStructure.lex" -{if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} - YY_BREAK -case 7: -YY_RULE_SETUP -#line 36 "lexicalStructure.lex" -{if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} - YY_BREAK -case 8: -YY_RULE_SETUP -#line 37 "lexicalStructure.lex" -{if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} - YY_BREAK -case 9: -YY_RULE_SETUP -#line 38 "lexicalStructure.lex" -{if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} - YY_BREAK -case 10: -YY_RULE_SETUP -#line 39 "lexicalStructure.lex" -{if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} - YY_BREAK -case 11: -YY_RULE_SETUP -#line 40 "lexicalStructure.lex" -{if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} - YY_BREAK -case 12: -YY_RULE_SETUP -#line 41 "lexicalStructure.lex" -{if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 42 "lexicalStructure.lex" -{if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} - YY_BREAK -case 14: -YY_RULE_SETUP -#line 44 "lexicalStructure.lex" -{if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} - YY_BREAK -case 15: -YY_RULE_SETUP -#line 45 "lexicalStructure.lex" -{if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} - YY_BREAK -case 16: -YY_RULE_SETUP -#line 47 "lexicalStructure.lex" -{if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} - YY_BREAK -case 17: -YY_RULE_SETUP -#line 48 "lexicalStructure.lex" -{if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} - YY_BREAK -case 18: -YY_RULE_SETUP -#line 49 "lexicalStructure.lex" -{if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} - YY_BREAK -case 19: -YY_RULE_SETUP -#line 50 "lexicalStructure.lex" -{if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} - YY_BREAK -case 20: -YY_RULE_SETUP -#line 51 "lexicalStructure.lex" -{if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} - YY_BREAK -case 21: -YY_RULE_SETUP -#line 52 "lexicalStructure.lex" -{if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} - YY_BREAK -case 22: -YY_RULE_SETUP -#line 53 "lexicalStructure.lex" -{if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} - YY_BREAK -case 23: -YY_RULE_SETUP -#line 54 "lexicalStructure.lex" -{if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} - YY_BREAK -case 24: -YY_RULE_SETUP -#line 55 "lexicalStructure.lex" -{if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} - YY_BREAK -case 25: -YY_RULE_SETUP -#line 56 "lexicalStructure.lex" -{if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} - YY_BREAK -case 26: -YY_RULE_SETUP -#line 57 "lexicalStructure.lex" -{if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} - YY_BREAK -case 27: -YY_RULE_SETUP -#line 58 "lexicalStructure.lex" -{if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} - YY_BREAK -case 28: -YY_RULE_SETUP -#line 60 "lexicalStructure.lex" -{if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} - YY_BREAK -case 29: -YY_RULE_SETUP -#line 61 "lexicalStructure.lex" -{if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} - YY_BREAK -case 30: -YY_RULE_SETUP -#line 62 "lexicalStructure.lex" -{if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} - YY_BREAK -case 31: -YY_RULE_SETUP -#line 63 "lexicalStructure.lex" -{if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} - YY_BREAK -case 32: -YY_RULE_SETUP -#line 65 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} - YY_BREAK -case 33: -YY_RULE_SETUP -#line 66 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} - YY_BREAK -case 34: -YY_RULE_SETUP -#line 67 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} - YY_BREAK -case 35: -/* rule 35 can match eol */ -YY_RULE_SETUP -#line 68 "lexicalStructure.lex" -{if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} - YY_BREAK -case 36: -YY_RULE_SETUP -#line 70 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} - YY_BREAK -case 37: -YY_RULE_SETUP -#line 71 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} - YY_BREAK -case 38: -YY_RULE_SETUP -#line 73 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} - YY_BREAK -case 39: -YY_RULE_SETUP -#line 74 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} - YY_BREAK -case 40: -YY_RULE_SETUP -#line 76 "lexicalStructure.lex" -{if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} - YY_BREAK -case 41: -YY_RULE_SETUP -#line 77 "lexicalStructure.lex" -{if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} - YY_BREAK -case 42: -YY_RULE_SETUP -#line 79 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} - YY_BREAK -case 43: -YY_RULE_SETUP -#line 80 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} - YY_BREAK -case 44: -YY_RULE_SETUP -#line 81 "lexicalStructure.lex" -{if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} - YY_BREAK -case 45: -YY_RULE_SETUP -#line 83 "lexicalStructure.lex" -{if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} - YY_BREAK -case 46: -/* rule 46 can match eol */ -YY_RULE_SETUP -#line 85 "lexicalStructure.lex" -{line_number++; column_number = 1;} - YY_BREAK -case 47: -YY_RULE_SETUP -#line 86 "lexicalStructure.lex" -{column_number++;} - YY_BREAK -case 48: -YY_RULE_SETUP -#line 87 "lexicalStructure.lex" -{column_number++;} - YY_BREAK -case 49: -YY_RULE_SETUP -#line 88 "lexicalStructure.lex" -{column_number++; return 1999;} - YY_BREAK -case 50: -YY_RULE_SETUP -#line 90 "lexicalStructure.lex" -ECHO; - YY_BREAK -#line 1094 "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. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - 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); - - 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); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - 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; - char *yy_cp = (yy_c_buf_p); - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = 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 >= 147 ) - yy_c = yy_meta[yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 146); - - 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 = file ? (isatty( fileno(file) ) > 0) : 0; - - 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; - -/* 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; - - /* 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 90 "lexicalStructure.lex" - - diff --git a/parser b/parser deleted file mode 100755 index 02e2648389b3dc49b093d9cc710c25095f792e19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40856 zcmeHwdwf*Ywf~+Zhaj&c$Ut}xDB+oq@G{{U9s`2{hDQ_?9fo8=qDdxBW+bshz#*3L z5Jg3$)mClmN3T^c_tsi!Q3HxWB@%9}MWtHoG#=P zRD7en0>Nh%SUghD6*TLSZya@k?`VjJXQf|`%JwTgB9mUW)XSE73U)|GD5(5NKA|gD z+OxuJ@F*#0)hm^HR=7l{F$Jj%N^3s~6#w6pS0MG0iiI63{7|+}K~>&r=#gLk-jpf@ z*U0j^>xWj^4+_fS+0^o~O|xc9EicY2FRKjJWY*-)%A7SLtJ;?}ja#OAIdD--En8K{ zV5X61syh?5i@dT&yg`yr@_B3i*!i=!Sk7=xJ;ibL;_vq~;ZvXJa`f{-Xj}lFzot zha^4ULT7GwQH{r4Qda3HFT2^xO3KQ;l|EMCDKGaGfr(*Sv4y2mD19 zRjj1SUsf3?VVk{yB39w8sP+cHD)t2fti*0IQ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;k^=GqY{gT>H7tY*Ag+~y8-ogyEj*0nDZz^Tnl%}8locA zK6k07vKTX05x&XnM{ijSQ&Z7B{HxDJRk1+GL3A#^9Cp$3?jU_@1d}Abs$tA9awzjT zss!H#sr1EJCU;QG`Ms6Y)MENRw)!3htKeR>$}g-e!f5jO$(04DYb7}e->i-=67xRQ zh1VH^YoKy@iBS|nmm(w1v=|R-i+mK4?oHKv#=)3{HXj=z&}eLOyEQxjv8qtLOUh$y zCi)8WJxSfKZ|5PJv4H54wt;)Kf4?3aaDVp-UiL_3>RcAL0X$jj?*Wyby(xY5d`?0B-z|YpbtK;@ zeRMxQ8)$>LLTV;bupLDGLdjvERQTC1d zkW>(n)bkOM6LnQM!3S}f^&L`ALH?a6lY(R$#XM%wuaY->3MzSJLgf|QZ_(c_^%cyQ z?e9+i*A{(sAFtr9Y^5onDpyfowCJnn*$Vbof)ZNC&k?Dw;zymcD3~bEag`Z|LL_Vk zq$VnTbuO;phnDtR%YWCRAHi}#Nx`i&@Jva?k0Q}I#Q7{rGd}l8Dk*&-WeMKtyWgpRo_6uOK~# zG3y)Wj@yNfb^cd+%3?n#6U``pkJQ^P;86jLPltgCBu$oY2~##=yWq>mLWUOAm692% z*byA@>Dn&fF6vyQk+^6sRP|T$&jp~Vx&t**%N+tetsE~os$3;V!?i2@gZBxEVHO2T Gmi-^SJbnZK From 2695334db91d5df680d6128aa91821b783bcfc8c Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 28 Feb 2025 15:42:43 -0500 Subject: [PATCH 16/31] added print statements to gramamr rules to check for debugging --- grammar.y | 65 ++++++++++++++++++++++++++++++++++++++++-------------- parser | Bin 0 -> 40984 bytes 2 files changed, 49 insertions(+), 16 deletions(-) create mode 100755 parser diff --git a/grammar.y b/grammar.y index e10b99f..bf8e417 100644 --- a/grammar.y +++ b/grammar.y @@ -39,7 +39,7 @@ %left ASSIGN %token ID 101 -%token T_INTEGER +%token T_INTEGER 201 %token T_ADDRESS 202 %token T_BOOLEAN 203 %token T_CHARACTER 204 @@ -120,20 +120,51 @@ idlist: ; sblock: - L_BRACE /*{st = CreateScope(st,1,1);}*/ statement_list /*{st = getParent(st);}*/ R_BRACE - | L_BRACE /*{st = CreateScope(st,1,1);}*/ dblock statement_list /*{st = getParent(st);}*/ R_BRACE + L_BRACE {st = CreateScope(st,1,1);} statement_list {st = getParent(st);} R_BRACE + | L_BRACE {st = CreateScope(st,1,1);} dblock statement_list {st = getParent(st);} R_BRACE ; dblock: L_BRACKET declaration_list R_BRACKET; declaration_list: - declaration /*{CreateEntry(st,cur_type,cur_value);}*/ SEMI_COLON declaration_list - | declaration //{CreateEntry(st,cur_type,cur_value);} + declaration + {printf( + "declaration list a rule encountered"); + //CreateEntry(st,cur_type,cur_value); + } + SEMI_COLON declaration_list + | declaration + {printf( + "declaration rule b encountered"); + //CreateEntry(st,cur_type,cur_value); + } ; declaration: - ID COLON ID //{cur_value = strdup($1);cur_type = strdup($3);} + ID COLON ID { + printf("declaration rule encountered"); +// if(cur_value != NULL){ +// char* delete1 = cur_value; + printf("delete1 var assigned to cur_value"); +// free(delete1); + printf("delete1 var freed"); +// } +// if(cur_type != NULL){ +// char* delete2 = cur_type; +// free(delete2);} +// int len = strlen($1); + printf("length determined"); +// cur_value = malloc(len + 1); + printf("space allocated"); +// strcpy(cur_value, $1); + printf("string copied over"); + +// len = strlen($3); +// cur_type = malloc(len + 1); +// strcpy(cur_type, $3); +// printf("value var is %s type var is %s\n",cur_value,cur_type); + } | types COLON ID ; @@ -220,25 +251,27 @@ types: %% void yyerror(const char *err) { - fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); + // fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); } int main() { - //cur_value = NULL; - //cur_type = NULL; + char *str = strdup("taco"); + cur_value = NULL; + cur_type = NULL; token_tracker = 1; st=CreateScope(NULL,1,1); - int a; - while ((a = yyparse()) != EOF){ - token_tracker++; + //int a; + yyparse(); + //while ((a = yyparse() != EOF){ + // token_tracker++; //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); - if(yytext[0] == '\n'){ + //if(yytext[0] == '\n'){ FILE* f = fdopen(1,"w"); print_symbol_table(getAncestor(st),f); fclose(f); - break; - } - } + // break; + //} + //} return 0; } diff --git a/parser b/parser new file mode 100755 index 0000000000000000000000000000000000000000..414407a4dbe4de88595d639d6eff1860f4fbd916 GIT binary patch literal 40984 zcmeHwdwf*Y_3zH(KtLb~WFR1q5qU#G0s#^b2#o35h0|IGK?|je;S{ zc#K3u#agZU(`u`>{*+qU`bZEBzG`UswY0Urri$&vpiL2LRAlaV?Z=rjhlJXDf4BGk zk(1Avwf1`Lz1Lp*bzZsIv3f;(TpUwJ0$ap*YM7wpOUA~1N`kR`mdgg?cN`nb`hlE? zGhec;@L0THD3~PW5&%grosb^jXhCKQsuB_;z21(t^8`mhmLk%mrx7aCR`}9vA*Z0? z8~GIoKC{3>;{;tnvmW^-rB3iu8e`!gS?^;KDm`)+>Di^8UFs>=B^{xl@+bL(&Rl8F z3bVkYLqV%vsnoN=p6U*;@snaX9yNinr@Z4rZ+ zW}>O)jNdNO${z93B%kD`ZcE+#!4=QEnb>~wkJnC0)29r$yM$z@+@wP?bdWt+L?eAZ zFp}Z^hk4uRs+88du*pxAMj6UN1WkpGmJ03;lb&(3kf@zp5Ad!CvUOz0fb|g--pYC;!arg+8MfKkVp5o`%() z>{A@{L?6)$y}B2Ac`x)AdZGWK7y5!;>gDZ4esM4Kb)cuRQOw>11cw@jV4jWVl-Qpe zkRy35P1_p*|*a&M)NRk+K`eI78;tv#;lfZHE%Rk+J4 zS#`kgsiK%g zdxdcb!l0+z>-Ky7epZ4XpP$qz1!JD7TC(CUMlnFD^tn(Zcc9Ey$-FgX$YGnmEZ_wb z#q(U_@|0fVDsh*Uv$AS;AW+MwFOCK%>~~C^{>14s)$4T;oCs zyj#nv173gOnq}p_N^hZiOF8A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h4B}}t5_yp zjP+)2tqf*X`OzHyK&^?iC5WiWC@YqvB}-Rj&>Dk_m%6JSo+~woH){PU4;$>)%8O`6|xE^cp*+K z1r7aNsjpxb37HPH9#o{cK+O83QeVLdN>DO&tTS9_c;`_D?tgZ`WryUM|SD* zC_mKwKn2xxb8JueVJ*KKRJs?a^ws@B14;&!k^HRm(}B}bhLftS^ws@G1=amVlBI)e zn2&3bpnG{rU){e`aFG;NOTS+`9#?__AeL)3 z^wo7u1qUlZ39bF-HL0)SM_tcR@EUdDMe5rnRNx&TR7It)uFETU+){sQ{(rFO7nBOi z3I-@}O^1pfMWX8=LvYGr$GFd!QYR#=@+z(1-yufVo|V3O-XQ%O>VFMgie06z?pN5Q zewVDjs)ou}wIf|`ArYmoo;OIj8AKdi0vNwaUqQN0X4Yp-Qgpk3*70BIDT9NcOf;3h zy3R3L>K|5u651{4RGEL4g|77FWk7>VWu?OmRqP0k_;qd Date: Fri, 28 Feb 2025 17:42:47 -0500 Subject: [PATCH 17/31] Updated header --- symbol_table.c | 261 +++++++++++++++++++++++-------------------------- symbol_table.h | 55 ++++++----- 2 files changed, 157 insertions(+), 159 deletions(-) diff --git a/symbol_table.c b/symbol_table.c index 1a2e375..48a7a42 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -1,156 +1,143 @@ +#include "symbol_table.h" + #include #include #include -#include "symbol_table.h" - -SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){ - SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable)); - table->Line_Number = Line; - table->Column_Number = Column; - table->Parent_Scope = ParentScope; - table->Children_Scope = NULL; - table->entries = NULL; - if(ParentScope != NULL){ - if(ParentScope->Children_Scope == NULL){ - ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable)); - newEntry->next = NULL; - //newEntry->prev = NULL; - newEntry->table = table; - ParentScope->Children_Scope = newEntry; - } else{ - ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable)); - //newEntry->prev = NULL; - newEntry->table= table; - ListOfTable* oldEntry = ParentScope->Children_Scope; - ParentScope->Children_Scope = newEntry; - newEntry->next = oldEntry; - } - } - return table; - } - - -TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id){ - TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode)); - newEntry->theType = typeOf; - newEntry->theName = id; - if(table->entries == NULL){ - table->entries = newEntry; - return newEntry; - } else{ - TableNode* oldEntry = table->entries; - table->entries = newEntry; - newEntry->next = oldEntry; - return newEntry; - } -} -TableNode * table_lookup(SymbolTable * table, char * x){ - TableNode * entrie = table->entries; - for(; entrie != NULL; entrie = entrie->next){ - if (!strcmp(entrie->theName, x)){ - return entrie; - } - } - return NULL; -} -TableNode * look_up(SymbolTable * table, char * x){ - if(table == NULL){ - return NULL; - } - TableNode * ret = table_lookup(table, x); - if (ret != NULL){ - return ret; - } - return look_up(table->Parent_Scope, x); +SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column) { + SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable)); + table->Line_Number = Line; + table->Column_Number = Column; + table->Parent_Scope = ParentScope; + table->Children_Scope = NULL; + table->entries = NULL; + if (ParentScope != NULL) { + if (ParentScope->Children_Scope == NULL) { + ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable)); + newEntry->next = NULL; + // newEntry->prev = NULL; + newEntry->table = table; + ParentScope->Children_Scope = newEntry; + } else { + ListOfTable* newEntry = (ListOfTable*)malloc(sizeof(ListOfTable)); + // newEntry->prev = NULL; + newEntry->table = table; + ListOfTable* oldEntry = ParentScope->Children_Scope; + ParentScope->Children_Scope = newEntry; + newEntry->next = oldEntry; + } + } + return table; } -SymbolTable * getAncestor(SymbolTable * table){ - if(table->Parent_Scope == NULL){ - //if table has no parent, return itself - return table; - } else { - //call function recursively to grab ancestor - return getAncestor(table->Parent_Scope); - } +TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id) { + TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode)); + newEntry->theType = typeOf; + newEntry->theName = id; + if (table->entries == NULL) { + table->entries = newEntry; + return newEntry; + } else { + TableNode* oldEntry = table->entries; + table->entries = newEntry; + newEntry->next = oldEntry; + return newEntry; + } } -void print_symbol_table(SymbolTable *table, FILE *file_ptr){ - if(table->Parent_Scope == NULL){ - fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); - } - TableNode * entrie = table->entries; - fprintf(file_ptr, "-----------------:--------:--------:----------------------:-----------------------------\n"); - int parant_scope = 0; - int current_scope = 0; - if(table->Parent_Scope != NULL){ - parant_scope = table->Parent_Scope->Line_Number*1000 + table->Parent_Scope->Column_Number; - current_scope = table->Line_Number*1000 + table->Column_Number; - } else { - current_scope = 1001; - } - - for(; entrie != NULL; entrie = entrie->next){ - if (parant_scope == 0){ - fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n", - entrie->theName, current_scope, - entrie->theType, "Extra annotation"); - } else { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", - entrie->theName, current_scope, parant_scope, - entrie->theType, "Extra annotation"); - } - } - if (table->Children_Scope != NULL){ - ListOfTable* node = table->Children_Scope; - for(; node != NULL; node = node->next){ - print_symbol_table(node->table, file_ptr); - } - } - if (table->Parent_Scope == NULL) { - fprintf(file_ptr, "-----------------:--------:--------:----------------------:-----------------------------\n"); - } +TableNode* table_lookup(SymbolTable* table, char* x) { + TableNode* entrie = table->entries; + for (; entrie != NULL; entrie = entrie->next) { + if (!strcmp(entrie->theName, x)) { + return entrie; + } + } + return NULL; +} +TableNode* look_up(SymbolTable* table, char* x) { + if (table == NULL) { + return NULL; + } + TableNode* ret = table_lookup(table, x); + if (ret != NULL) { + return ret; + } + return look_up(table->Parent_Scope, x); } -SymbolTable * getParent(SymbolTable* st){ - return st->Parent_Scope; - } +void print_symbol_table(SymbolTable* table, FILE* file_ptr) { + if (table->Parent_Scope == NULL) { + fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", + "PARENT", "TYPE", "Extra annotation"); + } + TableNode* entrie = table->entries; + fprintf(file_ptr, + "-----------------:--------:--------:----------------------:---------" + "--------------------\n"); + int parant_scope = 0; + int current_scope = 0; + if (table->Parent_Scope != NULL) { + parant_scope = table->Parent_Scope->Line_Number * 1000 + + table->Parent_Scope->Column_Number; + current_scope = table->Line_Number * 1000 + table->Column_Number; + } else { + current_scope = 1001; + } -ListOfTable * getChildren(SymbolTable* st){ - return st->Children_Scope; - } -SymbolTable * getFirstChild(ListOfTable * lt){ - return lt->table; - } -ListOfTable * getRestOfChildren(ListOfTable * lt){ - return lt->next; - } -TableNode * getFirstEntry(SymbolTable * st){ - return st->entries; - } -TableNode * getNextEntry(TableNode * tn){ - return tn->next; - } -char * getType(TableNode * tn){ - return tn->theType; - } -char * getName(TableNode * tn){ - return tn->theName; - } -int getLine(SymbolTable * st){ - return st->Line_Number; - } -int getColumn(SymbolTable *st){ - return st->Column_Number; - } -//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation + for (; entrie != NULL; entrie = entrie->next) { + if (parant_scope == 0) { + fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n", + entrie->theName, current_scope, entrie->theType, + "Extra annotation"); + } else { + fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", entrie->theName, + current_scope, parant_scope, entrie->theType, "Extra annotation"); + } + } + if (table->Children_Scope != NULL) { + ListOfTable* node = table->Children_Scope; + for (; node != NULL; node = node->next) { + print_symbol_table(node->table, file_ptr); + } + } + if (table->Parent_Scope == NULL) { + fprintf(file_ptr, + "-----------------:--------:--------:----------------------:-------" + "----------------------\n"); + } +} + +SymbolTable* getAncestor(SymbolTable* table) { + if (table->Parent_Scope == NULL) { + // if table has no parent, return itself + return table; + } else { + // call function recursively to grab ancestor + return getAncestor(table->Parent_Scope); + } +} + +SymbolTable* getParent(SymbolTable* st) { return st->Parent_Scope; } + +ListOfTable* getChildren(SymbolTable* st) { return st->Children_Scope; } +SymbolTable* getFirstChild(ListOfTable* lt) { return lt->table; } +ListOfTable* getRestOfChildren(ListOfTable* lt) { return lt->next; } +TableNode* getFirstEntry(SymbolTable* st) { return st->entries; } +TableNode* getNextEntry(TableNode* tn) { return tn->next; } +char* getType(TableNode* tn) { return tn->theType; } +char* getName(TableNode* tn) { return tn->theName; } +int getLine(SymbolTable* st) { return st->Line_Number; } +int getColumn(SymbolTable* st) { return st->Column_Number; } +// uncomment the below main function along with the headers above for a simple +// standalone test of table and entry creation /* int main(){ char* String = "STRING"; char* X = "X"; SymbolTable* Second = CreateScope(NULL, 2,2); - printf("Line number is %d, Column number of scope is %d\n",Second->Line_Number,Second->Column_Number); - TableNode* First_Entry = CreateEntry(Second,String,X); + printf("Line number is %d, Column number of scope is +%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry = +CreateEntry(Second,String,X); printf("The type of the first entry is %s\n",First_Entry->theType); return 0; diff --git a/symbol_table.h b/symbol_table.h index 0d30f59..0ef5c8a 100644 --- a/symbol_table.h +++ b/symbol_table.h @@ -3,30 +3,41 @@ #include #include -typedef struct ListOfTable{ - struct SymbolTable* table; - //struct ListOfTable* prev; - struct ListOfTable* next; +typedef struct ListOfTable { + struct SymbolTable* table; + // struct ListOfTable* prev; + struct ListOfTable* next; -}ListOfTable; +} ListOfTable; -typedef struct TableNode{ - char* theType; - char* theName; - struct TableNode* next; -}TableNode; +typedef struct TableNode { + char* theType; + char* theName; + struct TableNode* next; +} TableNode; -typedef struct SymbolTable{ - TableNode* entries; - struct SymbolTable* Parent_Scope; - struct ListOfTable* Children_Scope; - int Line_Number; - int Column_Number; -}SymbolTable; +typedef struct SymbolTable { + TableNode* entries; + struct SymbolTable* Parent_Scope; + struct ListOfTable* Children_Scope; + int Line_Number; + int Column_Number; +} SymbolTable; - -TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id); SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column); -TableNode * table_lookup(SymbolTable * table, char * x); -TableNode * look_up(SymbolTable * table, char * x); -void print_symbol_table(SymbolTable *table, FILE *file_ptr); +TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id); +TableNode* table_lookup(SymbolTable* table, char* x); +TableNode* look_up(SymbolTable* table, char* x); +void print_symbol_table(SymbolTable* table, FILE* file_ptr); + +SymbolTable* getAncestor(SymbolTable* table); +SymbolTable* getParent(SymbolTable* st); +ListOfTable* getChildren(SymbolTable* st); +SymbolTable* getFirstChild(ListOfTable* lt); +ListOfTable* getRestOfChildren(ListOfTable* lt); +TableNode* getFirstEntry(SymbolTable* st); +TableNode* getNextEntry(TableNode* tn); +char* getType(TableNode* tn); +char* getName(TableNode* tn); +int getLine(SymbolTable* st); +int getColumn(SymbolTable* st); \ No newline at end of file From 63212a3d63e85a97ca1f78f28274337cfdaff1d4 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 28 Feb 2025 18:16:44 -0500 Subject: [PATCH 18/31] entries are working but not freeing memory so potential for leaks --- .Makefile.swp | Bin 12288 -> 0 bytes grammar.y | 28 +++++++++++++++------------- lexicalStructure.lex | 4 +++- parser | Bin 40984 -> 0 bytes 4 files changed, 18 insertions(+), 14 deletions(-) delete mode 100644 .Makefile.swp delete mode 100755 parser diff --git a/.Makefile.swp b/.Makefile.swp deleted file mode 100644 index 731dce035acfa5772ee102a56adbe2804c3e8404..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2y>HV%7>5s72$T;&2PBpQiqryjN-0uhsY7W?RjEvTRst2rxqMK^w$2wIs`ywK zkeFD2e}KZk!hi$=A3H2;?0{7M02UbdonxnU;?M|*0rW1P*w1(6@Z-{^FZcJdpfEbBo7a0eLYCIc(eazQ!@T3#VVHM9F*iV<0Uy9y@B%D@$KVdQ z1TKO}V1Oea2R4J1?Kls-2T#Fma0{FV2f+aNv5m1e;5B##9)XA81}K9PxC|`N2fp?p zA3Ov#Fai3(x2Q6Bcfk_yz&w}&k&l0H zJ!#5hfDDiUGC&5%z~3{FlQnLX_#rb?EdIMJ?OM&2rm_oWC9Ba%8V{MuUrY{4uDHIM zKQK6bVR|Tu=}@C#t~t?Xjw@`>!hbntzM0I8P;oP_M5w~(ePK~FuKBVUnzkEM?6yn; zW2e*oK*;Dx%g%hA+tIxgw!08@y)cq}N@_NLo~|GI>|ubgS_@n;S5+v(%_zE~;N}Ul zo;m|(Jq+OEiBuWXJ*Su4-^)yy>Ap@KQ!WcnS9iu=6kdw&%T8+2PXiLl-C7qM*+hNV9>051q^kD^MW)#qx zhv6huIPq+Ck8!vatMGUW)t#N3o4ycPXjMHhsGC@F9MxNOZ1=R1bw|~uFcD%bS(Gdv z%@L!?&QECHsZ~kVNALSi*6LtQ0$YYcuBuL*!{X?gp;K{=uca84TjRWWQLy-mvBnve bTDLbhdK9V;P)}!pT8s{ASFG7t*>Tt}gkE>x diff --git a/grammar.y b/grammar.y index bf8e417..2302167 100644 --- a/grammar.y +++ b/grammar.y @@ -10,8 +10,8 @@ extern char* yytext; extern int yychar; SymbolTable * st; - char* cur_value; - char* cur_type; + //char* cur_value; + //char* cur_type; int token_tracker; extern int line_number; extern int column_number; @@ -120,8 +120,8 @@ idlist: ; sblock: - L_BRACE {st = CreateScope(st,1,1);} statement_list {st = getParent(st);} R_BRACE - | L_BRACE {st = CreateScope(st,1,1);} dblock statement_list {st = getParent(st);} R_BRACE + L_BRACE {st = CreateScope(st,2,2);} statement_list {st = getParent(st);} R_BRACE + | L_BRACE {st = CreateScope(st,2,2);} dblock statement_list {st = getParent(st);} R_BRACE ; dblock: @@ -143,22 +143,24 @@ declaration_list: declaration: ID COLON ID { - printf("declaration rule encountered"); + + CreateEntry(st,strdup($1),strdup($3)); +// printf("declaration rule encountered"); // if(cur_value != NULL){ // char* delete1 = cur_value; - printf("delete1 var assigned to cur_value"); +// printf("delete1 var assigned to cur_value"); // free(delete1); - printf("delete1 var freed"); +// printf("delete1 var freed"); // } // if(cur_type != NULL){ // char* delete2 = cur_type; // free(delete2);} // int len = strlen($1); - printf("length determined"); +// printf("length determined"); // cur_value = malloc(len + 1); - printf("space allocated"); +// printf("space allocated"); // strcpy(cur_value, $1); - printf("string copied over"); +// printf("string copied over"); // len = strlen($3); // cur_type = malloc(len + 1); @@ -255,9 +257,9 @@ void yyerror(const char *err) { } int main() { - char *str = strdup("taco"); - cur_value = NULL; - cur_type = NULL; + //char *str = strdup("taco"); + //cur_value = NULL; + //cur_type = NULL; token_tracker = 1; st=CreateScope(NULL,1,1); diff --git a/lexicalStructure.lex b/lexicalStructure.lex index 3bd0332..5f1f8ec 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -12,6 +12,8 @@ #ifndef DEBUG #define DEBUG 0 #endif + + %} STARCOM [^\*]|\*+[^\)\*]+ @@ -79,7 +81,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] "false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} "null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} \n {line_number++; column_number = 1;} \t {column_number++;} diff --git a/parser b/parser deleted file mode 100755 index 414407a4dbe4de88595d639d6eff1860f4fbd916..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40984 zcmeHwdwf*Y_3zH(KtLb~WFR1q5qU#G0s#^b2#o35h0|IGK?|je;S{ zc#K3u#agZU(`u`>{*+qU`bZEBzG`UswY0Urri$&vpiL2LRAlaV?Z=rjhlJXDf4BGk zk(1Avwf1`Lz1Lp*bzZsIv3f;(TpUwJ0$ap*YM7wpOUA~1N`kR`mdgg?cN`nb`hlE? zGhec;@L0THD3~PW5&%grosb^jXhC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P0k_;qd Date: Tue, 4 Mar 2025 16:14:01 -0500 Subject: [PATCH 19/31] Fixed formatting in lex; Updated Makefile t#30 --- .gitignore | 1 - Makefile | 25 ++-- src/grammar.y | 2 +- src/lexicalStructure.lex | 123 ++++++++--------- src/runner.c | 290 ++++++++++++++++++++------------------- src/runner.h | 34 +++-- 6 files changed, 240 insertions(+), 235 deletions(-) diff --git a/.gitignore b/.gitignore index 9110e5c..e6bdaa4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ grammar.tab.c grammar.tab.h .vscode out -src tmp \ No newline at end of file diff --git a/Makefile b/Makefile index 44c2969..07d1d87 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,7 @@ EXE := alpha CFLAGS := YACC := bison -compiler: tmp/grammar.tab.c tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o - $(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/lex.yy.c tmp/symbol_table.o +compiler: runner tmp/grammar.tab.c: src/grammar.y mkdir -p tmp @@ -14,7 +13,7 @@ tmp/grammar.tab.c: src/grammar.y mv grammar.tab.c tmp/ mv grammar.tab.h tmp/ -tmp/lex.yy.c: src/lexicalStructure.lex +tmp/lex.yy.c: src/lexicalStructure.lex tmp/grammar.tab.c $(FLEX) -o tmp/lex.yy.c $(LEX) mv flex.h tmp/ @@ -25,21 +24,17 @@ tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h $(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c parser : tmp/lex.yy.c tmp/grammar.tab.c - $(CC) -o parser tmp/lex.yy.c tmp/grammar.tab.c src/symbol_table.c + $(CC) -o parser tmp/lex.yy.c tmp/grammar.tab.c runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o $(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/lex.yy.c tmp/symbol_table.o - - - - - - debug: CFLAGS += -DDEBUG=1 debug: clean compiler -test: +test: test-s1 test-s2 + +test-s1: ./$(EXE) -tok ./tests/sprint1/test_comment_fix1.alpha ./$(EXE) -tok ./tests/sprint1/test_comment_fix2.alpha ./$(EXE) -tok ./tests/sprint1/test_comment_issues.alpha @@ -55,6 +50,11 @@ test: ./$(EXE) -tok ./tests/sprint1/test_simple_literals.alpha ./$(EXE) -tok ./tests/sprint1/test_variables.alpha +test-s2: + ./$(EXE) -tok ./tests/sprint2/alpha/test_library.alpha + ./$(EXE) -tok ./tests/sprint2/alpha/test_one_line.alpha + ./$(EXE) -tok ./tests/sprint2/alpha/test_simple.alpha + clean: rm -f *.o rm -f lex.yy.c @@ -65,4 +65,5 @@ clean: rm -f grammar.tab.h rm -f *.st rm -rf out - rm -rf tmp \ No newline at end of file + rm -rf tmp + rm -f parser \ No newline at end of file diff --git a/src/grammar.y b/src/grammar.y index 2302167..0645a4a 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -4,7 +4,7 @@ // Prologue %{ #include - #include "symbol_table.c" + #include "../src/symbol_table.c" extern int yylex(void); void yyerror(const char *err); extern char* yytext; diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 5f1f8ec..79ccaea 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -1,91 +1,84 @@ -/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */ -/* so we placed the citation here. */ -/* definitions */ +/* Lexical Analyzer with Flex (1.6.0) */ %option noyywrap %option header-file="flex.h" %{ - #include - //#include "typedefs.h" - #include "grammar.tab.h" - int line_number = 1, column_number = 1; - #ifndef DEBUG - #define DEBUG 0 - #endif - - + #include + //#include "typedefs.h" + #include "grammar.tab.h" + int line_number = 1, column_number = 1; + #ifndef DEBUG + #define DEBUG 0 + #endif %} STARCOM [^\*]|\*+[^\)\*]+ PARENCOM [^\)]|[^\*\)]+\)+ +COMMENT \(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) ID [A-Za-z_][0-9A-Za-z_]* DIGIT [0-9] CHAR \\n|\\t|\\'|[^'\n\t\\]|\\\\ - /* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */ SCHAR \\n|\\t|\\\"|[^\"\n\\] - /* similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */ %% -"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} -"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} -"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} -"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} +"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} +"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} +"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} +"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} -"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} -"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} -"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} -"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} -"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} -"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} -"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} -"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} -"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} +"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} +"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} +"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} +"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} +"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} +"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} +"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} +"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} +"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} -"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} -"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} +"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} +"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} -"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} -"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} -"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} -"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} -"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} -"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} -"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} -":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} -"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} -"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} -"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} -"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} +"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} +"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} +"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} +"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} +"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} +"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} +"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} +":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} +"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} +"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} +"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} +"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} -";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} -":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} -"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} -"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} +";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} +":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} +"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} +"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} -{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} -'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} -\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} -\(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} +{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} +'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} +\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} +{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} -"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} -")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} +"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} +")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} +"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} +"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} +"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} +"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} -"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} -"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} +"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} +"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} +"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} -"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} -"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {/*yylval.words = strdup(yytext);*/ return ID;}} -"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} -"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} -"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} - -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} - -\n {line_number++; column_number = 1;} -\t {column_number++;} -" " {column_number++;} -. {column_number++; return 1999;} +\n {line_number++; column_number = 1;} +\t {column_number++;} +" " {column_number++;} +. {column_number++; return 1999;} %% diff --git a/src/runner.c b/src/runner.c index 6e0a61b..49f50f8 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1,177 +1,183 @@ -//#include "symbol_table.h" +// #include "symbol_table.h" #include "runner.h" int main(int argc, char *argv[]) { - if (argc == 1) { - fprintf(stderr, "INVALID INPUT: Include a .alpha file or use -help for more inputs \n"); - return -1; - } else if (argc == 2) { - //can be either -help or .alpha file - if (is_help(argv[1])) { - return 0; - } else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) { - //run flex for now - no_flag = SET_FLAG; //no argument but valid input - alpha_file = fopen(argv[1], "r"); + if (argc == 1) { + fprintf( + stderr, + "INVALID INPUT: Include a .alpha file or use -help for more inputs \n"); + return -1; + } else if (argc == 2) { + // can be either -help or .alpha file + if (is_help(argv[1])) { + return 0; + } else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) { + // run flex for now + no_flag = SET_FLAG; // no argument but valid input + alpha_file = fopen(argv[1], "r"); - } else { - fprintf(stderr, "INVALID INPUT: Include a .alpha file or use -help for more inputs\n"); - return -1; - } } else { - //last input must be .alpha - if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) { - fprintf(stderr, "INVALID INPUT: Include a .alpha file at end of input or use -help for more inputs \n"); - return -1; - } else { - //now check that other args are valid (flags will not be null if flag is present) - for (int i = 1; i < argc - 1; i++) { - if (check_flag(argv[i], argv[argc - 1]) != 0) { - fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n"); - return -1; - } - } - alpha_file = fopen(argv[argc - 1], "r"); - } + fprintf(stderr, + "INVALID INPUT: Include a .alpha file or use -help for more " + "inputs\n"); + return -1; } - return run(alpha_file); + } else { + // last input must be .alpha + if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) { + fprintf(stderr, + "INVALID INPUT: Include a .alpha file at end of input or use " + "-help for more inputs \n"); + return -1; + } else { + // now check that other args are valid (flags will not be null if flag is + // present) + for (int i = 1; i < argc - 1; i++) { + if (check_flag(argv[i], argv[argc - 1]) != 0) { + fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n"); + return -1; + } + } + alpha_file = fopen(argv[argc - 1], "r"); + } + } + return run(alpha_file); } -int check_flag(char *arg, char* alpha) { - if (strcmp("-tok", arg) == 0) { - if (tok_flag == NULL) { - return new_file(arg, alpha); - } - fprintf(stderr, "FLAGS REPEAT\n"); - return -1; - } else if (strcmp("-st", arg) == 0) { - if (st_flag == NULL) { - return new_file(arg, alpha); - } - fprintf(stderr, "FLAGS REPEAT\n"); - return -1; - } else { - fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n"); - return -1; +int check_flag(char *arg, char *alpha) { + if (strcmp("-tok", arg) == 0) { + if (tok_flag == NULL) { + return new_file(arg, alpha); } + fprintf(stderr, "FLAGS REPEAT\n"); + return -1; + } else if (strcmp("-st", arg) == 0) { + if (st_flag == NULL) { + return new_file(arg, alpha); + } + fprintf(stderr, "FLAGS REPEAT\n"); + return -1; + } else { + fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n"); + return -1; + } } - int run(FILE *alpha) { - int token; - //check that file exists - if (alpha == NULL) { - fprintf(stderr, "INPUT FILE NOT FOUND\n"); - return -1; - } - yyin = alpha; - while (0 != (token = yylex())) { - if (tok_flag != NULL) { - fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext); - } - if(token == COMMENT){ - for (int i = 0; i < yyleng; i++) { - if(yytext[i] == '\n'){ - line_number++; - column_number = 0; - } - column_number++; - } - continue; - } - if(token == 1999){ - printf("On line number %d and column number %d we have an invalid character:%s\n",line_number,column_number,yytext); - //return -1; -} - column_number += yyleng; - } - - if (st_flag != NULL) { - //output symbol table, file pointer is - //print_symbol_table(top,st_flag); - } - - if (yyin != NULL) { - fclose(yyin); - } - + int token; + // check that file exists + if (alpha == NULL) { + fprintf(stderr, "INPUT FILE NOT FOUND\n"); + return -1; + } + yyin = alpha; + while (0 != (token = yylex())) { if (tok_flag != NULL) { - fclose(tok_flag); + fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, token, + yytext); } + if (token == COMMENT) { + for (int i = 0; i < yyleng; i++) { + if (yytext[i] == '\n') { + line_number++; + column_number = 0; + } + column_number++; + } + continue; + } + if (token == 1999) { + printf( + "On line number %d and column number %d we have an invalid " + "character:%s\n", + line_number, column_number, yytext); + // return -1; + } + column_number += yyleng; + } - return 0; + if (st_flag != NULL) { + // output symbol table, file pointer is + // print_symbol_table(top,st_flag); + } + + if (yyin != NULL) { + fclose(yyin); + } + + if (tok_flag != NULL) { + fclose(tok_flag); + } + + return 0; } - - -bool is_help(char * input) { - if (strcmp(input, "-help") == 0) { - printf("%s", HELP); - return true; - } - return false; +bool is_help(char *input) { + if (strcmp(input, "-help") == 0) { + printf("%s", HELP); + return true; + } + return false; } int new_file(char *arg, char *alpha) { - int type_len; - const char *basename = alpha; - const char *slash = strchr(alpha, '/'); + int type_len; + const char *basename = alpha; + const char *slash = strchr(alpha, '/'); - while (slash != NULL) { - basename = slash + 1; - slash = strchr(basename, '/'); - } - - mkdir("./out", 0777); + while (slash != NULL) { + basename = slash + 1; + slash = strchr(basename, '/'); + } - char *new_basename = calloc(strlen(basename) + 5, sizeof(char)); - strcpy(new_basename, "./out/"); - strcat(new_basename, basename); - basename = new_basename; + mkdir("./out", 0777); - if (strcmp(arg, "-tok") == 0) { - type_len = TOK_LEN; - } else if (strcmp(arg, "-st") == 0) { - type_len = ST_LEN; - } else { - fprintf(stderr, "INVALID FLAG: Use -help to view valid inputs\n"); - return -1; - } + char *new_basename = calloc(strlen(basename) + 5, sizeof(char)); + strcpy(new_basename, "./out/"); + strcat(new_basename, basename); + basename = new_basename; + if (strcmp(arg, "-tok") == 0) { + type_len = TOK_LEN; + } else if (strcmp(arg, "-st") == 0) { + type_len = ST_LEN; + } else { + fprintf(stderr, "INVALID FLAG: Use -help to view valid inputs\n"); + return -1; + } - // calculate lengths - int basename_len = strlen(basename); - char *file_name = calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char)); + // calculate lengths + int basename_len = strlen(basename); + char *file_name = + calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char)); - //coy filename and add extension - strncpy(file_name, basename, basename_len - ALPHA_OFFSET); - strcat(file_name, "."); - strcat(file_name, arg + 1); + // coy filename and add extension + strncpy(file_name, basename, basename_len - ALPHA_OFFSET); + strcat(file_name, "."); + strcat(file_name, arg + 1); - - if (strcmp(arg, "-tok") == 0) { - tok_flag = fopen(file_name, "w"); - } else if (strcmp(arg, "-st") == 0) { - st_flag = fopen(file_name, "w"); - } - return 0; + if (strcmp(arg, "-tok") == 0) { + tok_flag = fopen(file_name, "w"); + } else if (strcmp(arg, "-st") == 0) { + st_flag = fopen(file_name, "w"); + } + return 0; } - int is_alpha_file(char *alpha, int file_len) { - if (strcmp(".alpha", alpha + sizeof(char) * (file_len - ALPHA_OFFSET)) != 0) { - return -1; //not alpha file - } - return 0; //is alpha file + if (strcmp(".alpha", alpha + sizeof(char) * (file_len - ALPHA_OFFSET)) != 0) { + return -1; // not alpha file + } + return 0; // is alpha file } -void enter_scope(int line, int column){ - curr = CreateScope(curr, line, column); +void enter_scope(int line, int column) { + curr = CreateScope(curr, line, column); } void exit_scope() { - if(curr->Parent_Scope == NULL){ - printf("Can't close top"); - return; - } - curr = curr->Parent_Scope; + if (curr->Parent_Scope == NULL) { + printf("Can't close top"); + return; + } + curr = curr->Parent_Scope; } diff --git a/src/runner.h b/src/runner.h index 63d6fd2..7c0d83a 100644 --- a/src/runner.h +++ b/src/runner.h @@ -1,29 +1,35 @@ #define ALPHA_OFFSET 6 #define TOK_LEN 3 #define ST_LEN 2 -#define HELP "HELP:\nHow to run the alpha compiler:\n./alpha [options] program\nValid options:\n-tok output the token number, token, line number, and column number for each of the tokens to the .tok file\n-st output the symbol table for the program to the .st file\n-help print this message and exit the alpha compiler\n" -//use to set flags for arg types +#define HELP \ + "HELP:\nHow to run the alpha compiler:\n./alpha [options] program\nValid " \ + "options:\n-tok output the token number, token, line number, and column " \ + "number for each of the tokens to the .tok file\n-st output the symbol " \ + "table for the program to the .st file\n-help print this message and exit " \ + "the alpha compiler\n" +// use to set flags for arg types #define SET_FLAG 1 -#include +#include #include #include -#include "../tmp/flex.h" -#include "typedefs.h" -#include -#include "symbol_table.h" +#include #include +#include "../tmp/flex.h" +#include "symbol_table.h" +#include "typedefs.h" + extern int line_number, column_number; extern char *yytext; extern FILE *yyin; int arg; -SymbolTable * top; -SymbolTable * curr; +SymbolTable *top; +SymbolTable *curr; // int main(int argc, char* argv[]); -char *is_tok(int argc, char* argv[]); +char *is_tok(int argc, char *argv[]); // int is_alpha_file(char *file, int file_len); void enter_scope(int, int); void exit_scope(void); @@ -33,9 +39,9 @@ FILE *tok_flag = NULL; FILE *st_flag = NULL; int no_flag = 0; -int main(int argc, char* argv[]); +int main(int argc, char *argv[]); int new_file(char *arg, char *alpha); int is_alpha_file(char *alpha, int file_len); -bool is_help(char * input); -int run(FILE*alpha); -int check_flag(char * arg, char* alpha); +bool is_help(char *input); +int run(FILE *alpha); +int check_flag(char *arg, char *alpha); From 4d674eb8b740047a5cb059e5a1ca8ce95707c50f Mon Sep 17 00:00:00 2001 From: Scarlett Date: Wed, 5 Mar 2025 12:30:33 -0500 Subject: [PATCH 20/31] Testing update with check.sh --- Makefile | 30 +++++++---------- check.sh | 27 ++++++++++++++++ src/grammar.y | 4 +-- src/lexicalStructure.lex | 8 +++-- src/runner.c | 32 ++++++++----------- src/runner.h | 8 +++-- .../expected/sp1_comment_fix1.expected | 1 + .../sp1_comment_fix1.alpha} | 0 .../sp1_comment_fix2.alpha} | 0 .../sp1_comment_issues.alpha} | 0 .../sp1_comments.alpha} | 0 .../sp1_general_token.alpha} | 0 .../sp1_keywords.alpha} | 0 .../sp1_operators.alpha} | 0 .../sp1_other_punc.alpha} | 0 .../sp1_punc_grouping.alpha} | 0 .../sp1_real_alpha_file1.alpha} | 0 .../sp1_real_alpha_file2.alpha} | 0 .../sp1_simple_int.alpha} | 0 .../sp1_simple_literals.alpha} | 0 .../sp1_variables.alpha} | 0 tests/sprint2/test/sp2_library.alpha | 30 +++++++++++++++++ tests/sprint2/test/sp2_one_line.alpha | 1 + tests/sprint2/test/sp2_simple.alpha | 4 +++ 24 files changed, 101 insertions(+), 44 deletions(-) create mode 100755 check.sh create mode 100644 tests/sprint1/expected/sp1_comment_fix1.expected rename tests/sprint1/{test_comment_fix1.alpha => test/sp1_comment_fix1.alpha} (100%) rename tests/sprint1/{test_comment_fix2.alpha => test/sp1_comment_fix2.alpha} (100%) rename tests/sprint1/{test_comment_issues.alpha => test/sp1_comment_issues.alpha} (100%) rename tests/sprint1/{test_comments.alpha => test/sp1_comments.alpha} (100%) rename tests/sprint1/{test_general_token.alpha => test/sp1_general_token.alpha} (100%) rename tests/sprint1/{test_keywords.alpha => test/sp1_keywords.alpha} (100%) rename tests/sprint1/{test_operators.alpha => test/sp1_operators.alpha} (100%) rename tests/sprint1/{test_other_punc.alpha => test/sp1_other_punc.alpha} (100%) rename tests/sprint1/{test_punc_grouping.alpha => test/sp1_punc_grouping.alpha} (100%) rename tests/sprint1/{test_real_alpha_file1.alpha => test/sp1_real_alpha_file1.alpha} (100%) rename tests/sprint1/{test_real_alpha_file2.alpha => test/sp1_real_alpha_file2.alpha} (100%) rename tests/sprint1/{test_simple_int.alpha => test/sp1_simple_int.alpha} (100%) rename tests/sprint1/{test_simple_literals.alpha => test/sp1_simple_literals.alpha} (100%) rename tests/sprint1/{test_variables.alpha => test/sp1_variables.alpha} (100%) create mode 100644 tests/sprint2/test/sp2_library.alpha create mode 100644 tests/sprint2/test/sp2_one_line.alpha create mode 100644 tests/sprint2/test/sp2_simple.alpha diff --git a/Makefile b/Makefile index 07d1d87..256aad2 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,12 @@ FLEX := flex LEX := src/lexicalStructure.lex EXE := alpha CFLAGS := -YACC := bison +YACC := bison -compiler: runner +TESTS-S1 := $(wildcard tests/sprint1/test/*.alpha) +TESTS-S2 := $(wildcard tests/sprint2/test/*.alpha) + +compiler: clean runner tmp/grammar.tab.c: src/grammar.y mkdir -p tmp @@ -35,25 +38,14 @@ debug: clean compiler test: test-s1 test-s2 test-s1: - ./$(EXE) -tok ./tests/sprint1/test_comment_fix1.alpha - ./$(EXE) -tok ./tests/sprint1/test_comment_fix2.alpha - ./$(EXE) -tok ./tests/sprint1/test_comment_issues.alpha - ./$(EXE) -tok ./tests/sprint1/test_comments.alpha - ./$(EXE) -tok ./tests/sprint1/test_general_token.alpha - ./$(EXE) -tok ./tests/sprint1/test_keywords.alpha - ./$(EXE) -tok ./tests/sprint1/test_operators.alpha - ./$(EXE) -tok ./tests/sprint1/test_other_punc.alpha - ./$(EXE) -tok ./tests/sprint1/test_punc_grouping.alpha - ./$(EXE) -tok ./tests/sprint1/test_real_alpha_file1.alpha - ./$(EXE) -tok ./tests/sprint1/test_real_alpha_file2.alpha - ./$(EXE) -tok ./tests/sprint1/test_simple_int.alpha - ./$(EXE) -tok ./tests/sprint1/test_simple_literals.alpha - ./$(EXE) -tok ./tests/sprint1/test_variables.alpha + chmod +x ./check.sh + $(foreach test, $(TESTS-S1), ./$(EXE) -tok $(test);) + ./check.sh test-s2: - ./$(EXE) -tok ./tests/sprint2/alpha/test_library.alpha - ./$(EXE) -tok ./tests/sprint2/alpha/test_one_line.alpha - ./$(EXE) -tok ./tests/sprint2/alpha/test_simple.alpha + chmod +x ./check.sh + $(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);) + ./check.sh clean: rm -f *.o diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..b8b138c --- /dev/null +++ b/check.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Diff-Check Tool # +# Checks if outputed TOK = exp # +# The Translators - Spring 2025 # + +TOK_DIR="out" + +if [[ ! -d "$TOK_DIR" ]]; then + echo "Directory $TOK_DIR does not exist." + exit 1 +fi + +echo -e "\n" +for file in "$TOK_DIR"/*; do + filename=$(basename -- "$file") + filename="${filename%.*}" + num=${filename:2:1} + exp="./tests/sprint$num/expected/$filename.expected" + + if [[ -f "$exp" ]]; then + echo -e "--------------------------------------------" + echo -e "Checking $file...\n" + diff --color=always "$file" "$exp" + echo -e "--------------------------------------------\n" + fi +done \ No newline at end of file diff --git a/src/grammar.y b/src/grammar.y index 0645a4a..db116e7 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,5 +1,5 @@ -/* Syntax Analyzer with Bison (3.8.1) */ -/* (referenced Bison manual for file boilerplate [3.1]) */ +/* Syntax Analyzer with Bison (3.8.1) */ +/* The Translators - Spring 2025 */ // Prologue %{ diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 79ccaea..7a5f113 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -1,15 +1,17 @@ -/* Lexical Analyzer with Flex (1.6.0) */ +/* Lexical Analyzer with Flex (1.6.0) */ +/* The Translators - Spring 2025 */ %option noyywrap %option header-file="flex.h" + %{ #include - //#include "typedefs.h" #include "grammar.tab.h" - int line_number = 1, column_number = 1; #ifndef DEBUG #define DEBUG 0 #endif + + int line_number = 1, column_number = 1; %} STARCOM [^\*]|\*+[^\)\*]+ diff --git a/src/runner.c b/src/runner.c index 49f50f8..7ee5d58 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1,37 +1,32 @@ -// #include "symbol_table.h" +/* Runner File - Compiles alpha Compiler */ +/* The Translators - Spring 2025 */ + #include "runner.h" int main(int argc, char *argv[]) { if (argc == 1) { fprintf( - stderr, - "INVALID INPUT: Include a .alpha file or use -help for more inputs \n"); + stderr, INVALID); return -1; - } else if (argc == 2) { - // can be either -help or .alpha file + } + + else if (argc == 2) { if (is_help(argv[1])) { return 0; } else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) { - // run flex for now - no_flag = SET_FLAG; // no argument but valid input + no_flag = SET_FLAG; alpha_file = fopen(argv[1], "r"); - } else { - fprintf(stderr, - "INVALID INPUT: Include a .alpha file or use -help for more " - "inputs\n"); + fprintf(stderr, INVALID); return -1; } - } else { - // last input must be .alpha + } + + else { if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) { - fprintf(stderr, - "INVALID INPUT: Include a .alpha file at end of input or use " - "-help for more inputs \n"); + fprintf(stderr, INVALID); return -1; } else { - // now check that other args are valid (flags will not be null if flag is - // present) for (int i = 1; i < argc - 1; i++) { if (check_flag(argv[i], argv[argc - 1]) != 0) { fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n"); @@ -117,6 +112,7 @@ bool is_help(char *input) { printf("%s", HELP); return true; } + return false; } diff --git a/src/runner.h b/src/runner.h index 7c0d83a..2c516bf 100644 --- a/src/runner.h +++ b/src/runner.h @@ -1,3 +1,6 @@ +/* Runner File - Compiles alpha Compiler */ +/* The Translators - Spring 2025 */ + #define ALPHA_OFFSET 6 #define TOK_LEN 3 #define ST_LEN 2 @@ -7,8 +10,9 @@ "number for each of the tokens to the .tok file\n-st output the symbol " \ "table for the program to the .st file\n-help print this message and exit " \ "the alpha compiler\n" -// use to set flags for arg types -#define SET_FLAG 1 +#define SET_FLAG 1 // Used to set flags for arg types +#define INVALID \ + "INVALID INPUT: Include a .alpha file or use -help for more inputs \n" #include #include diff --git a/tests/sprint1/expected/sp1_comment_fix1.expected b/tests/sprint1/expected/sp1_comment_fix1.expected new file mode 100644 index 0000000..07d66e1 --- /dev/null +++ b/tests/sprint1/expected/sp1_comment_fix1.expected @@ -0,0 +1 @@ + daskmskdfm \ No newline at end of file diff --git a/tests/sprint1/test_comment_fix1.alpha b/tests/sprint1/test/sp1_comment_fix1.alpha similarity index 100% rename from tests/sprint1/test_comment_fix1.alpha rename to tests/sprint1/test/sp1_comment_fix1.alpha diff --git a/tests/sprint1/test_comment_fix2.alpha b/tests/sprint1/test/sp1_comment_fix2.alpha similarity index 100% rename from tests/sprint1/test_comment_fix2.alpha rename to tests/sprint1/test/sp1_comment_fix2.alpha diff --git a/tests/sprint1/test_comment_issues.alpha b/tests/sprint1/test/sp1_comment_issues.alpha similarity index 100% rename from tests/sprint1/test_comment_issues.alpha rename to tests/sprint1/test/sp1_comment_issues.alpha diff --git a/tests/sprint1/test_comments.alpha b/tests/sprint1/test/sp1_comments.alpha similarity index 100% rename from tests/sprint1/test_comments.alpha rename to tests/sprint1/test/sp1_comments.alpha diff --git a/tests/sprint1/test_general_token.alpha b/tests/sprint1/test/sp1_general_token.alpha similarity index 100% rename from tests/sprint1/test_general_token.alpha rename to tests/sprint1/test/sp1_general_token.alpha diff --git a/tests/sprint1/test_keywords.alpha b/tests/sprint1/test/sp1_keywords.alpha similarity index 100% rename from tests/sprint1/test_keywords.alpha rename to tests/sprint1/test/sp1_keywords.alpha diff --git a/tests/sprint1/test_operators.alpha b/tests/sprint1/test/sp1_operators.alpha similarity index 100% rename from tests/sprint1/test_operators.alpha rename to tests/sprint1/test/sp1_operators.alpha diff --git a/tests/sprint1/test_other_punc.alpha b/tests/sprint1/test/sp1_other_punc.alpha similarity index 100% rename from tests/sprint1/test_other_punc.alpha rename to tests/sprint1/test/sp1_other_punc.alpha diff --git a/tests/sprint1/test_punc_grouping.alpha b/tests/sprint1/test/sp1_punc_grouping.alpha similarity index 100% rename from tests/sprint1/test_punc_grouping.alpha rename to tests/sprint1/test/sp1_punc_grouping.alpha diff --git a/tests/sprint1/test_real_alpha_file1.alpha b/tests/sprint1/test/sp1_real_alpha_file1.alpha similarity index 100% rename from tests/sprint1/test_real_alpha_file1.alpha rename to tests/sprint1/test/sp1_real_alpha_file1.alpha diff --git a/tests/sprint1/test_real_alpha_file2.alpha b/tests/sprint1/test/sp1_real_alpha_file2.alpha similarity index 100% rename from tests/sprint1/test_real_alpha_file2.alpha rename to tests/sprint1/test/sp1_real_alpha_file2.alpha diff --git a/tests/sprint1/test_simple_int.alpha b/tests/sprint1/test/sp1_simple_int.alpha similarity index 100% rename from tests/sprint1/test_simple_int.alpha rename to tests/sprint1/test/sp1_simple_int.alpha diff --git a/tests/sprint1/test_simple_literals.alpha b/tests/sprint1/test/sp1_simple_literals.alpha similarity index 100% rename from tests/sprint1/test_simple_literals.alpha rename to tests/sprint1/test/sp1_simple_literals.alpha diff --git a/tests/sprint1/test_variables.alpha b/tests/sprint1/test/sp1_variables.alpha similarity index 100% rename from tests/sprint1/test_variables.alpha rename to tests/sprint1/test/sp1_variables.alpha diff --git a/tests/sprint2/test/sp2_library.alpha b/tests/sprint2/test/sp2_library.alpha new file mode 100644 index 0000000..9bacd6c --- /dev/null +++ b/tests/sprint2/test/sp2_library.alpha @@ -0,0 +1,30 @@ +(* At compiler start-up your program should create symbol table entries for the four primitive types: + Boolean (1 byte) + character (1 byte) + integer (4 bytes) + address (8 bytes) +You should #include this file at the start of your alpha file. +Some useful types are defined below. +*) +type string: 1 -> character +type BooleanXBoolean: [Boolean: x, y] +type characterXcharacter: [character: x, y] +type integerXinteger: [integer: x, y] + +type Boolean2Boolean: Boolean -> Boolean +type integer2integer: integer -> integer +type character2integer: character -> integer +type Boolean2integer: Boolean -> integer +type string2integer: string -> integer +type integerXinteger2integer: integerXinteger -> integer +type integerXinteger2Boolean: integerXinteger -> Boolean +type characterXcharacter2Boolean: characterXcharacter -> Boolean +type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean +type integer2address: integer -> address +type address2integer: address -> integer +external function printInteger: integer2integer +external function printCharacter: character2integer +external function printBoolean: Boolean2integer +external function reserve: integer2address +external function release: address2integer +function entry: string2integer diff --git a/tests/sprint2/test/sp2_one_line.alpha b/tests/sprint2/test/sp2_one_line.alpha new file mode 100644 index 0000000..01f115e --- /dev/null +++ b/tests/sprint2/test/sp2_one_line.alpha @@ -0,0 +1 @@ +type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } diff --git a/tests/sprint2/test/sp2_simple.alpha b/tests/sprint2/test/sp2_simple.alpha new file mode 100644 index 0000000..13f3c9f --- /dev/null +++ b/tests/sprint2/test/sp2_simple.alpha @@ -0,0 +1,4 @@ +#include "library.alpha" +entry(arg) := { + return 0; +} From 45940c0500b4048b273165385c7661f7b15b74aa Mon Sep 17 00:00:00 2001 From: Scarlett Date: Wed, 5 Mar 2025 12:54:30 -0500 Subject: [PATCH 21/31] quick update #30 --- .gitignore | 3 ++- Makefile | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e6bdaa4..8cf77d3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ grammar.tab.c grammar.tab.h .vscode out -tmp \ No newline at end of file +tmp +parser \ No newline at end of file diff --git a/Makefile b/Makefile index 256aad2..d742a62 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ tmp/runner.o: src/runner.c src/runner.h tmp/flex.h tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h $(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c -parser : tmp/lex.yy.c tmp/grammar.tab.c +parser : clean tmp/lex.yy.c tmp/grammar.tab.c $(CC) -o parser tmp/lex.yy.c tmp/grammar.tab.c runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o From c2f28b68369af66d8eafc709381699595063fd8c Mon Sep 17 00:00:00 2001 From: Scarlett Date: Wed, 5 Mar 2025 14:01:34 -0500 Subject: [PATCH 22/31] Combined binaries (parser + alpha) --- Makefile | 6 ++-- src/grammar.y | 6 ++-- src/lexicalStructure.lex | 4 +-- src/runner.c | 65 +++++++++++++++++++++++----------------- src/runner.h | 3 +- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index d742a62..fe8f769 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,8 @@ tmp/runner.o: src/runner.c src/runner.h tmp/flex.h tmp/symbol_table.o: src/symbol_table.c src/symbol_table.h $(CC) $(CFLAGS) -o tmp/symbol_table.o -c src/symbol_table.c -parser : clean tmp/lex.yy.c tmp/grammar.tab.c - $(CC) -o parser tmp/lex.yy.c tmp/grammar.tab.c - runner: tmp/lex.yy.c tmp/runner.o tmp/symbol_table.o - $(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/lex.yy.c tmp/symbol_table.o + $(CC) $(CFLAGS) -o $(EXE) tmp/runner.o tmp/grammar.tab.c tmp/lex.yy.c debug: CFLAGS += -DDEBUG=1 debug: clean compiler @@ -46,6 +43,7 @@ test-s2: chmod +x ./check.sh $(foreach test, $(TESTS-S2), ./$(EXE) -tok $(test);) ./check.sh + $(foreach test, $(TESTS-S2), ./$(EXE) $(test);) clean: rm -f *.o diff --git a/src/grammar.y b/src/grammar.y index db116e7..4f65856 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -253,10 +253,10 @@ types: %% void yyerror(const char *err) { - // fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); + fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); } -int main() { +/* int main() { //char *str = strdup("taco"); //cur_value = NULL; //cur_type = NULL; @@ -276,4 +276,4 @@ int main() { //} //} return 0; -} +} */ diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 7a5f113..bf05e1d 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -6,7 +6,7 @@ %{ #include - #include "grammar.tab.h" + #include "../tmp/grammar.tab.h" #ifndef DEBUG #define DEBUG 0 #endif @@ -76,7 +76,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] "false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} "null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {/*yylval.words = strdup(yytext);*/ return ID;}} +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} \n {line_number++; column_number = 1;} \t {column_number++;} diff --git a/src/runner.c b/src/runner.c index 7ee5d58..85e9495 100644 --- a/src/runner.c +++ b/src/runner.c @@ -5,8 +5,7 @@ int main(int argc, char *argv[]) { if (argc == 1) { - fprintf( - stderr, INVALID); + fprintf(stderr, INVALID); return -1; } @@ -60,35 +59,46 @@ int check_flag(char *arg, char *alpha) { int run(FILE *alpha) { int token; - // check that file exists + curr = CreateScope(NULL, 1, 1); + + // If file is not found if (alpha == NULL) { fprintf(stderr, "INPUT FILE NOT FOUND\n"); return -1; } yyin = alpha; - while (0 != (token = yylex())) { - if (tok_flag != NULL) { - fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, token, - yytext); - } - if (token == COMMENT) { - for (int i = 0; i < yyleng; i++) { - if (yytext[i] == '\n') { - line_number++; - column_number = 0; - } - column_number++; + + // TOK FLAG + if (tok_flag != NULL) { + while (0 != (token = yylex())) { + if (tok_flag != NULL) { + fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, + token, yytext); } - continue; + if (token == COMMENT) { + for (int i = 0; i < yyleng; i++) { + if (yytext[i] == '\n') { + line_number++; + column_number = 0; + } + column_number++; + } + continue; + } + if (token == 1999) { + printf( + "On line number %d and column number %d we have an invalid " + "character:%s\n", + line_number, column_number, yytext); + } + column_number += yyleng; } - if (token == 1999) { - printf( - "On line number %d and column number %d we have an invalid " - "character:%s\n", - line_number, column_number, yytext); - // return -1; + fclose(tok_flag); + + if (yyin != NULL) { + fclose(yyin); } - column_number += yyleng; + return 0; } if (st_flag != NULL) { @@ -96,14 +106,15 @@ int run(FILE *alpha) { // print_symbol_table(top,st_flag); } + yyparse(); + FILE *f = fdopen(1, "w"); + print_symbol_table(getAncestor(curr), f); + fclose(f); + if (yyin != NULL) { fclose(yyin); } - if (tok_flag != NULL) { - fclose(tok_flag); - } - return 0; } diff --git a/src/runner.h b/src/runner.h index 2c516bf..daff88c 100644 --- a/src/runner.h +++ b/src/runner.h @@ -22,7 +22,8 @@ #include "../tmp/flex.h" #include "symbol_table.h" -#include "typedefs.h" +//#include "typedefs.h" +#include "../tmp/grammar.tab.h" extern int line_number, column_number; extern char *yytext; From f819a68ef7226931f220c3f160b2c3fea413d1ae Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Wed, 5 Mar 2025 15:02:30 -0500 Subject: [PATCH 23/31] runner and parser together add entries ok --- src/grammar.y | 389 ++++++++++++++------------ src/lexicalStructure.lex | 2 +- src/runner.c | 10 +- src/runner.h | 2 +- tests/sprint2/test/sp2_one_line.alpha | 2 +- 5 files changed, 211 insertions(+), 194 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 4f65856..3b5359f 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,5 +1,5 @@ -/* Syntax Analyzer with Bison (3.8.1) */ -/* The Translators - Spring 2025 */ +/* Syntax Analyzer with Bison (3.8.1) */ +/* (referenced Bison manual for file boilerplate [3.1]) */ // Prologue %{ @@ -9,148 +9,151 @@ void yyerror(const char *err); extern char* yytext; extern int yychar; - SymbolTable * st; + extern SymbolTable * cur; //char* cur_value; //char* cur_type; int token_tracker; extern int line_number; extern int column_number; + extern FILE * yyin; %} %union { - int integ; - char * words; + int integ; + char * words; } //precedence order -%precedence RESERVE -%precedence RELEASE -%precedence DOT -%precedence SUB_OR_NEG -%precedence NOT -%left MUL -%left DIV -%left REM -%left ADD //need subtraction only here +%type id_or_types +%type types +%token ID 101 +%token T_INTEGER 201 +%token T_ADDRESS 202 +%token T_BOOLEAN 203 +%token T_CHARACTER 204 +%token T_STRING 205 +%token C_INTEGER 301 +%token C_NULL 302 +%token C_CHARACTER 303 +%token C_STRING 304 +%token C_TRUE 305 +%token C_FALSE 306 +%token WHILE 401 +%token IF 402 +%token THEN 403 +%token ELSE 404 +%token TYPE 405 +%token FUNCTION 406 +%token RETURN 407 +%token EXTERNAL 408 +%token AS 409 +%token L_PAREN 501 +%token R_PAREN 502 +%token L_BRACKET 503 +%token R_BRACKET 504 +%token L_BRACE 505 +%token R_BRACE 506 +%token SEMI_COLON 507 +%token COLON 508 +%token COMMA 509 +%token ARROW 510 +%token MUL 603 +%token DIV 604 +%token REM 605 +%token ADD 601 +%token LESS_THAN 606 +%token EQUAL_TO 607 +%token AND 610 +%token OR 611 +%token ASSIGN 608 +%token SUB_OR_NEG 602 +%token NOT 609 +%token DOT 612 +%token RESERVE 613 +%token RELEASE 614 +%token COMMENT 700 +%precedence RESERVE RELEASE +%precedence DOT +%precedence UMINUS +%precedence NOT +%left MUL DIV REM +%left ADD SUB_OR_NEG %left LESS_THAN %left EQUAL_TO %left AND %left OR %left ASSIGN -%token ID 101 -%token T_INTEGER 201 -%token T_ADDRESS 202 -%token T_BOOLEAN 203 -%token T_CHARACTER 204 -%token T_STRING 205 -%token C_INTEGER 301 -%token C_NULL 302 -%token C_CHARACTER 303 -%token C_STRING 304 -%token C_TRUE 305 -%token C_FALSE 306 -%token WHILE 401 -%token IF 402 -%token THEN 403 -%token ELSE 404 -%token TYPE 405 -%token FUNCTION 406 -%token RETURN 407 -%token EXTERNAL 408 -%token AS 409 -%token L_PAREN 501 -%token R_PAREN 502 -%token L_BRACKET 503 -%token R_BRACKET 504 -%token L_BRACE 505 -%token R_BRACE 506 -%token SEMI_COLON 507 -%token COLON 508 -%token COMMA 509 -%token ARROW 510 -/* %token ADD 601 -%token SUB_OR_NEG 602 -%token MUL 603 -%token DIV 604 -%token REM 605 -%token LESS_THAN 606 -%token EQUAL_TO 607 -%token ASSIGN 608 -%token NOT 609 -%token AND 610 -%token OR 611 -%token DOT 612 -%token RESERVE 613 -%token RELEASE 614 */ -%token COMMENT 700 - %% -program: - prototype_or_definition_list; +program: + prototype_or_definition_list; prototype_or_definition_list: - prototype prototype_or_definition_list - | definition prototype_or_definition_list - | prototype - | definition - ; + prototype prototype_or_definition_list + | definition prototype_or_definition_list + | prototype + | definition + ; prototype: - L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; + L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; definition: - TYPE ID COLON dblock - | TYPE ID COLON constant ARROW ID - | TYPE ID COLON types ARROW ID - | FUNCTION ID COLON ID - | TYPE ID COLON ID ARROW ID - | ID parameter ASSIGN sblock - ; + TYPE ID COLON dblock + | TYPE ID COLON constant ARROW ID + //| TYPE ID COLON types ARROW ID + | function_declaration + | TYPE ID COLON id_or_types ARROW id_or_types + | ID parameter ASSIGN sblock + ; +function_declaration: + FUNCTION { printf("found a function def\n"); }ID COLON ID + | EXTERNAL { printf("found an external function def\n"); }FUNCTION ID COLON ID + ; parameter: - L_PAREN ID R_PAREN - | AS L_PAREN idlist R_PAREN - ; + L_PAREN { printf("found a param def\n"); } ID R_PAREN + | AS{ printf("found a param_as_list def\n"); } L_PAREN idlist R_PAREN + ; idlist: - ID COMMA idlist - |ID - ; + ID COMMA idlist + |ID + ; sblock: - L_BRACE {st = CreateScope(st,2,2);} statement_list {st = getParent(st);} R_BRACE - | L_BRACE {st = CreateScope(st,2,2);} dblock statement_list {st = getParent(st);} R_BRACE - ; + L_BRACE {printf("open brace\n"); cur = CreateScope(cur,2,2);} statement_list {printf("close brace\n"); cur = getParent(cur);} R_BRACE + | L_BRACE {printf("open brace\n"); cur = CreateScope(cur,2,2);} dblock statement_list {printf("close brace\n"); cur = getParent(cur);} R_BRACE + ; dblock: - L_BRACKET declaration_list R_BRACKET; + L_BRACKET declaration_list R_BRACKET; declaration_list: - declaration - {printf( - "declaration list a rule encountered"); - //CreateEntry(st,cur_type,cur_value); - } - SEMI_COLON declaration_list - | declaration - {printf( - "declaration rule b encountered"); - //CreateEntry(st,cur_type,cur_value); - } - ; + declaration + {printf( + "found a decleration of form dec;dec_list\n"); + //CreateEntry(cur,cur_type,cur_value); + } + SEMI_COLON declaration_list + | declaration + {printf( + "found a decleration of form dec\n"); + //CreateEntry(cur,cur_type,cur_value); + } + ; declaration: - ID COLON ID { - - CreateEntry(st,strdup($1),strdup($3)); + id_or_types COLON ID { + + CreateEntry(cur,$1,$3); // printf("declaration rule encountered"); // if(cur_value != NULL){ // char* delete1 = cur_value; // printf("delete1 var assigned to cur_value"); // free(delete1); -// printf("delete1 var freed"); +// printf("delete1 var freed"); // } // if(cur_type != NULL){ // char* delete2 = cur_type; @@ -161,119 +164,133 @@ declaration: // printf("space allocated"); // strcpy(cur_value, $1); // printf("string copied over"); - + // len = strlen($3); // cur_type = malloc(len + 1); // strcpy(cur_type, $3); // printf("value var is %s type var is %s\n",cur_value,cur_type); - } - | types COLON ID - ; - + } +// | types COLON ID + ; +id_or_types: + ID + | types + ; statement_list: - compound_statement statement_list - | compound_statement - | simple_statement SEMI_COLON statement_list - | simple_statement SEMI_COLON - ; + compound_statement statement_list + | compound_statement + | simple_statement SEMI_COLON statement_list + | simple_statement SEMI_COLON + ; compound_statement: - WHILE L_PAREN expression R_PAREN sblock - | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock - | sblock - ; + WHILE {printf("found an while statment\n"); } L_PAREN expression R_PAREN sblock + | IF {printf("found an if statment\n"); }L_PAREN expression R_PAREN THEN sblock ELSE sblock + | sblock + ; + +// Ref Compilers Principles, Techniques, & Tools + + + simple_statement: - assignable ASSIGN expression - | RETURN expression - ; + assignable ASSIGN {printf("found an assignment statment\n"); } expression +// I think that we need to add memOp stuff here | assignable ASSIGN expression {printf("found an assignment statment\n"); } + | RETURN {printf("found an return statment\n"); } expression + ; assignable: - ID - | assignable ablock - | assignable DOT ID - ; + ID + | assignable ablock + | assignable rec_op ID + ; + +rec_op : + DOT expression: - constant - | UnaryOperator expression - | assignable - | constant binaryOperator expression - | L_PAREN expression R_PAREN - | memOp assignable - ; + constant + | SUB_OR_NEG expression %prec UMINUS + | NOT expression + | expression ADD expression + | expression SUB_OR_NEG expression + | expression MUL expression + | expression DIV expression + | expression REM expression + | expression AND expression + | expression OR expression + | expression LESS_THAN expression + | expression EQUAL_TO expression + | assignable + //| constant binaryOperator expression + //| ID binaryOperator expression + | L_PAREN expression R_PAREN + | memOp assignable + ; + + ablock: - L_PAREN argument_list R_PAREN; + L_PAREN argument_list R_PAREN; argument_list: - expression COMMA argument_list - | expression - ; + expression COMMA argument_list + | expression + ; -UnaryOperator: - SUB_OR_NEG - | NOT - ; memOp: - RESERVE - | RELEASE - ; + RESERVE + | RELEASE + ; -binaryOperator: - ADD - | SUB_OR_NEG - | MUL - | DIV - | REM - | AND - | OR - | LESS_THAN - | EQUAL_TO - ; constant: - C_STRING - | C_INTEGER - | C_NULL - | C_CHARACTER - | C_TRUE - | C_FALSE - ; + C_STRING + | C_INTEGER + | C_NULL + | C_CHARACTER + | C_TRUE + | C_FALSE + ; types: - T_STRING - | T_INTEGER - | T_ADDRESS - | T_CHARACTER - | T_BOOLEAN - ; + T_STRING + | T_INTEGER + | T_ADDRESS + | T_CHARACTER + | T_BOOLEAN + ; // %% void yyerror(const char *err) { fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); } - -/* int main() { - //char *str = strdup("taco"); - //cur_value = NULL; - //cur_type = NULL; - - token_tracker = 1; - st=CreateScope(NULL,1,1); - //int a; - yyparse(); - //while ((a = yyparse() != EOF){ - // token_tracker++; - //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); - //if(yytext[0] == '\n'){ - FILE* f = fdopen(1,"w"); - print_symbol_table(getAncestor(st),f); - fclose(f); - // break; - //} - //} - return 0; +/* +int main(int argc, char * argv[]) { + token_tracker = 1; + cur=CreateScope(NULL,1,1); + //int a; + FILE * fp; + if(argc > 1){ + fp = fopen(argv[1], "r"); + yyin = fp; + } else { + fp = stdin; + yyin = fp; + } + yyparse(); + //while ((a = yyparse() != EOF){ + // token_tracker++; + //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); + //if(yytext[0] == '\n'){ + FILE* f = fdopen(1,"w"); + print_symbol_table(getAncestor(cur),f); + fclose(f); + // break; + //} + //} + return 0; } */ diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index bf05e1d..c2db6b5 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -63,7 +63,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] {DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} '{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} \"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} -{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}} +{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} "(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} ")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} diff --git a/src/runner.c b/src/runner.c index 85e9495..fa361d5 100644 --- a/src/runner.c +++ b/src/runner.c @@ -59,7 +59,7 @@ int check_flag(char *arg, char *alpha) { int run(FILE *alpha) { int token; - curr = CreateScope(NULL, 1, 1); + cur = CreateScope(NULL, 1, 1); // If file is not found if (alpha == NULL) { @@ -108,7 +108,7 @@ int run(FILE *alpha) { yyparse(); FILE *f = fdopen(1, "w"); - print_symbol_table(getAncestor(curr), f); + print_symbol_table(getAncestor(cur), f); fclose(f); if (yyin != NULL) { @@ -179,12 +179,12 @@ int is_alpha_file(char *alpha, int file_len) { } void enter_scope(int line, int column) { - curr = CreateScope(curr, line, column); + cur = CreateScope(cur, line, column); } void exit_scope() { - if (curr->Parent_Scope == NULL) { + if (cur->Parent_Scope == NULL) { printf("Can't close top"); return; } - curr = curr->Parent_Scope; + cur = cur->Parent_Scope; } diff --git a/src/runner.h b/src/runner.h index daff88c..9f66407 100644 --- a/src/runner.h +++ b/src/runner.h @@ -31,7 +31,7 @@ extern FILE *yyin; int arg; SymbolTable *top; -SymbolTable *curr; +SymbolTable *cur; // int main(int argc, char* argv[]); char *is_tok(int argc, char *argv[]); diff --git a/tests/sprint2/test/sp2_one_line.alpha b/tests/sprint2/test/sp2_one_line.alpha index 01f115e..9031b5f 100644 --- a/tests/sprint2/test/sp2_one_line.alpha +++ b/tests/sprint2/test/sp2_one_line.alpha @@ -1 +1 @@ -type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve(w); w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } +type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve w; w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } From f99dfc9b5454caac34c754eaec068c696f66669b Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Wed, 5 Mar 2025 15:31:01 -0500 Subject: [PATCH 24/31] Fixed some of the spacing and added a harder test t#36 --- src/grammar.y | 120 ++++++++++++++++---------------------------------- 1 file changed, 39 insertions(+), 81 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 3b5359f..d275f94 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,7 +1,3 @@ -/* Syntax Analyzer with Bison (3.8.1) */ -/* (referenced Bison manual for file boilerplate [3.1]) */ - -// Prologue %{ #include #include "../src/symbol_table.c" @@ -22,7 +18,7 @@ int integ; char * words; } -//precedence order + //need subtraction only here %type id_or_types %type types @@ -72,6 +68,8 @@ %token RESERVE 613 %token RELEASE 614 %token COMMENT 700 + +//precedence order %precedence RESERVE RELEASE %precedence DOT %precedence UMINUS @@ -84,120 +82,83 @@ %left OR %left ASSIGN - %% program: - prototype_or_definition_list; + prototype_or_definition_list + ; prototype_or_definition_list: - prototype prototype_or_definition_list + prototype prototype_or_definition_list | definition prototype_or_definition_list | prototype | definition ; + prototype: - L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; + L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; definition: TYPE ID COLON dblock | TYPE ID COLON constant ARROW ID - //| TYPE ID COLON types ARROW ID | function_declaration | TYPE ID COLON id_or_types ARROW id_or_types | ID parameter ASSIGN sblock ; + function_declaration: - FUNCTION { printf("found a function def\n"); }ID COLON ID - | EXTERNAL { printf("found an external function def\n"); }FUNCTION ID COLON ID + FUNCTION ID COLON ID + | EXTERNAL FUNCTION ID COLON ID ; parameter: - L_PAREN { printf("found a param def\n"); } ID R_PAREN - | AS{ printf("found a param_as_list def\n"); } L_PAREN idlist R_PAREN + L_PAREN ID R_PAREN + | AS L_PAREN idlist R_PAREN ; idlist: - ID COMMA idlist - |ID + ID COMMA idlist + | ID ; sblock: - L_BRACE {printf("open brace\n"); cur = CreateScope(cur,2,2);} statement_list {printf("close brace\n"); cur = getParent(cur);} R_BRACE - | L_BRACE {printf("open brace\n"); cur = CreateScope(cur,2,2);} dblock statement_list {printf("close brace\n"); cur = getParent(cur);} R_BRACE + L_BRACE {cur = CreateScope(cur,2,2);} statement_list {cur = getParent(cur);} R_BRACE + | L_BRACE {cur = CreateScope(cur,2,2);} dblock statement_list {cur = getParent(cur);} R_BRACE ; dblock: - L_BRACKET declaration_list R_BRACKET; + L_BRACKET declaration_list R_BRACKET; declaration_list: - declaration - {printf( - "found a decleration of form dec;dec_list\n"); - //CreateEntry(cur,cur_type,cur_value); - } - SEMI_COLON declaration_list + declaration SEMI_COLON declaration_list | declaration - {printf( - "found a decleration of form dec\n"); - //CreateEntry(cur,cur_type,cur_value); - } ; declaration: - id_or_types COLON ID { - - CreateEntry(cur,$1,$3); -// printf("declaration rule encountered"); -// if(cur_value != NULL){ -// char* delete1 = cur_value; -// printf("delete1 var assigned to cur_value"); -// free(delete1); -// printf("delete1 var freed"); -// } -// if(cur_type != NULL){ -// char* delete2 = cur_type; -// free(delete2);} -// int len = strlen($1); -// printf("length determined"); -// cur_value = malloc(len + 1); -// printf("space allocated"); -// strcpy(cur_value, $1); -// printf("string copied over"); - -// len = strlen($3); -// cur_type = malloc(len + 1); -// strcpy(cur_type, $3); -// printf("value var is %s type var is %s\n",cur_value,cur_type); - } -// | types COLON ID + id_or_types COLON ID {CreateEntry(cur,$1,$3); } ; + id_or_types: - ID + ID | types ; + statement_list: - compound_statement statement_list + compound_statement statement_list | compound_statement | simple_statement SEMI_COLON statement_list | simple_statement SEMI_COLON ; compound_statement: - WHILE {printf("found an while statment\n"); } L_PAREN expression R_PAREN sblock - | IF {printf("found an if statment\n"); }L_PAREN expression R_PAREN THEN sblock ELSE sblock + WHILE L_PAREN expression R_PAREN sblock + | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock | sblock ; -// Ref Compilers Principles, Techniques, & Tools - - - - simple_statement: - assignable ASSIGN {printf("found an assignment statment\n"); } expression -// I think that we need to add memOp stuff here | assignable ASSIGN expression {printf("found an assignment statment\n"); } - | RETURN {printf("found an return statment\n"); } expression + assignable ASSIGN expression + | RETURN expression ; assignable: @@ -207,7 +168,7 @@ assignable: ; rec_op : - DOT + DOT expression: constant @@ -223,31 +184,28 @@ expression: | expression LESS_THAN expression | expression EQUAL_TO expression | assignable - //| constant binaryOperator expression - //| ID binaryOperator expression | L_PAREN expression R_PAREN | memOp assignable ; - - ablock: - L_PAREN argument_list R_PAREN; + L_PAREN argument_list R_PAREN + ; argument_list: - expression COMMA argument_list + expression COMMA argument_list | expression ; memOp: - RESERVE + RESERVE | RELEASE ; constant: - C_STRING + C_STRING | C_INTEGER | C_NULL | C_CHARACTER @@ -256,19 +214,19 @@ constant: ; types: - T_STRING + T_STRING | T_INTEGER | T_ADDRESS | T_CHARACTER | T_BOOLEAN ; -// + %% void yyerror(const char *err) { fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); } -/* +/* int main(int argc, char * argv[]) { token_tracker = 1; cur=CreateScope(NULL,1,1); @@ -283,13 +241,13 @@ int main(int argc, char * argv[]) { } yyparse(); //while ((a = yyparse() != EOF){ - // token_tracker++; + // token_tracker++; //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); //if(yytext[0] == '\n'){ FILE* f = fdopen(1,"w"); print_symbol_table(getAncestor(cur),f); fclose(f); - // break; + // break; //} //} return 0; From 6fdccb3d8e0405a1bc4556963d2068ee7950ac37 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Wed, 5 Mar 2025 16:49:45 -0500 Subject: [PATCH 25/31] fixed the spaceing t#34 --- src/grammar.y | 5 +- src/lexicalStructure.lex | 2 + src/runner.c | 294 ++++++++++++++-------------- tests/sprint2/test/sp2_llnode.alpha | 74 +++++++ 4 files changed, 226 insertions(+), 149 deletions(-) create mode 100644 tests/sprint2/test/sp2_llnode.alpha diff --git a/src/grammar.y b/src/grammar.y index d275f94..921a666 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -4,6 +4,7 @@ extern int yylex(void); void yyerror(const char *err); extern char* yytext; + extern int yyleng; extern int yychar; extern SymbolTable * cur; //char* cur_value; @@ -122,8 +123,8 @@ idlist: ; sblock: - L_BRACE {cur = CreateScope(cur,2,2);} statement_list {cur = getParent(cur);} R_BRACE - | L_BRACE {cur = CreateScope(cur,2,2);} dblock statement_list {cur = getParent(cur);} R_BRACE + L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} statement_list {cur = getParent(cur);} R_BRACE + | L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} dblock statement_list {cur = getParent(cur);} R_BRACE ; dblock: diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index c2db6b5..98a70d2 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -7,9 +7,11 @@ %{ #include #include "../tmp/grammar.tab.h" + #include "../src/symbol_table.h" #ifndef DEBUG #define DEBUG 0 #endif + extern SymbolTable * cur; int line_number = 1, column_number = 1; %} diff --git a/src/runner.c b/src/runner.c index fa361d5..2132f65 100644 --- a/src/runner.c +++ b/src/runner.c @@ -4,187 +4,187 @@ #include "runner.h" int main(int argc, char *argv[]) { - if (argc == 1) { - fprintf(stderr, INVALID); - return -1; - } - - else if (argc == 2) { - if (is_help(argv[1])) { - return 0; - } else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) { - no_flag = SET_FLAG; - alpha_file = fopen(argv[1], "r"); - } else { - fprintf(stderr, INVALID); - return -1; - } - } - - else { - if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) { - fprintf(stderr, INVALID); - return -1; - } else { - for (int i = 1; i < argc - 1; i++) { - if (check_flag(argv[i], argv[argc - 1]) != 0) { - fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n"); - return -1; + if (argc == 1) { + fprintf(stderr, INVALID); + return -1; } - } - alpha_file = fopen(argv[argc - 1], "r"); - } - } - return run(alpha_file); + + else if (argc == 2) { + if (is_help(argv[1])) { + return 0; + } else if (is_alpha_file(argv[1], strlen(argv[1])) == 0) { + no_flag = SET_FLAG; + alpha_file = fopen(argv[1], "r"); + } else { + fprintf(stderr, INVALID); + return -1; + } + } + + else { + if (is_alpha_file(argv[argc - 1], strlen(argv[argc - 1])) != 0) { + fprintf(stderr, INVALID); + return -1; + } else { + for (int i = 1; i < argc - 1; i++) { + if (check_flag(argv[i], argv[argc - 1]) != 0) { + fprintf(stderr, "INVALID FLAG(S): Use -help to view valid inputs \n"); + return -1; + } + } + alpha_file = fopen(argv[argc - 1], "r"); + } + } + return run(alpha_file); } int check_flag(char *arg, char *alpha) { - if (strcmp("-tok", arg) == 0) { - if (tok_flag == NULL) { - return new_file(arg, alpha); - } - fprintf(stderr, "FLAGS REPEAT\n"); - return -1; - } else if (strcmp("-st", arg) == 0) { - if (st_flag == NULL) { - return new_file(arg, alpha); - } - fprintf(stderr, "FLAGS REPEAT\n"); - return -1; - } else { - fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n"); - return -1; - } + if (strcmp("-tok", arg) == 0) { + if (tok_flag == NULL) { + return new_file(arg, alpha); + } + fprintf(stderr, "FLAGS REPEAT\n"); + return -1; + } else if (strcmp("-st", arg) == 0) { + if (st_flag == NULL) { + return new_file(arg, alpha); + } + fprintf(stderr, "FLAGS REPEAT\n"); + return -1; + } else { + fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n"); + return -1; + } } int run(FILE *alpha) { - int token; - cur = CreateScope(NULL, 1, 1); + int token; + cur = CreateScope(NULL, 1, 1); - // If file is not found - if (alpha == NULL) { - fprintf(stderr, "INPUT FILE NOT FOUND\n"); - return -1; - } - yyin = alpha; - - // TOK FLAG - if (tok_flag != NULL) { - while (0 != (token = yylex())) { - if (tok_flag != NULL) { - fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, - token, yytext); - } - if (token == COMMENT) { - for (int i = 0; i < yyleng; i++) { - if (yytext[i] == '\n') { - line_number++; - column_number = 0; - } - column_number++; + // If file is not found + if (alpha == NULL) { + fprintf(stderr, "INPUT FILE NOT FOUND\n"); + return -1; } - continue; - } - if (token == 1999) { - printf( - "On line number %d and column number %d we have an invalid " - "character:%s\n", - line_number, column_number, yytext); - } - column_number += yyleng; - } - fclose(tok_flag); + yyin = alpha; - if (yyin != NULL) { - fclose(yyin); - } - return 0; - } + // TOK FLAG + if (tok_flag != NULL) { + while (0 != (token = yylex())) { + if (tok_flag != NULL) { + fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, + token, yytext); + } + if (token == COMMENT) { + for (int i = 0; i < yyleng; i++) { + if (yytext[i] == '\n') { + line_number++; + column_number = 0; + } + column_number++; + } + continue; + } + if (token == 1999) { + printf( + "On line number %d and column number %d we have an invalid " + "character:%s\n", + line_number, column_number, yytext); + } + column_number += yyleng; + } + fclose(tok_flag); - if (st_flag != NULL) { - // output symbol table, file pointer is - // print_symbol_table(top,st_flag); - } + if (yyin != NULL) { + fclose(yyin); + } + return 0; + } - yyparse(); - FILE *f = fdopen(1, "w"); - print_symbol_table(getAncestor(cur), f); - fclose(f); + if (st_flag != NULL) { + // output symbol table, file pointer is + // print_symbol_table(top,st_flag); + } - if (yyin != NULL) { - fclose(yyin); - } + yyparse(); + FILE *f = fdopen(1, "w"); + print_symbol_table(getAncestor(cur), f); + fclose(f); - return 0; + if (yyin != NULL) { + fclose(yyin); + } + + return 0; } bool is_help(char *input) { - if (strcmp(input, "-help") == 0) { - printf("%s", HELP); - return true; - } + if (strcmp(input, "-help") == 0) { + printf("%s", HELP); + return true; + } - return false; + return false; } int new_file(char *arg, char *alpha) { - int type_len; - const char *basename = alpha; - const char *slash = strchr(alpha, '/'); + int type_len; + const char *basename = alpha; + const char *slash = strchr(alpha, '/'); - while (slash != NULL) { - basename = slash + 1; - slash = strchr(basename, '/'); - } + while (slash != NULL) { + basename = slash + 1; + slash = strchr(basename, '/'); + } - mkdir("./out", 0777); + mkdir("./out", 0777); - char *new_basename = calloc(strlen(basename) + 5, sizeof(char)); - strcpy(new_basename, "./out/"); - strcat(new_basename, basename); - basename = new_basename; + char *new_basename = calloc(strlen(basename) + 5, sizeof(char)); + strcpy(new_basename, "./out/"); + strcat(new_basename, basename); + basename = new_basename; - if (strcmp(arg, "-tok") == 0) { - type_len = TOK_LEN; - } else if (strcmp(arg, "-st") == 0) { - type_len = ST_LEN; - } else { - fprintf(stderr, "INVALID FLAG: Use -help to view valid inputs\n"); - return -1; - } + if (strcmp(arg, "-tok") == 0) { + type_len = TOK_LEN; + } else if (strcmp(arg, "-st") == 0) { + type_len = ST_LEN; + } else { + fprintf(stderr, "INVALID FLAG: Use -help to view valid inputs\n"); + return -1; + } - // calculate lengths - int basename_len = strlen(basename); - char *file_name = - calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char)); + // calculate lengths + int basename_len = strlen(basename); + char *file_name = + calloc(basename_len - ALPHA_OFFSET + type_len + 2, sizeof(char)); - // coy filename and add extension - strncpy(file_name, basename, basename_len - ALPHA_OFFSET); - strcat(file_name, "."); - strcat(file_name, arg + 1); + // coy filename and add extension + strncpy(file_name, basename, basename_len - ALPHA_OFFSET); + strcat(file_name, "."); + strcat(file_name, arg + 1); - if (strcmp(arg, "-tok") == 0) { - tok_flag = fopen(file_name, "w"); - } else if (strcmp(arg, "-st") == 0) { - st_flag = fopen(file_name, "w"); - } - return 0; + if (strcmp(arg, "-tok") == 0) { + tok_flag = fopen(file_name, "w"); + } else if (strcmp(arg, "-st") == 0) { + st_flag = fopen(file_name, "w"); + } + return 0; } int is_alpha_file(char *alpha, int file_len) { - if (strcmp(".alpha", alpha + sizeof(char) * (file_len - ALPHA_OFFSET)) != 0) { - return -1; // not alpha file - } - return 0; // is alpha file + if (strcmp(".alpha", alpha + sizeof(char) * (file_len - ALPHA_OFFSET)) != 0) { + return -1; // not alpha file + } + return 0; // is alpha file } void enter_scope(int line, int column) { - cur = CreateScope(cur, line, column); + cur = CreateScope(cur, line, column); } void exit_scope() { - if (cur->Parent_Scope == NULL) { - printf("Can't close top"); - return; - } - cur = cur->Parent_Scope; + if (cur->Parent_Scope == NULL) { + printf("Can't close top"); + return; + } + cur = cur->Parent_Scope; } diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha new file mode 100644 index 0000000..880ca0b --- /dev/null +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -0,0 +1,74 @@ +type rec: [integer: x; integer: y] +type T1: integer -> integer +type T2: rec -> integer + +type llnode: [address: prev; integer: val; address: next] +type list: integer -> llnode + +function foo : T1 +function bar1 : T2 +function bar2 : T2 +function make_list : list +make_list(a) := { + [integer:orig_a; address: ret; address: curr; address: temp] + if (a < 0 | a = 0) then { + return null; + } else { + ret := reserve llnode; + ret.prev := null; + ret.next := null; + ret.val := a; + while (0 < a) { + temp := reserve llnode; + temp.prev := null; + temp.next := null; + temp.val := val; + if (a = orig_a) then { + ret.next := temp; + temp.prev := ret; + curr := temp; + } else { + curr.next := temp; + temp.prev := curr; + curr := temp; + } + a := a - 1; + } + return ret; + } +} + + +foo(x) := { + return x * x; + } +bar1(a) := { + return a.x * a.y; + } + +bar2 as (r,s) := { + if (r < s) then { + while (!(r < s)) { + r := r + 1; + } + } else { + [integer: x] + x := 0; + while (x < 10) { + r := r + s; + } + } + return r * s; + } +entry(arg) := { + [ integer: result ; rec: w; llnode: li] + li := make_list(6); + result := foo(5); + w := reserve w; + w.x := 5; + w.y := 7; + result := bar1(w); + result := bar2(5,7); + + return 0; +} From 211919d70ec1ac7416be8db7af92eb70d7a81288 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Thu, 6 Mar 2025 02:05:47 -0500 Subject: [PATCH 26/31] fixed location issues for error messages and scoping. Used location macros and the percent location as defined in guides to track location. Code may warrant cleanup as we don't need to manually keep track of locations ourselves any more through our line and column number variables --- src/grammar.y | 9 +- src/grammar.y.save | 255 ++++++++++++++++++++++++++++++++ src/lexicalStructure.lex | 110 +++++++------- src/lexicalStructure.lex.save | 91 ++++++++++++ src/lexicalStructure.lex.save.1 | 91 ++++++++++++ src/runner.c | 28 +++- 6 files changed, 524 insertions(+), 60 deletions(-) create mode 100644 src/grammar.y.save create mode 100644 src/lexicalStructure.lex.save create mode 100644 src/lexicalStructure.lex.save.1 diff --git a/src/grammar.y b/src/grammar.y index 921a666..3732fc1 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -14,7 +14,8 @@ extern int column_number; extern FILE * yyin; %} - +//%define api.location.type {location_t} +%locations %union { int integ; char * words; @@ -123,8 +124,8 @@ idlist: ; sblock: - L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} statement_list {cur = getParent(cur);} R_BRACE - | L_BRACE {column_number += yyleng; cur = CreateScope(cur,line_number,column_number);} dblock statement_list {cur = getParent(cur);} R_BRACE + L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE + | L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock statement_list {cur = getParent(cur);} R_BRACE ; dblock: @@ -225,7 +226,7 @@ types: %% void yyerror(const char *err) { - fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); + fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,yylloc.first_line,yylloc.first_column); } /* int main(int argc, char * argv[]) { diff --git a/src/grammar.y.save b/src/grammar.y.save new file mode 100644 index 0000000..df5d589 --- /dev/null +++ b/src/grammar.y.save @@ -0,0 +1,255 @@ +%{ + #include + #include "../src/symbol_table.c" + extern int yylex(void); + void yyerror(const char *err); + extern char* yytext; + extern int yychar; + extern SymbolTable * cur; + //char* cur_value; + //char* cur_type; + int token_tracker; + extern int line_number; + extern int column_number; + extern FILE * yyin; +%} + +%union { + int integ; + char * words; +} + +//need subtraction only here +%type id_or_types +%type types +%token ID 101 +%token T_INTEGER 201 +%token T_ADDRESS 202 +%token T_BOOLEAN 203 +%token T_CHARACTER 204 +%token T_STRING 205 +%token C_INTEGER 301 +%token C_NULL 302 +%token C_CHARACTER 303 +%token C_STRING 304 +%token C_TRUE 305 +%token C_FALSE 306 +%token WHILE 401 +%token IF 402 +%token THEN 403 +%token ELSE 404 +%token TYPE 405 +%token FUNCTION 406 +%token RETURN 407 +%token EXTERNAL 408 +%token AS 409 +%token L_PAREN 501 +%token R_PAREN 502 +%token L_BRACKET 503 +%token R_BRACKET 504 +%token L_BRACE 505 +%token R_BRACE 506 +%token SEMI_COLON 507 +%token COLON 508 +%token COMMA 509 +%token ARROW 510 +%token MUL 603 +%token DIV 604 +%token REM 605 +%token ADD 601 +%token LESS_THAN 606 +%token EQUAL_TO 607 +%token AND 610 +%token OR 611 +%token ASSIGN 608 +%token SUB_OR_NEG 602 +%token NOT 609 +%token DOT 612 +%token RESERVE 613 +%token RELEASE 614 +%token COMMENT 700 + +//precedence order +%precedence RESERVE RELEASE +%precedence DOT +%precedence UMINUS +%precedence NOT +%left MUL DIV REM +%left ADD SUB_OR_NEG +%left LESS_THAN +%left EQUAL_TO +%left AND +%left OR +%left ASSIGN + +%% + +program: + prototype_or_definition_list + ; + +prototype_or_definition_list: + prototype prototype_or_definition_list + | definition prototype_or_definition_list + | prototype + | definition + ; + +prototype: + L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; + +definition: + TYPE ID COLON dblock + | TYPE ID COLON constant ARROW ID + | function_declaration + | TYPE ID COLON id_or_types ARROW id_or_types + | ID parameter ASSIGN sblock + ; + +function_declaration: + FUNCTION ID COLON ID + | EXTERNAL FUNCTION ID COLON ID + ; + +parameter: + L_PAREN ID R_PAREN + | AS L_PAREN idlist R_PAREN + ; + +idlist: + ID COMMA idlist + | ID + ; + +sblock: + L_BRACE {cur = CreateScope(cur,2,2);} statement_list {cur = getParent(cur);} R_BRACE + | L_BRACE {cur = CreateScope(cur,2,2);} dblock statement_list {cur = getParent(cur);} R_BRACE + ; + +dblock: + L_BRACKET declaration_list R_BRACKET; + +declaration_list: + declaration SEMI_COLON declaration_list + | declaration + ; + + +declaration: + id_or_types COLON ID {CreateEntry(cur,$1,$3); } + ; + +id_or_types: + ID + | types + ; + +statement_list: + compound_statement statement_list + | compound_statement + | simple_statement SEMI_COLON statement_list + | simple_statement SEMI_COLON + ; + +compound_statement: + WHILE L_PAREN expression R_PAREN sblock + | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock + | sblock + ; + +simple_statement: + assignable ASSIGN expression + | RETURN expression + ; + +assignable: + ID + | assignable ablock + | assignable rec_op ID + ; + +rec_op : + DOT + +expression: + constant + | SUB_OR_NEG expression %prec UMINUS + | NOT expression + | expression ADD expression + | expression SUB_OR_NEG expression + | expression MUL expression + | expression DIV expression + | expression REM expression + | expression AND expression + | expression OR expression + | expression LESS_THAN expression + | expression EQUAL_TO expression + | assignable + | L_PAREN expression R_PAREN + | memOp assignable + ; + +ablock: + L_PAREN argument_list R_PAREN + ; + +argument_list: + expression COMMA argument_list + | expression + ; + + +memOp: + RESERVE + | RELEASE + ; + + +constant: + C_STRING + | C_INTEGER + | C_NULL + | C_CHARACTER + | C_TRUE + | C_FALSE + ; + +types: + T_STRING + | T_INTEGER + | T_ADDRESS + | T_CHARACTER + | T_BOOLEAN + ; + +%% + +void yyerror(const char *err) { + fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); +} +/* +int main(int argc, char * argv[]) { + token_tracker = 1; + cur=CreateScope(NULL,1,1); + //int a; + FILE * fp; + if(argc > 1){ + fp = fopen(argv[1], "r"); + yyin = fp; + } else { + fp = stdin; + yyin = fp; + } + yyparse(); + //while ((a = yyparse() != EOF){ + // token_tracker++; + //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); + //if(yytext[0] == '\n'){ + FILE* f = fdopen(1,"w"); + print_symbol_table(getAncestor(cur),f); + fclose(f); + // break; + //} + //} + return 0; +} */ diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 98a70d2..aae5433 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -3,7 +3,7 @@ %option noyywrap %option header-file="flex.h" - +%option yylineno %{ #include #include "../tmp/grammar.tab.h" @@ -12,8 +12,18 @@ #define DEBUG 0 #endif extern SymbolTable * cur; + extern FILE* tok_flag; + extern void incr(int lnum,int cnum, int tok); + extern void print_tok(int tok); int line_number = 1, column_number = 1; + int yycolumn = 1; + #define YY_USER_ACTION { \ + yylloc.first_line = yylineno; \ + yylloc.last_line = yylineno; \ + yylloc.first_column = yycolumn; \ + yylloc.last_column = yycolumn + yyleng - 1; \ + yycolumn += yyleng; } %} STARCOM [^\*]|\*+[^\)\*]+ @@ -26,63 +36,63 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] %% -"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} -"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} -"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} -"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} +"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {if(tok_flag != NULL){print_tok(T_INTEGER);}incr(line_number,column_number,T_INTEGER);return T_INTEGER;}} +"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {if(tok_flag != NULL){print_tok(T_ADDRESS);}incr(line_number,column_number,T_ADDRESS);return T_ADDRESS;}} +"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {if(tok_flag != NULL){print_tok(T_INTEGER);}incr(line_number,column_number,T_INTEGER);return T_BOOLEAN;}} +"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {if(tok_flag != NULL){print_tok(T_CHARACTER);}incr(line_number,column_number,T_CHARACTER);return T_CHARACTER;}} -"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} -"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} -"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} -"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} -"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} -"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} -"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} -"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} -"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} +"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {if(tok_flag != NULL){print_tok(WHILE);}incr(line_number,column_number,WHILE);return WHILE;}} +"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {if(tok_flag != NULL){print_tok(IF);}incr(line_number,column_number,IF);return IF;}} +"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {if(tok_flag != NULL){print_tok(THEN);}incr(line_number,column_number,THEN);return THEN;}} +"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {if(tok_flag != NULL){print_tok(ELSE);}incr(line_number,column_number,ELSE);return ELSE;}} +"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {if(tok_flag != NULL){print_tok(TYPE);}incr(line_number,column_number,TYPE);return TYPE;}} +"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {if(tok_flag != NULL){print_tok(FUNCTION);}incr(line_number,column_number,FUNCTION);return FUNCTION;}} +"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {if(tok_flag != NULL){print_tok(RETURN);}incr(line_number,column_number,RETURN);return RETURN;}} +"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {if(tok_flag != NULL){print_tok(EXTERNAL);}incr(line_number,column_number,EXTERNAL);return EXTERNAL;}} +"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {if(tok_flag != NULL){print_tok(AS);}incr(line_number,column_number,AS);return AS;}} -"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} -"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} +"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {if(tok_flag != NULL){print_tok(RELEASE);}incr(line_number,column_number,RELEASE);return RELEASE;}} +"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {if(tok_flag != NULL){print_tok(RESERVE);}incr(line_number,column_number,RESERVE);return RESERVE;}} -"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} -"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} -"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} -"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} -"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} -"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} -"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} -":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} -"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} -"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} -"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} -"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} +"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {if(tok_flag != NULL){print_tok(ADD);}incr(line_number,column_number,ADD);return ADD;}} +"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {if(tok_flag != NULL){print_tok(SUB_OR_NEG);}incr(line_number,column_number,SUB_OR_NEG);return SUB_OR_NEG;}} +"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {if(tok_flag != NULL){print_tok(MUL);}incr(line_number,column_number,MUL);return MUL;}} +"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {if(tok_flag != NULL){print_tok(DIV);}incr(line_number,column_number,DIV);return DIV;}} +"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {if(tok_flag != NULL){print_tok(REM);}incr(line_number,column_number,REM);return REM;}} +"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {if(tok_flag != NULL){print_tok(LESS_THAN);}incr(line_number,column_number,LESS_THAN);return LESS_THAN;}} +"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {if(tok_flag != NULL){print_tok(EQUAL_TO);}incr(line_number,column_number,EQUAL_TO);return EQUAL_TO;}} +":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {if(tok_flag != NULL){print_tok(ASSIGN);}incr(line_number,column_number,ASSIGN);return ASSIGN;}} +"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {if(tok_flag != NULL){print_tok(NOT);}incr(line_number,column_number,NOT);return NOT;}} +"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {if(tok_flag != NULL){print_tok(AND);}incr(line_number,column_number,AND);return AND;}} +"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {if(tok_flag != NULL){print_tok(OR);}incr(line_number,column_number,OR);return OR;}} +"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {if(tok_flag != NULL){print_tok(DOT);}incr(line_number,column_number,DOT);return DOT;}} -";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} -":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} -"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} -"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} +";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {if(tok_flag != NULL){print_tok(SEMI_COLON);}incr(line_number,column_number,SEMI_COLON);return SEMI_COLON;}} +":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {if(tok_flag != NULL){print_tok(COLON);}incr(line_number,column_number,COLON);return COLON;}} +"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}} +"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}} -{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} -'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} -\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} -{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} +{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);return C_INTEGER;}} +'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);return C_CHARACTER;}} +\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);return C_STRING;}} +{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}} -"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} -")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} -"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} -"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} -"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} -"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} +"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {if(tok_flag != NULL){print_tok(L_PAREN);}incr(line_number,column_number,L_PAREN);return L_PAREN;}} +")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {if(tok_flag != NULL){print_tok(R_PAREN);}incr(line_number,column_number,R_PAREN);return R_PAREN;}} +"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {if(tok_flag != NULL){print_tok(L_BRACKET);}incr(line_number,column_number,L_BRACKET);return L_BRACKET;}} +"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {if(tok_flag != NULL){print_tok(R_BRACKET);}incr(line_number,column_number,R_BRACKET);return R_BRACKET;}} +"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {if(tok_flag != NULL){print_tok(L_BRACE);}incr(line_number,column_number,L_BRACE);return L_BRACE;}} +"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {if(tok_flag != NULL){print_tok(R_BRACE);}incr(line_number,column_number,R_BRACE);return R_BRACE;}} -"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} -"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} -"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} +"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {if(tok_flag != NULL){print_tok(C_TRUE);}incr(line_number,column_number,C_TRUE);return C_TRUE;}} +"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {if(tok_flag != NULL){print_tok(C_FALSE);}incr(line_number,column_number,C_FALSE);return C_FALSE;}} +"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {if(tok_flag != NULL){print_tok(C_NULL);}incr(line_number,column_number,C_NULL);return C_NULL;}} -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {if(tok_flag != NULL){print_tok(ID);}incr(line_number,column_number,ID);yylval.words = strdup(yytext); return ID;}} -\n {line_number++; column_number = 1;} -\t {column_number++;} -" " {column_number++;} -. {column_number++; return 1999;} +\n {yycolumn=1;incr(line_number,column_number,0);} +\t {incr(line_number,column_number,0);} +" " {incr(line_number,column_number,0);} +. {incr(line_number,column_number,0);} %% diff --git a/src/lexicalStructure.lex.save b/src/lexicalStructure.lex.save new file mode 100644 index 0000000..c2ce8c9 --- /dev/null +++ b/src/lexicalStructure.lex.save @@ -0,0 +1,91 @@ +/* Lexical Analyzer with Flex (1.6.0) */ +/* The Translators - Spring 2025 */ + +%option noyywrap +%option header-file="flex.h" + +%{ + #include + #include "../tmp/grammar.tab.h" + #include "../src/symbol_table.h" + #ifndef DEBUG + #define DEBUG 0 + #endif + extern SymbolTable * cur; + extern int tok_flag; + extern void incr(int lnum,int cnum, int tok); + extern void print_tok(int tok); + + int line_number = 1, column_number = 1; +%} + +STARCOM [^\*]|\*+[^\)\*]+ +PARENCOM [^\)]|[^\*\)]+\)+ +COMMENT \(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) +ID [A-Za-z_][0-9A-Za-z_]* +DIGIT [0-9] +CHAR \\n|\\t|\\'|[^'\n\t\\]|\\\\ +SCHAR \\n|\\t|\\\"|[^\"\n\\] + +%% + +"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {if(tok_flag != NULL){print_tok(T_INTEGER);}incr(line_number,column_number,T_INTEGER);return T_INTEGER;}} +"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} +"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} +"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} + +"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} +"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} +"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} +"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} +"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} +"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} +"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} +"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} +"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} + +"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} +"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} + +"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} +"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} +"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} +"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} +"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} +"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} +"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} +":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} +"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} +"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} +"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} +"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} + +";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} +":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} +"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} +"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} + +{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} +'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} +\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} +{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} + +"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} +")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} +"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} +"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} +"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} +"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} + +"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} +"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} +"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} + +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} + +\n {line_number++; column_number = 1;} +\t {column_number++;} +" " {column_number++;} +. {column_number++; return 1999;} + +%% diff --git a/src/lexicalStructure.lex.save.1 b/src/lexicalStructure.lex.save.1 new file mode 100644 index 0000000..e0d5cc3 --- /dev/null +++ b/src/lexicalStructure.lex.save.1 @@ -0,0 +1,91 @@ +/* Lexical Analyzer with Flex (1.6.0) */ +/* The Translators - Spring 2025 */ + +%option noyywrap +%option header-file="flex.h" + +%{ + #include + #include "../tmp/grammar.tab.h" + #include "../src/symbol_table.h" + #ifndef DEBUG + #define DEBUG 0 + #endif + extern SymbolTable * cur; + extern int tok_flag; + extern void incr(int lnum,int cnum, int tok); + extern void print_tok(int tok); + + int line_number = 1, column_number = 1; +%} + +STARCOM [^\*]|\*+[^\)\*]+ +PARENCOM [^\)]|[^\*\)]+\)+ +COMMENT \(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) +ID [A-Za-z_][0-9A-Za-z_]* +DIGIT [0-9] +CHAR \\n|\\t|\\'|[^'\n\t\\]|\\\\ +SCHAR \\n|\\t|\\\"|[^\"\n\\] + +%% + +"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} +"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} +"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} +"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} + +"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} +"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} +"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} +"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} +"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} +"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} +"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} +"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} +"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} + +"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} +"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} + +"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} +"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} +"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} +"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} +"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} +"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} +"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} +":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} +"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} +"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} +"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} +"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} + +";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} +":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} +"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} +"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} + +{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} +'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} +\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} +{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} + +"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} +")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} +"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} +"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} +"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} +"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} + +"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} +"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} +"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} + +{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} + +\n {line_number++; column_number = 1;} +\t {column_number++;} +" " {column_number++;} +. {column_number++; return 1999;} + +%% diff --git a/src/runner.c b/src/runner.c index 2132f65..d6327ef 100644 --- a/src/runner.c +++ b/src/runner.c @@ -57,6 +57,22 @@ int check_flag(char *arg, char *alpha) { } } +void incr(int lnum,int cnum, int tok){ + //if (tok == COMMENT) { + for (int i = 0; i < yyleng; i++) { + if (yytext[i] == '\n') { + line_number++; + column_number = 0; + } + column_number++; + } +// }else{ +// column_number += yyleng; +// } +} +void print_tok(int tok){ +fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number,tok, yytext); +} int run(FILE *alpha) { int token; cur = CreateScope(NULL, 1, 1); @@ -71,11 +87,11 @@ int run(FILE *alpha) { // TOK FLAG if (tok_flag != NULL) { while (0 != (token = yylex())) { - if (tok_flag != NULL) { - fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, - token, yytext); - } - if (token == COMMENT) { + //if (tok_flag != NULL) { + // fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, + // token, yytext); + //} + /*if (token == COMMENT) { for (int i = 0; i < yyleng; i++) { if (yytext[i] == '\n') { line_number++; @@ -91,7 +107,7 @@ int run(FILE *alpha) { "character:%s\n", line_number, column_number, yytext); } - column_number += yyleng; + column_number += yyleng; */ } fclose(tok_flag); From 9eee3d94ba3458c0ef99003828d5d9a16907f354 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Thu, 6 Mar 2025 21:31:55 -0500 Subject: [PATCH 27/31] cleanup (removed .saves) --- .gitignore | 3 +- src/grammar.y | 3 + src/grammar.y.save | 255 -------------------------------- src/lexicalStructure.lex.save | 91 ------------ src/lexicalStructure.lex.save.1 | 91 ------------ src/symbol_table.c | 3 + 6 files changed, 8 insertions(+), 438 deletions(-) delete mode 100644 src/grammar.y.save delete mode 100644 src/lexicalStructure.lex.save delete mode 100644 src/lexicalStructure.lex.save.1 diff --git a/.gitignore b/.gitignore index 8cf77d3..a6fca1a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ grammar.tab.h .vscode out tmp -parser \ No newline at end of file +parser +*.save \ No newline at end of file diff --git a/src/grammar.y b/src/grammar.y index 3732fc1..350b568 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,3 +1,6 @@ +/* Syntax Analyzer with Bison (3.8.2) */ +/* The Translators - Spring 2025 */ + %{ #include #include "../src/symbol_table.c" diff --git a/src/grammar.y.save b/src/grammar.y.save deleted file mode 100644 index df5d589..0000000 --- a/src/grammar.y.save +++ /dev/null @@ -1,255 +0,0 @@ -%{ - #include - #include "../src/symbol_table.c" - extern int yylex(void); - void yyerror(const char *err); - extern char* yytext; - extern int yychar; - extern SymbolTable * cur; - //char* cur_value; - //char* cur_type; - int token_tracker; - extern int line_number; - extern int column_number; - extern FILE * yyin; -%} - -%union { - int integ; - char * words; -} - -//need subtraction only here -%type id_or_types -%type types -%token ID 101 -%token T_INTEGER 201 -%token T_ADDRESS 202 -%token T_BOOLEAN 203 -%token T_CHARACTER 204 -%token T_STRING 205 -%token C_INTEGER 301 -%token C_NULL 302 -%token C_CHARACTER 303 -%token C_STRING 304 -%token C_TRUE 305 -%token C_FALSE 306 -%token WHILE 401 -%token IF 402 -%token THEN 403 -%token ELSE 404 -%token TYPE 405 -%token FUNCTION 406 -%token RETURN 407 -%token EXTERNAL 408 -%token AS 409 -%token L_PAREN 501 -%token R_PAREN 502 -%token L_BRACKET 503 -%token R_BRACKET 504 -%token L_BRACE 505 -%token R_BRACE 506 -%token SEMI_COLON 507 -%token COLON 508 -%token COMMA 509 -%token ARROW 510 -%token MUL 603 -%token DIV 604 -%token REM 605 -%token ADD 601 -%token LESS_THAN 606 -%token EQUAL_TO 607 -%token AND 610 -%token OR 611 -%token ASSIGN 608 -%token SUB_OR_NEG 602 -%token NOT 609 -%token DOT 612 -%token RESERVE 613 -%token RELEASE 614 -%token COMMENT 700 - -//precedence order -%precedence RESERVE RELEASE -%precedence DOT -%precedence UMINUS -%precedence NOT -%left MUL DIV REM -%left ADD SUB_OR_NEG -%left LESS_THAN -%left EQUAL_TO -%left AND -%left OR -%left ASSIGN - -%% - -program: - prototype_or_definition_list - ; - -prototype_or_definition_list: - prototype prototype_or_definition_list - | definition prototype_or_definition_list - | prototype - | definition - ; - -prototype: - L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; - -definition: - TYPE ID COLON dblock - | TYPE ID COLON constant ARROW ID - | function_declaration - | TYPE ID COLON id_or_types ARROW id_or_types - | ID parameter ASSIGN sblock - ; - -function_declaration: - FUNCTION ID COLON ID - | EXTERNAL FUNCTION ID COLON ID - ; - -parameter: - L_PAREN ID R_PAREN - | AS L_PAREN idlist R_PAREN - ; - -idlist: - ID COMMA idlist - | ID - ; - -sblock: - L_BRACE {cur = CreateScope(cur,2,2);} statement_list {cur = getParent(cur);} R_BRACE - | L_BRACE {cur = CreateScope(cur,2,2);} dblock statement_list {cur = getParent(cur);} R_BRACE - ; - -dblock: - L_BRACKET declaration_list R_BRACKET; - -declaration_list: - declaration SEMI_COLON declaration_list - | declaration - ; - - -declaration: - id_or_types COLON ID {CreateEntry(cur,$1,$3); } - ; - -id_or_types: - ID - | types - ; - -statement_list: - compound_statement statement_list - | compound_statement - | simple_statement SEMI_COLON statement_list - | simple_statement SEMI_COLON - ; - -compound_statement: - WHILE L_PAREN expression R_PAREN sblock - | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock - | sblock - ; - -simple_statement: - assignable ASSIGN expression - | RETURN expression - ; - -assignable: - ID - | assignable ablock - | assignable rec_op ID - ; - -rec_op : - DOT - -expression: - constant - | SUB_OR_NEG expression %prec UMINUS - | NOT expression - | expression ADD expression - | expression SUB_OR_NEG expression - | expression MUL expression - | expression DIV expression - | expression REM expression - | expression AND expression - | expression OR expression - | expression LESS_THAN expression - | expression EQUAL_TO expression - | assignable - | L_PAREN expression R_PAREN - | memOp assignable - ; - -ablock: - L_PAREN argument_list R_PAREN - ; - -argument_list: - expression COMMA argument_list - | expression - ; - - -memOp: - RESERVE - | RELEASE - ; - - -constant: - C_STRING - | C_INTEGER - | C_NULL - | C_CHARACTER - | C_TRUE - | C_FALSE - ; - -types: - T_STRING - | T_INTEGER - | T_ADDRESS - | T_CHARACTER - | T_BOOLEAN - ; - -%% - -void yyerror(const char *err) { - fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,line_number,column_number); -} -/* -int main(int argc, char * argv[]) { - token_tracker = 1; - cur=CreateScope(NULL,1,1); - //int a; - FILE * fp; - if(argc > 1){ - fp = fopen(argv[1], "r"); - yyin = fp; - } else { - fp = stdin; - yyin = fp; - } - yyparse(); - //while ((a = yyparse() != EOF){ - // token_tracker++; - //printf("%d = a: yytext = %s: yychar = %d, token number: %d\n", a, yytext, yychar,token_tracker); - //if(yytext[0] == '\n'){ - FILE* f = fdopen(1,"w"); - print_symbol_table(getAncestor(cur),f); - fclose(f); - // break; - //} - //} - return 0; -} */ diff --git a/src/lexicalStructure.lex.save b/src/lexicalStructure.lex.save deleted file mode 100644 index c2ce8c9..0000000 --- a/src/lexicalStructure.lex.save +++ /dev/null @@ -1,91 +0,0 @@ -/* Lexical Analyzer with Flex (1.6.0) */ -/* The Translators - Spring 2025 */ - -%option noyywrap -%option header-file="flex.h" - -%{ - #include - #include "../tmp/grammar.tab.h" - #include "../src/symbol_table.h" - #ifndef DEBUG - #define DEBUG 0 - #endif - extern SymbolTable * cur; - extern int tok_flag; - extern void incr(int lnum,int cnum, int tok); - extern void print_tok(int tok); - - int line_number = 1, column_number = 1; -%} - -STARCOM [^\*]|\*+[^\)\*]+ -PARENCOM [^\)]|[^\*\)]+\)+ -COMMENT \(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) -ID [A-Za-z_][0-9A-Za-z_]* -DIGIT [0-9] -CHAR \\n|\\t|\\'|[^'\n\t\\]|\\\\ -SCHAR \\n|\\t|\\\"|[^\"\n\\] - -%% - -"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {if(tok_flag != NULL){print_tok(T_INTEGER);}incr(line_number,column_number,T_INTEGER);return T_INTEGER;}} -"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} -"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} -"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} - -"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} -"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} -"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} -"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} -"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} -"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} -"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} -"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} -"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} - -"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} -"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} - -"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} -"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} -"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} -"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} -"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} -"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} -"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} -":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} -"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} -"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} -"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} -"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} - -";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} -":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} -"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} -"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} - -{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} -'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} -\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} -{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} - -"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} -")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} -"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} -"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} -"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} -"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} - -"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} -"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} -"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} - -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} - -\n {line_number++; column_number = 1;} -\t {column_number++;} -" " {column_number++;} -. {column_number++; return 1999;} - -%% diff --git a/src/lexicalStructure.lex.save.1 b/src/lexicalStructure.lex.save.1 deleted file mode 100644 index e0d5cc3..0000000 --- a/src/lexicalStructure.lex.save.1 +++ /dev/null @@ -1,91 +0,0 @@ -/* Lexical Analyzer with Flex (1.6.0) */ -/* The Translators - Spring 2025 */ - -%option noyywrap -%option header-file="flex.h" - -%{ - #include - #include "../tmp/grammar.tab.h" - #include "../src/symbol_table.h" - #ifndef DEBUG - #define DEBUG 0 - #endif - extern SymbolTable * cur; - extern int tok_flag; - extern void incr(int lnum,int cnum, int tok); - extern void print_tok(int tok); - - int line_number = 1, column_number = 1; -%} - -STARCOM [^\*]|\*+[^\)\*]+ -PARENCOM [^\)]|[^\*\)]+\)+ -COMMENT \(\*{STARCOM}*\*\)|\(\*{PARENCOM}*\*\) -ID [A-Za-z_][0-9A-Za-z_]* -DIGIT [0-9] -CHAR \\n|\\t|\\'|[^'\n\t\\]|\\\\ -SCHAR \\n|\\t|\\\"|[^\"\n\\] - -%% - -"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}} -"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}} -"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}} -"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}} - -"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}} -"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}} -"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}} -"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}} -"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}} -"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}} -"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}} -"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}} -"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}} - -"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}} -"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}} - -"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}} -"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}} -"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}} -"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}} -"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}} -"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}} -"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}} -":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}} -"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}} -"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}} -"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}} -"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}} - -";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}} -":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}} -"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}} -"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}} - -{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}} -'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}} -\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}} -{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {/*return COMMENT;*/}} - -"(" {if(DEBUG) {printf( "L_PAREN: %s (%d)\n", yytext, L_PAREN);} else {return L_PAREN;}} -")" {if(DEBUG) {printf( "R_PAREN: %s (%d)\n", yytext, R_PAREN);} else {return R_PAREN;}} -"[" {if(DEBUG) {printf( "L_BRACKET: %s (%d)\n", yytext, L_BRACKET);} else {return L_BRACKET;}} -"]" {if(DEBUG) {printf( "R_BRACKET: %s (%d)\n", yytext, R_BRACKET);} else {return R_BRACKET;}} -"{" {if(DEBUG) {printf( "L_BRACE: %s (%d)\n", yytext, L_BRACE);} else {return L_BRACE;}} -"}" {if(DEBUG) {printf( "R_BRACE: %s (%d)\n", yytext, R_BRACE);} else {return R_BRACE;}} - -"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}} -"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}} -"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}} - -{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {yylval.words = strdup(yytext); return ID;}} - -\n {line_number++; column_number = 1;} -\t {column_number++;} -" " {column_number++;} -. {column_number++; return 1999;} - -%% diff --git a/src/symbol_table.c b/src/symbol_table.c index 48a7a42..47d731b 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -1,3 +1,6 @@ +/* Symbol Table */ +/* The Translators - Spring 2025 */ + #include "symbol_table.h" #include From e32b8758b5950222e94319a4d26e1818c8f37096 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 6 Mar 2025 21:39:51 -0500 Subject: [PATCH 28/31] edited the test file llnode t#36 --- tests/sprint2/test/sp2_llnode.alpha | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha index 880ca0b..6b4912e 100644 --- a/tests/sprint2/test/sp2_llnode.alpha +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -2,7 +2,7 @@ type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer -type llnode: [address: prev; integer: val; address: next] +type llnode: [llnode: prev; integer: val; llnode: next] type list: integer -> llnode function foo : T1 From 06764ad9b3bb621b9a36e11b3cfbe0f1ed266bd2 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Fri, 7 Mar 2025 12:36:06 -0500 Subject: [PATCH 29/31] Prec not working --- src/grammar.y | 28 ++++++++++++------------- tests/sprint2/test/sp2_presidence.alpha | 4 ++++ 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 tests/sprint2/test/sp2_presidence.alpha diff --git a/src/grammar.y b/src/grammar.y index 350b568..0fc6eb0 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -177,20 +177,20 @@ rec_op : expression: constant - | SUB_OR_NEG expression %prec UMINUS - | NOT expression - | expression ADD expression - | expression SUB_OR_NEG expression - | expression MUL expression - | expression DIV expression - | expression REM expression - | expression AND expression - | expression OR expression - | expression LESS_THAN expression - | expression EQUAL_TO expression - | assignable - | L_PAREN expression R_PAREN - | memOp assignable + | SUB_OR_NEG expression %prec UMINUS{printf("==\n");} + | NOT expression{printf("==\n");} + | expression ADD expression %prec ADD {printf("doing addition\n");} + | expression SUB_OR_NEG expression %prec SUB_OR_NEG{printf("subtraction\n");} + | expression MUL expression %prec MUL {printf("multiplication\n");} + | expression DIV expression %prec DIV{printf("division\n");} + | expression REM expression %prec REM {printf("remainder\n");} + | expression AND expression %prec AND {printf("and\n");} + | expression OR expression %prec OR {printf("or\n");} + | expression LESS_THAN expression %prec LESS_THAN {printf("less than\n");} + | expression EQUAL_TO expression %prec EQUAL_TO{printf("==\n");} + | assignable {printf("==\n");} + | L_PAREN expression R_PAREN {printf("==\n");} + | memOp assignable{printf("==\n");} ; ablock: diff --git a/tests/sprint2/test/sp2_presidence.alpha b/tests/sprint2/test/sp2_presidence.alpha new file mode 100644 index 0000000..9b2ef86 --- /dev/null +++ b/tests/sprint2/test/sp2_presidence.alpha @@ -0,0 +1,4 @@ +entry(arg) := { + [integer:x] + x := 3 + 2 * 8; +} From 6dcad0752073e30f75bfaa787b66b1b71b49d52f Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 7 Mar 2025 13:36:07 -0500 Subject: [PATCH 30/31] fixed precedence tests --- src/grammar.y | 67 ++++++++++--------- src/lexicalStructure.lex | 2 +- .../sprint2/test/sp2_integer_binary_op.alpha | 15 +++++ 3 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 tests/sprint2/test/sp2_integer_binary_op.alpha diff --git a/src/grammar.y b/src/grammar.y index 3732fc1..f4a8b1b 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,6 +1,7 @@ %{ #include #include "../src/symbol_table.c" + #include extern int yylex(void); void yyerror(const char *err); extern char* yytext; @@ -21,16 +22,18 @@ char * words; } -//need subtraction only here + %type id_or_types %type types +%type expression +%type constant %token ID 101 %token T_INTEGER 201 %token T_ADDRESS 202 %token T_BOOLEAN 203 %token T_CHARACTER 204 %token T_STRING 205 -%token C_INTEGER 301 +%token C_INTEGER 301 %token C_NULL 302 %token C_CHARACTER 303 %token C_STRING 304 @@ -72,17 +75,19 @@ %token COMMENT 700 //precedence order -%precedence RESERVE RELEASE -%precedence DOT -%precedence UMINUS -%precedence NOT -%left MUL DIV REM -%left ADD SUB_OR_NEG -%left LESS_THAN -%left EQUAL_TO -%left AND -%left OR %left ASSIGN +%left OR +%left AND +%left EQUAL_TO +%left LESS_THAN +%left ADD SUB_OR_NEG +%left MUL DIV REM +%precedence NOT +%precedence UMINUS +%precedence DOT +%precedence RESERVE RELEASE + + %% @@ -125,7 +130,7 @@ idlist: sblock: L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE - | L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock statement_list {cur = getParent(cur);} R_BRACE + | L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE ; dblock: @@ -155,7 +160,7 @@ statement_list: compound_statement: WHILE L_PAREN expression R_PAREN sblock | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock - | sblock + | sblock //{printf("seen a compound statement rule\n");} ; simple_statement: @@ -173,21 +178,21 @@ rec_op : DOT expression: - constant - | SUB_OR_NEG expression %prec UMINUS - | NOT expression - | expression ADD expression - | expression SUB_OR_NEG expression - | expression MUL expression - | expression DIV expression - | expression REM expression - | expression AND expression - | expression OR expression - | expression LESS_THAN expression - | expression EQUAL_TO expression - | assignable - | L_PAREN expression R_PAREN - | memOp assignable + constant {printf("constant expression\n");} + | SUB_OR_NEG expression %prec UMINUS {printf("negative expression\n");} + | NOT expression {printf("not expression\n");} + | expression ADD expression {printf("add expression\n");} + | expression SUB_OR_NEG expression {printf("subtract expression\n");} + | expression MUL expression {printf("multiply expression\n");} + | expression DIV expression {printf("division expression\n");} + | expression REM expression {printf("remainder expression\n");} + | expression AND expression {printf("and expression\n");} + | expression OR expression {printf("or expression\n");} + | expression LESS_THAN expression {printf("less than expression\n");} + | expression EQUAL_TO expression {printf("equals check expression\n");} + | assignable {printf("assignable expression\n");} + | L_PAREN expression R_PAREN {printf("paren expression\n");} + | memOp assignable ; ablock: @@ -201,8 +206,8 @@ argument_list: memOp: - RESERVE - | RELEASE + RESERVE {printf("reserve expression\n");} + | RELEASE {printf("release expression\n");} ; diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index aae5433..0c53b6f 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -72,7 +72,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] "," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}} "->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}} -{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);return C_INTEGER;}} +{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.integ = atoi(yytext);return C_INTEGER;}} '{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);return C_CHARACTER;}} \"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);return C_STRING;}} {COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}} diff --git a/tests/sprint2/test/sp2_integer_binary_op.alpha b/tests/sprint2/test/sp2_integer_binary_op.alpha new file mode 100644 index 0000000..39e00a6 --- /dev/null +++ b/tests/sprint2/test/sp2_integer_binary_op.alpha @@ -0,0 +1,15 @@ +entry(arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] + x := 3 + 2 * 8; + x := 3 - 2 / 8; + x := 3 * 2 % 8; + x := 3 * 2 % 8; + x := 3 % 2 * 8; + x := 3 + 2 - 8; + arr2 := 1 * reserve x; + arr2 := release x; + b2 := 3 < 2; + b1 := 1 = 2; + b2 := !(3 < 2); + b1 := 6<7 & 7=7; +} From d1c36566c70539ed0ea72875bdd8efab98a1fb4f Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 7 Mar 2025 15:22:10 -0500 Subject: [PATCH 31/31] still working on resolving type name issue --- src/grammar.y | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 8ea0317..4c5e4e6 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -28,8 +28,6 @@ %type id_or_types %type types -%type expression -%type constant %token ID 101 %token T_INTEGER 201 %token T_ADDRESS 202 @@ -37,11 +35,11 @@ %token T_CHARACTER 204 %token T_STRING 205 %token C_INTEGER 301 -%token C_NULL 302 -%token C_CHARACTER 303 -%token C_STRING 304 -%token C_TRUE 305 -%token C_FALSE 306 +%token C_NULL 302 +%token C_CHARACTER 303 +%token C_STRING 304 +%token C_TRUE 305 +%token C_FALSE 306 %token WHILE 401 %token IF 402 %token THEN 403 @@ -109,17 +107,17 @@ prototype: L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; definition: - TYPE ID COLON dblock + TYPE ID COLON dblock | TYPE ID COLON constant ARROW ID - | function_declaration + //| function_declaration | TYPE ID COLON id_or_types ARROW id_or_types | ID parameter ASSIGN sblock ; -function_declaration: - FUNCTION ID COLON ID - | EXTERNAL FUNCTION ID COLON ID - ; +//function_declaration: + // FUNCTION ID COLON ID + //| EXTERNAL FUNCTION ID COLON ID + //; parameter: L_PAREN ID R_PAREN @@ -145,12 +143,12 @@ declaration_list: ; declaration: - id_or_types COLON ID {CreateEntry(cur,$1,$3); } + id_or_types COLON ID {CreateEntry(cur,$1,$3); } ; id_or_types: - ID - | types + ID {printf("string of id in id_or_type is %s\n",$1);} {$$ = $1;} + | types {printf("string of type in id_or_type is %s\n",$1);} {$$ = $1;} ; statement_list: @@ -226,11 +224,11 @@ constant: ; types: - T_STRING - | T_INTEGER - | T_ADDRESS - | T_CHARACTER - | T_BOOLEAN + T_STRING {printf("string of T_STRING in types is %s\n",$1);} {$$ = $1;} + | T_INTEGER {printf("string of T_INTEGER in types is %s\n",$1);} {$$ = $1;} + | T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$1);} {$$ = $1;} + | T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$1);} {$$ = $1;} + | T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$1);} {$$ = $1;} ; %%