diff options
Diffstat (limited to 'vendor/vm')
| -rw-r--r-- | vendor/vm/doc/changelog.txt | 10 | ||||
| -rw-r--r-- | vendor/vm/doc/vm.txt | 230 | ||||
| -rw-r--r-- | vendor/vm/vm/Makefile | 15 | ||||
| -rw-r--r-- | vendor/vm/vm/lex.yy.c | 1964 | ||||
| -rw-r--r-- | vendor/vm/vm/main.c | 47 | ||||
| -rw-r--r-- | vendor/vm/vm/test/bop1.ms | 6 | ||||
| -rw-r--r-- | vendor/vm/vm/test/bop2.ms | 8 | ||||
| -rw-r--r-- | vendor/vm/vm/test/fib.ms | 37 | ||||
| -rw-r--r-- | vendor/vm/vm/test/fib2.ms | 21 | ||||
| -rw-r--r-- | vendor/vm/vm/vm.c | 458 | ||||
| -rw-r--r-- | vendor/vm/vm/vm.h | 94 | ||||
| -rw-r--r-- | vendor/vm/vm/vmlex.l | 56 | ||||
| -rw-r--r-- | vendor/vm/vm/vmparse.y | 83 |
13 files changed, 3029 insertions, 0 deletions
diff --git a/vendor/vm/doc/changelog.txt b/vendor/vm/doc/changelog.txt new file mode 100644 index 0000000..104d663 --- /dev/null +++ b/vendor/vm/doc/changelog.txt | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | История изменений: | ||
| 2 | ================== | ||
| 3 | |||
| 4 | Версия 1.2: | ||
| 5 | * Виртуальная машина отделена от компилятора ymilan в отдельный пакет со своей | ||
| 6 | нумерацией версий. | ||
| 7 | * Добавлена команда NOP (отсутствие операции). | ||
| 8 | |||
| 9 | Версия 1.1: | ||
| 10 | * Первоначальная версия виртуальной машины в комплеке компилятора ymilan 1.1. | ||
diff --git a/vendor/vm/doc/vm.txt b/vendor/vm/doc/vm.txt new file mode 100644 index 0000000..8c27ff3 --- /dev/null +++ b/vendor/vm/doc/vm.txt | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | == Машинные команды == | ||
| 2 | |||
| 3 | Виртуальная машина Милана содержит из памяти команд, памяти данных и | ||
| 4 | стека. В памяти команд находятся исполняемые инструкции. Память | ||
| 5 | данных используется для хранения значений переменных. Является рабочей | ||
| 6 | областью: команды виртуальной машины считывают свои аргументы из стека | ||
| 7 | и заталкивают в стек результаты. | ||
| 8 | |||
| 9 | Виртуальная машина Милана исполняет следующие команды. | ||
| 10 | |||
| 11 | NOP | ||
| 12 | |||
| 13 | Отсутствие операции; команда пропускается. | ||
| 14 | |||
| 15 | STOP | ||
| 16 | |||
| 17 | Прекращает выполнение программы; виртуальная машина возвращает | ||
| 18 | управление операционной системе. | ||
| 19 | |||
| 20 | LOAD <адрес> | ||
| 21 | |||
| 22 | Помещает в стек слово, расположенное в памяти по адресу | ||
| 23 | <адрес>. | ||
| 24 | |||
| 25 | STORE <адрес> | ||
| 26 | |||
| 27 | Выталкивает из стека слово и записывает его в память по адресу | ||
| 28 | <адрес>. Если нужная ячейка находится за пределами рабочей | ||
| 29 | области памяти, диагностируется ошибка времени исполнения. | ||
| 30 | |||
| 31 | |||
| 32 | BLOAD <адрес> | ||
| 33 | |||
| 34 | Помещает в стек слово, адрес которого вычисляется следующим | ||
| 35 | образом: <адрес в памяти> = <адрес> + <значение с вершины | ||
| 36 | стека>. Значение с вершины стека удаляется. | ||
| 37 | |||
| 38 | Команду BLOAD можно использовать, например, для обращения к | ||
| 39 | элементу массива или к переменной, адрес которой вычисляется | ||
| 40 | во время выполнения программы. | ||
| 41 | |||
| 42 | BSTORE <адрес> | ||
| 43 | |||
| 44 | Вычисляет адрес в памяти по формуле: | ||
| 45 | <адрес в памяти> = <адрес> + <значение с вершины стека>, значение | ||
| 46 | с вершины стека при этом удаляется. Выталкивает из стека слово и записывает | ||
| 47 | его по адресу <адрес в памяти>. | ||
| 48 | |||
| 49 | Команду BSTORE можно использовать для записи значения в элемент | ||
| 50 | массива или в переменную, адрес которой вычисляется во время выполнения | ||
| 51 | программы. | ||
| 52 | |||
| 53 | Пусть стек имеет вид: [10, 20, ...]. В этом случае команда BSTORE 5 | ||
| 54 | запишет по адресу 15 число 20. | ||
| 55 | |||
| 56 | PUSH <значение> | ||
| 57 | |||
| 58 | Заталкивает <значение> в стек. | ||
| 59 | |||
| 60 | POP | ||
| 61 | |||
| 62 | Выталкивает слово из стека. | ||
| 63 | |||
| 64 | DUP | ||
| 65 | |||
| 66 | Заталкивает в стек значение, равное значению на вершине стека. | ||
| 67 | |||
| 68 | ADD | ||
| 69 | |||
| 70 | Выталкивает из стека два числа и заталкивает в стек результат | ||
| 71 | их сложения. | ||
| 72 | |||
| 73 | MULT | ||
| 74 | |||
| 75 | Выталкивает из стека два числа и заталкивает в стек результат | ||
| 76 | их умножения. | ||
| 77 | |||
| 78 | SUB | ||
| 79 | |||
| 80 | Выталкивает из стека число <a>, выталкивает из стека число <b> | ||
| 81 | и заталкивает в стек разность <b> - <a>. | ||
| 82 | |||
| 83 | Пример: после выполнения последовательности команд | ||
| 84 | |||
| 85 | PUSH 10 | ||
| 86 | PUSH 8 | ||
| 87 | SUB | ||
| 88 | |||
| 89 | на вершине стека будет находиться число 2. | ||
| 90 | |||
| 91 | DIV | ||
| 92 | |||
| 93 | Выталкивает из стека число <a>, выталкивает из стека число <b> | ||
| 94 | и заталкивает в стек частное <b> / <a>. Используется | ||
| 95 | целочисленное деление. Если значение <a> = 0, то | ||
| 96 | диагностируется ошибка времени исполнения. | ||
| 97 | |||
| 98 | INVERT | ||
| 99 | |||
| 100 | Меняет знак числа на вершине стека на противоположный. | ||
| 101 | |||
| 102 | COMPARE <код> | ||
| 103 | |||
| 104 | Выталкивает из стека число <a>, выталкивает из стека число | ||
| 105 | <b>, затем заталкивает в стек результат сравнения <b> и <a>. | ||
| 106 | |||
| 107 | Операция сравнения определяется значением аргумента <код>: | ||
| 108 | |||
| 109 | <код> операция | ||
| 110 | |||
| 111 | 0 <b> = <a> | ||
| 112 | 1 <b> != <a> | ||
| 113 | 2 <b> < <a> | ||
| 114 | 3 <b> > <a> | ||
| 115 | 4 <b> <= <a> | ||
| 116 | 5 <b> >= <a> | ||
| 117 | |||
| 118 | Результатом сравнения является значение 1, если требуемое | ||
| 119 | неравенство выполняется, и 0 в противном случае. | ||
| 120 | |||
| 121 | Пример: после выполнения последовательности команд | ||
| 122 | |||
| 123 | PUSH 5 | ||
| 124 | PUSH 7 | ||
| 125 | COMPARE 2 | ||
| 126 | |||
| 127 | на вершине стека будет находиться значение 1 (так как 5 < 7). | ||
| 128 | |||
| 129 | JUMP <адрес> | ||
| 130 | |||
| 131 | Выполняет переход по адресу <адрес>, то есть устанавливает | ||
| 132 | адрес следующей исполняемой команды равным <адрес>. Если | ||
| 133 | <адрес> меньше нуля или больше, чем адрес последней команды в | ||
| 134 | программе, диагностируется ошибка времени исполнения. | ||
| 135 | |||
| 136 | |||
| 137 | JUMP_YES <адрес> | ||
| 138 | |||
| 139 | Выполняет переход по адресу <адрес>, если на вершине стека | ||
| 140 | находится ненулевое значение; слово выталкивается из стека. | ||
| 141 | |||
| 142 | JUMP_NO <адрес> | ||
| 143 | |||
| 144 | Выполняет переход по адресу <адрес>, если на вершине стека | ||
| 145 | находится значение 0; слово выталкивается из стека. Если | ||
| 146 | <адрес> меньше нуля или больше, чем адрес последней команды в | ||
| 147 | программе, диагностируется ошибка времени исполнения. | ||
| 148 | |||
| 149 | INPUT | ||
| 150 | |||
| 151 | Считывает целочисленное значение со стандартного устройства | ||
| 152 | ввода и заталкивает его в стек. В случае ошибки ввода-вывода | ||
| 153 | или несоответсвия формата диагностируется ошибка времени | ||
| 154 | исполнения. | ||
| 155 | |||
| 156 | |||
| 157 | |||
| 158 | Выталкивает из стека слово и выводит его на стандартное | ||
| 159 | устройство ввода. Значение форматируется как целое число. | ||
| 160 | |||
| 161 | Каждая команда исполняется за один такт работы виртуальной машины. | ||
| 162 | |||
| 163 | Виртуальная машина формирует содержимое памяти команд и данных, читая | ||
| 164 | и интерпретируя текстовый файл программы. Файл имеет следующий формат. | ||
| 165 | |||
| 166 | Файл читается как последовательность строк. Символ ';' начинает | ||
| 167 | комментарий, все символы, начиная с него и до конца строки, | ||
| 168 | игнорируются. | ||
| 169 | |||
| 170 | Команда состоит из адреса, кода операции и аргумента, если он | ||
| 171 | требуется. Адрес является целым числом, за которым следует символ | ||
| 172 | ':'. Нумерация команд начинается с 0. | ||
| 173 | |||
| 174 | Код операции совпадает с описанным ранее символьным обозначением, | ||
| 175 | например: STOP. Если команда имеет аргумент, он должен быть целым | ||
| 176 | числом. | ||
| 177 | |||
| 178 | Пример корректной программы на языке виртуальной машины Милана: | ||
| 179 | |||
| 180 | ------------------------------------------------------------ | ||
| 181 | 0: INPUT | ||
| 182 | 1: STORE 42 ; n := READ | ||
| 183 | 2: LOAD 14 | ||
| 184 | 3: PUSH 4 | ||
| 185 | 4: LOAD 42 | ||
| 186 | 5: COMPARE 2 | ||
| 187 | 6: JUMP_NO 9 | ||
| 188 | 7: PUSH 10 | ||
| 189 | 8: STORE 42 | ||
| 190 | 9: LOAD 42 | ||
| 191 | 10: PRINT | ||
| 192 | 11: STOP | ||
| 193 | ------------------------------------------------------------- | ||
| 194 | |||
| 195 | Для инициализации памяти данных используется служебная инструкция | ||
| 196 | виртуальной машины SET: | ||
| 197 | |||
| 198 | SET <адрес> <значение> | ||
| 199 | |||
| 200 | В результате исполнения инструкции SET по адресу <адрес> в память | ||
| 201 | данных записывается слово <значение>. | ||
| 202 | |||
| 203 | Инструкция SET не сохраняется в памяти команд. Она служит для | ||
| 204 | инициализации памяти перед началом исполнения программы. Компилятор | ||
| 205 | может генерировать блок команд SET для задания значений констант и | ||
| 206 | статически инициализированных переменных. | ||
| 207 | |||
| 208 | Инструкция SET <адрес> <значение> эквивалентна паре команд | ||
| 209 | |||
| 210 | PUSH <значение> | ||
| 211 | STORE <адрес> | ||
| 212 | |||
| 213 | и выполняется за один такт. | ||
| 214 | |||
| 215 | Инструкция SET не требует указания адреса. Пример корректного | ||
| 216 | использованя SET: | ||
| 217 | |||
| 218 | ------------------------------------ | ||
| 219 | SET 0 15 | ||
| 220 | SET 1 40 | ||
| 221 | |||
| 222 | 0: LOAD 0 | ||
| 223 | 1: LOAD 1 | ||
| 224 | 2: ADD | ||
| 225 | 3: PRINT | ||
| 226 | 4: STOP | ||
| 227 | ------------------------------------ | ||
| 228 | |||
| 229 | В результате выполнения этой программы будет напечатано число 55. | ||
| 230 | |||
diff --git a/vendor/vm/vm/Makefile b/vendor/vm/vm/Makefile new file mode 100644 index 0000000..c0c1887 --- /dev/null +++ b/vendor/vm/vm/Makefile | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | mvm: vm.c lex.yy.c vmparse.tab.h main.c | ||
| 2 | gcc -ggdb3 -o mvm main.c vm.c lex.yy.c vmparse.tab.c | ||
| 3 | |||
| 4 | lex.yy.c: vmlex.l | ||
| 5 | flex vmlex.l | ||
| 6 | |||
| 7 | vmparse.tab.h: vmparse.y | ||
| 8 | bison -d vmparse.y | ||
| 9 | |||
| 10 | clean: | ||
| 11 | rm lex.yy.c vmparse.tab.h vmparse.tab.c | ||
| 12 | |||
| 13 | distclean: | ||
| 14 | rm mvm lex.yy.c vmparse.tab.h vmparse.tab.c | ||
| 15 | |||
diff --git a/vendor/vm/vm/lex.yy.c b/vendor/vm/vm/lex.yy.c new file mode 100644 index 0000000..558802d --- /dev/null +++ b/vendor/vm/vm/lex.yy.c | |||
| @@ -0,0 +1,1964 @@ | |||
| 1 | |||
| 2 | #line 2 "lex.yy.c" | ||
| 3 | |||
| 4 | #define YY_INT_ALIGNED short int | ||
| 5 | |||
| 6 | /* A lexical scanner generated by flex */ | ||
| 7 | |||
| 8 | #define FLEX_SCANNER | ||
| 9 | #define YY_FLEX_MAJOR_VERSION 2 | ||
| 10 | #define YY_FLEX_MINOR_VERSION 6 | ||
| 11 | #define YY_FLEX_SUBMINOR_VERSION 4 | ||
| 12 | #if YY_FLEX_SUBMINOR_VERSION > 0 | ||
| 13 | #define FLEX_BETA | ||
| 14 | #endif | ||
| 15 | |||
| 16 | /* First, we deal with platform-specific or compiler-specific issues. */ | ||
| 17 | |||
| 18 | /* begin standard C headers. */ | ||
| 19 | #include <stdio.h> | ||
| 20 | #include <string.h> | ||
| 21 | #include <errno.h> | ||
| 22 | #include <stdlib.h> | ||
| 23 | |||
| 24 | /* end standard C headers. */ | ||
| 25 | |||
| 26 | /* flex integer type definitions */ | ||
| 27 | |||
| 28 | #ifndef FLEXINT_H | ||
| 29 | #define FLEXINT_H | ||
| 30 | |||
| 31 | /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ | ||
| 32 | |||
| 33 | #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L | ||
| 34 | |||
| 35 | /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, | ||
| 36 | * if you want the limit (max/min) macros for int types. | ||
| 37 | */ | ||
| 38 | #ifndef __STDC_LIMIT_MACROS | ||
| 39 | #define __STDC_LIMIT_MACROS 1 | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #include <inttypes.h> | ||
| 43 | typedef int8_t flex_int8_t; | ||
| 44 | typedef uint8_t flex_uint8_t; | ||
| 45 | typedef int16_t flex_int16_t; | ||
| 46 | typedef uint16_t flex_uint16_t; | ||
| 47 | typedef int32_t flex_int32_t; | ||
| 48 | typedef uint32_t flex_uint32_t; | ||
| 49 | #else | ||
| 50 | typedef signed char flex_int8_t; | ||
| 51 | typedef short int flex_int16_t; | ||
| 52 | typedef int flex_int32_t; | ||
| 53 | typedef unsigned char flex_uint8_t; | ||
| 54 | typedef unsigned short int flex_uint16_t; | ||
| 55 | typedef unsigned int flex_uint32_t; | ||
| 56 | |||
| 57 | /* Limits of integral types. */ | ||
| 58 | #ifndef INT8_MIN | ||
| 59 | #define INT8_MIN (-128) | ||
| 60 | #endif | ||
| 61 | #ifndef INT16_MIN | ||
| 62 | #define INT16_MIN (-32767-1) | ||
| 63 | #endif | ||
| 64 | #ifndef INT32_MIN | ||
| 65 | #define INT32_MIN (-2147483647-1) | ||
| 66 | #endif | ||
| 67 | #ifndef INT8_MAX | ||
| 68 | #define INT8_MAX (127) | ||
| 69 | #endif | ||
| 70 | #ifndef INT16_MAX | ||
| 71 | #define INT16_MAX (32767) | ||
| 72 | #endif | ||
| 73 | #ifndef INT32_MAX | ||
| 74 | #define INT32_MAX (2147483647) | ||
| 75 | #endif | ||
| 76 | #ifndef UINT8_MAX | ||
| 77 | #define UINT8_MAX (255U) | ||
| 78 | #endif | ||
| 79 | #ifndef UINT16_MAX | ||
| 80 | #define UINT16_MAX (65535U) | ||
| 81 | #endif | ||
| 82 | #ifndef UINT32_MAX | ||
| 83 | #define UINT32_MAX (4294967295U) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #ifndef SIZE_MAX | ||
| 87 | #define SIZE_MAX (~(size_t)0) | ||
| 88 | #endif | ||
| 89 | |||
| 90 | #endif /* ! C99 */ | ||
| 91 | |||
| 92 | #endif /* ! FLEXINT_H */ | ||
| 93 | |||
| 94 | /* begin standard C++ headers. */ | ||
| 95 | |||
| 96 | /* TODO: this is always defined, so inline it */ | ||
| 97 | #define yyconst const | ||
| 98 | |||
| 99 | #if defined(__GNUC__) && __GNUC__ >= 3 | ||
| 100 | #define yynoreturn __attribute__((__noreturn__)) | ||
| 101 | #else | ||
| 102 | #define yynoreturn | ||
| 103 | #endif | ||
| 104 | |||
| 105 | /* Returned upon end-of-file. */ | ||
| 106 | #define YY_NULL 0 | ||
| 107 | |||
| 108 | /* Promotes a possibly negative, possibly signed char to an | ||
| 109 | * integer in range [0..255] for use as an array index. | ||
| 110 | */ | ||
| 111 | #define YY_SC_TO_UI(c) ((YY_CHAR) (c)) | ||
| 112 | |||
| 113 | /* Enter a start condition. This macro really ought to take a parameter, | ||
| 114 | * but we do it the disgusting crufty way forced on us by the ()-less | ||
| 115 | * definition of BEGIN. | ||
| 116 | */ | ||
| 117 | #define BEGIN (yy_start) = 1 + 2 * | ||
| 118 | /* Translate the current start state into a value that can be later handed | ||
| 119 | * to BEGIN to return to the state. The YYSTATE alias is for lex | ||
| 120 | * compatibility. | ||
| 121 | */ | ||
| 122 | #define YY_START (((yy_start) - 1) / 2) | ||
| 123 | #define YYSTATE YY_START | ||
| 124 | /* Action number for EOF rule of a given start state. */ | ||
| 125 | #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) | ||
| 126 | /* Special action meaning "start processing a new file". */ | ||
| 127 | #define YY_NEW_FILE yyrestart( yyin ) | ||
| 128 | #define YY_END_OF_BUFFER_CHAR 0 | ||
| 129 | |||
| 130 | /* Size of default input buffer. */ | ||
| 131 | #ifndef YY_BUF_SIZE | ||
| 132 | #ifdef __ia64__ | ||
| 133 | /* On IA-64, the buffer size is 16k, not 8k. | ||
| 134 | * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. | ||
| 135 | * Ditto for the __ia64__ case accordingly. | ||
| 136 | */ | ||
| 137 | #define YY_BUF_SIZE 32768 | ||
| 138 | #else | ||
| 139 | #define YY_BUF_SIZE 16384 | ||
| 140 | #endif /* __ia64__ */ | ||
| 141 | #endif | ||
| 142 | |||
| 143 | /* The state buf must be large enough to hold one state per character in the main buffer. | ||
| 144 | */ | ||
| 145 | #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) | ||
| 146 | |||
| 147 | #ifndef YY_TYPEDEF_YY_BUFFER_STATE | ||
| 148 | #define YY_TYPEDEF_YY_BUFFER_STATE | ||
| 149 | typedef struct yy_buffer_state *YY_BUFFER_STATE; | ||
| 150 | #endif | ||
| 151 | |||
| 152 | #ifndef YY_TYPEDEF_YY_SIZE_T | ||
| 153 | #define YY_TYPEDEF_YY_SIZE_T | ||
| 154 | typedef size_t yy_size_t; | ||
| 155 | #endif | ||
| 156 | |||
| 157 | extern int yyleng; | ||
| 158 | |||
| 159 | extern FILE *yyin, *yyout; | ||
| 160 | |||
| 161 | #define EOB_ACT_CONTINUE_SCAN 0 | ||
| 162 | #define EOB_ACT_END_OF_FILE 1 | ||
| 163 | #define EOB_ACT_LAST_MATCH 2 | ||
| 164 | |||
| 165 | #define YY_LESS_LINENO(n) | ||
| 166 | #define YY_LINENO_REWIND_TO(ptr) | ||
| 167 | |||
| 168 | /* Return all but the first "n" matched characters back to the input stream. */ | ||
| 169 | #define yyless(n) \ | ||
| 170 | do \ | ||
| 171 | { \ | ||
| 172 | /* Undo effects of setting up yytext. */ \ | ||
| 173 | int yyless_macro_arg = (n); \ | ||
| 174 | YY_LESS_LINENO(yyless_macro_arg);\ | ||
| 175 | *yy_cp = (yy_hold_char); \ | ||
| 176 | YY_RESTORE_YY_MORE_OFFSET \ | ||
| 177 | (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ | ||
| 178 | YY_DO_BEFORE_ACTION; /* set up yytext again */ \ | ||
| 179 | } \ | ||
| 180 | while ( 0 ) | ||
| 181 | #define unput(c) yyunput( c, (yytext_ptr) ) | ||
| 182 | |||
| 183 | #ifndef YY_STRUCT_YY_BUFFER_STATE | ||
| 184 | #define YY_STRUCT_YY_BUFFER_STATE | ||
| 185 | struct yy_buffer_state | ||
| 186 | { | ||
| 187 | FILE *yy_input_file; | ||
| 188 | |||
| 189 | char *yy_ch_buf; /* input buffer */ | ||
| 190 | char *yy_buf_pos; /* current position in input buffer */ | ||
| 191 | |||
| 192 | /* Size of input buffer in bytes, not including room for EOB | ||
| 193 | * characters. | ||
| 194 | */ | ||
| 195 | int yy_buf_size; | ||
| 196 | |||
| 197 | /* Number of characters read into yy_ch_buf, not including EOB | ||
| 198 | * characters. | ||
| 199 | */ | ||
| 200 | int yy_n_chars; | ||
| 201 | |||
| 202 | /* Whether we "own" the buffer - i.e., we know we created it, | ||
| 203 | * and can realloc() it to grow it, and should free() it to | ||
| 204 | * delete it. | ||
| 205 | */ | ||
| 206 | int yy_is_our_buffer; | ||
| 207 | |||
| 208 | /* Whether this is an "interactive" input source; if so, and | ||
| 209 | * if we're using stdio for input, then we want to use getc() | ||
| 210 | * instead of fread(), to make sure we stop fetching input after | ||
| 211 | * each newline. | ||
| 212 | */ | ||
| 213 | int yy_is_interactive; | ||
| 214 | |||
| 215 | /* Whether we're considered to be at the beginning of a line. | ||
| 216 | * If so, '^' rules will be active on the next match, otherwise | ||
| 217 | * not. | ||
| 218 | */ | ||
| 219 | int yy_at_bol; | ||
| 220 | |||
| 221 | int yy_bs_lineno; /**< The line count. */ | ||
| 222 | int yy_bs_column; /**< The column count. */ | ||
| 223 | |||
| 224 | /* Whether to try to fill the input buffer when we reach the | ||
| 225 | * end of it. | ||
| 226 | */ | ||
| 227 | int yy_fill_buffer; | ||
| 228 | |||
| 229 | int yy_buffer_status; | ||
| 230 | |||
| 231 | #define YY_BUFFER_NEW 0 | ||
| 232 | #define YY_BUFFER_NORMAL 1 | ||
| 233 | /* When an EOF's been seen but there's still some text to process | ||
| 234 | * then we mark the buffer as YY_EOF_PENDING, to indicate that we | ||
| 235 | * shouldn't try reading from the input source any more. We might | ||
| 236 | * still have a bunch of tokens to match, though, because of | ||
| 237 | * possible backing-up. | ||
| 238 | * | ||
| 239 | * When we actually see the EOF, we change the status to "new" | ||
| 240 | * (via yyrestart()), so that the user can continue scanning by | ||
| 241 | * just pointing yyin at a new input file. | ||
| 242 | */ | ||
| 243 | #define YY_BUFFER_EOF_PENDING 2 | ||
| 244 | |||
| 245 | }; | ||
| 246 | #endif /* !YY_STRUCT_YY_BUFFER_STATE */ | ||
| 247 | |||
| 248 | /* Stack of input buffers. */ | ||
| 249 | static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ | ||
| 250 | static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ | ||
| 251 | static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ | ||
| 252 | |||
| 253 | /* We provide macros for accessing buffer states in case in the | ||
| 254 | * future we want to put the buffer states in a more general | ||
| 255 | * "scanner state". | ||
| 256 | * | ||
| 257 | * Returns the top of the stack, or NULL. | ||
| 258 | */ | ||
| 259 | #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ | ||
| 260 | ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ | ||
| 261 | : NULL) | ||
| 262 | /* Same as previous macro, but useful when we know that the buffer stack is not | ||
| 263 | * NULL or when we need an lvalue. For internal use only. | ||
| 264 | */ | ||
| 265 | #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] | ||
| 266 | |||
| 267 | /* yy_hold_char holds the character lost when yytext is formed. */ | ||
| 268 | static char yy_hold_char; | ||
| 269 | static int yy_n_chars; /* number of characters read into yy_ch_buf */ | ||
| 270 | int yyleng; | ||
| 271 | |||
| 272 | /* Points to current character in buffer. */ | ||
| 273 | static char *yy_c_buf_p = NULL; | ||
| 274 | static int yy_init = 0; /* whether we need to initialize */ | ||
| 275 | static int yy_start = 0; /* start state number */ | ||
| 276 | |||
| 277 | /* Flag which is used to allow yywrap()'s to do buffer switches | ||
| 278 | * instead of setting up a fresh yyin. A bit of a hack ... | ||
| 279 | */ | ||
| 280 | static int yy_did_buffer_switch_on_eof; | ||
| 281 | |||
| 282 | void yyrestart ( FILE *input_file ); | ||
| 283 | void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); | ||
| 284 | YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); | ||
| 285 | void yy_delete_buffer ( YY_BUFFER_STATE b ); | ||
| 286 | void yy_flush_buffer ( YY_BUFFER_STATE b ); | ||
| 287 | void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); | ||
| 288 | void yypop_buffer_state ( void ); | ||
| 289 | |||
| 290 | static void yyensure_buffer_stack ( void ); | ||
| 291 | static void yy_load_buffer_state ( void ); | ||
| 292 | static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); | ||
| 293 | #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) | ||
| 294 | |||
| 295 | YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); | ||
| 296 | YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); | ||
| 297 | YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); | ||
| 298 | |||
| 299 | void *yyalloc ( yy_size_t ); | ||
| 300 | void *yyrealloc ( void *, yy_size_t ); | ||
| 301 | void yyfree ( void * ); | ||
| 302 | |||
| 303 | #define yy_new_buffer yy_create_buffer | ||
| 304 | #define yy_set_interactive(is_interactive) \ | ||
| 305 | { \ | ||
| 306 | if ( ! YY_CURRENT_BUFFER ){ \ | ||
| 307 | yyensure_buffer_stack (); \ | ||
| 308 | YY_CURRENT_BUFFER_LVALUE = \ | ||
| 309 | yy_create_buffer( yyin, YY_BUF_SIZE ); \ | ||
| 310 | } \ | ||
| 311 | YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ | ||
| 312 | } | ||
| 313 | #define yy_set_bol(at_bol) \ | ||
| 314 | { \ | ||
| 315 | if ( ! YY_CURRENT_BUFFER ){\ | ||
| 316 | yyensure_buffer_stack (); \ | ||
| 317 | YY_CURRENT_BUFFER_LVALUE = \ | ||
| 318 | yy_create_buffer( yyin, YY_BUF_SIZE ); \ | ||
| 319 | } \ | ||
| 320 | YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ | ||
| 321 | } | ||
| 322 | #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) | ||
| 323 | |||
| 324 | /* Begin user sect3 */ | ||
| 325 | |||
| 326 | #define yywrap() (/*CONSTCOND*/1) | ||
| 327 | #define YY_SKIP_YYWRAP | ||
| 328 | typedef flex_uint8_t YY_CHAR; | ||
| 329 | |||
| 330 | FILE *yyin = NULL, *yyout = NULL; | ||
| 331 | |||
| 332 | typedef int yy_state_type; | ||
| 333 | |||
| 334 | extern int yylineno; | ||
| 335 | int yylineno = 1; | ||
| 336 | |||
| 337 | extern char *yytext; | ||
| 338 | #ifdef yytext_ptr | ||
| 339 | #undef yytext_ptr | ||
| 340 | #endif | ||
| 341 | #define yytext_ptr yytext | ||
| 342 | |||
| 343 | static yy_state_type yy_get_previous_state ( void ); | ||
| 344 | static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); | ||
| 345 | static int yy_get_next_buffer ( void ); | ||
| 346 | static void yynoreturn yy_fatal_error ( const char* msg ); | ||
| 347 | |||
| 348 | /* Done after the current pattern has been matched and before the | ||
| 349 | * corresponding action - sets up yytext. | ||
| 350 | */ | ||
| 351 | #define YY_DO_BEFORE_ACTION \ | ||
| 352 | (yytext_ptr) = yy_bp; \ | ||
| 353 | yyleng = (int) (yy_cp - yy_bp); \ | ||
| 354 | (yy_hold_char) = *yy_cp; \ | ||
| 355 | *yy_cp = '\0'; \ | ||
| 356 | (yy_c_buf_p) = yy_cp; | ||
| 357 | #define YY_NUM_RULES 32 | ||
| 358 | #define YY_END_OF_BUFFER 33 | ||
| 359 | /* This struct is not used in this scanner, | ||
| 360 | but its presence is necessary. */ | ||
| 361 | struct yy_trans_info | ||
| 362 | { | ||
| 363 | flex_int32_t yy_verify; | ||
| 364 | flex_int32_t yy_nxt; | ||
| 365 | }; | ||
| 366 | static const flex_int16_t yy_accept[106] = | ||
| 367 | { 0, | ||
| 368 | 0, 0, 33, 32, 3, 1, 32, 4, 5, 32, | ||
| 369 | 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, | ||
| 370 | 32, 32, 3, 4, 0, 2, 0, 0, 0, 0, | ||
| 371 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 372 | 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, | ||
| 373 | 0, 24, 19, 0, 0, 0, 0, 0, 31, 18, | ||
| 374 | 0, 0, 0, 11, 0, 0, 22, 0, 0, 6, | ||
| 375 | 0, 0, 0, 26, 13, 23, 0, 17, 0, 0, | ||
| 376 | 12, 0, 15, 0, 0, 29, 0, 0, 8, 30, | ||
| 377 | 0, 10, 14, 16, 0, 20, 0, 0, 7, 9, | ||
| 378 | |||
| 379 | 25, 28, 0, 27, 0 | ||
| 380 | } ; | ||
| 381 | |||
| 382 | static const YY_CHAR yy_ec[256] = | ||
| 383 | { 0, | ||
| 384 | 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, | ||
| 385 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 386 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 387 | 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 388 | 1, 1, 1, 1, 4, 1, 1, 5, 5, 5, | ||
| 389 | 5, 5, 5, 5, 5, 5, 5, 6, 7, 1, | ||
| 390 | 1, 1, 1, 1, 8, 9, 10, 11, 12, 13, | ||
| 391 | 1, 14, 15, 16, 1, 17, 18, 19, 20, 21, | ||
| 392 | 1, 22, 23, 24, 25, 26, 1, 1, 27, 1, | ||
| 393 | 1, 1, 1, 1, 28, 1, 1, 1, 1, 1, | ||
| 394 | |||
| 395 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 396 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 397 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 398 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 399 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 400 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 401 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 402 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 403 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 404 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 405 | |||
| 406 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 407 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 408 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 409 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 410 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 411 | 1, 1, 1, 1, 1 | ||
| 412 | } ; | ||
| 413 | |||
| 414 | static const YY_CHAR yy_meta[29] = | ||
| 415 | { 0, | ||
| 416 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 417 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 418 | 1, 1, 1, 1, 1, 1, 1, 1 | ||
| 419 | } ; | ||
| 420 | |||
| 421 | static const flex_int16_t yy_base[107] = | ||
| 422 | { 0, | ||
| 423 | 0, 0, 115, 116, 112, 116, 108, 107, 116, 108, | ||
| 424 | 99, 12, 22, 16, 90, 83, 87, 81, 85, 12, | ||
| 425 | 92, 24, 101, 97, 98, 116, 89, 79, 74, 80, | ||
| 426 | 78, 69, 73, 18, 75, 84, 74, 69, 68, 73, | ||
| 427 | 64, 62, 61, 69, 63, 73, 116, 73, 60, 62, | ||
| 428 | 57, 116, 116, 52, 64, 54, 63, 49, 116, 116, | ||
| 429 | 53, 57, 45, 116, 56, 24, 116, 57, 45, 116, | ||
| 430 | 58, 41, 42, 35, 53, 116, 37, 116, 38, 35, | ||
| 431 | 116, 46, 116, 45, 34, 116, 31, 24, 116, 116, | ||
| 432 | 35, 116, 44, 116, 40, 116, 30, 35, 116, 116, | ||
| 433 | |||
| 434 | 116, 116, 17, 116, 116, 32 | ||
| 435 | } ; | ||
| 436 | |||
| 437 | static const flex_int16_t yy_def[107] = | ||
| 438 | { 0, | ||
| 439 | 105, 1, 105, 105, 105, 105, 105, 105, 105, 106, | ||
| 440 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 441 | 105, 105, 105, 105, 106, 105, 105, 105, 105, 105, | ||
| 442 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 443 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 444 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 445 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 446 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 447 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 448 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 449 | |||
| 450 | 105, 105, 105, 105, 0, 105 | ||
| 451 | } ; | ||
| 452 | |||
| 453 | static const flex_int16_t yy_nxt[145] = | ||
| 454 | { 0, | ||
| 455 | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, | ||
| 456 | 14, 4, 4, 4, 15, 16, 17, 18, 19, 4, | ||
| 457 | 20, 21, 22, 4, 4, 4, 4, 4, 28, 30, | ||
| 458 | 32, 39, 25, 40, 29, 43, 41, 44, 54, 104, | ||
| 459 | 33, 31, 97, 55, 81, 82, 103, 45, 46, 102, | ||
| 460 | 98, 101, 100, 99, 96, 95, 94, 93, 92, 91, | ||
| 461 | 90, 89, 88, 87, 86, 85, 84, 83, 80, 79, | ||
| 462 | 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, | ||
| 463 | 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, | ||
| 464 | 58, 57, 56, 53, 52, 51, 50, 49, 48, 47, | ||
| 465 | |||
| 466 | 26, 24, 23, 42, 38, 37, 36, 35, 34, 27, | ||
| 467 | 26, 24, 24, 23, 105, 3, 105, 105, 105, 105, | ||
| 468 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 469 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 470 | 105, 105, 105, 105 | ||
| 471 | } ; | ||
| 472 | |||
| 473 | static const flex_int16_t yy_chk[145] = | ||
| 474 | { 0, | ||
| 475 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 476 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
| 477 | 1, 1, 1, 1, 1, 1, 1, 1, 12, 13, | ||
| 478 | 14, 20, 106, 20, 12, 22, 20, 22, 34, 103, | ||
| 479 | 14, 13, 88, 34, 66, 66, 98, 22, 22, 97, | ||
| 480 | 88, 95, 93, 91, 87, 85, 84, 82, 80, 79, | ||
| 481 | 77, 75, 74, 73, 72, 71, 69, 68, 65, 63, | ||
| 482 | 62, 61, 58, 57, 56, 55, 54, 51, 50, 49, | ||
| 483 | 48, 46, 45, 44, 43, 42, 41, 40, 39, 38, | ||
| 484 | 37, 36, 35, 33, 32, 31, 30, 29, 28, 27, | ||
| 485 | |||
| 486 | 25, 24, 23, 21, 19, 18, 17, 16, 15, 11, | ||
| 487 | 10, 8, 7, 5, 3, 105, 105, 105, 105, 105, | ||
| 488 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 489 | 105, 105, 105, 105, 105, 105, 105, 105, 105, 105, | ||
| 490 | 105, 105, 105, 105 | ||
| 491 | } ; | ||
| 492 | |||
| 493 | static yy_state_type yy_last_accepting_state; | ||
| 494 | static char *yy_last_accepting_cpos; | ||
| 495 | |||
| 496 | extern int yy_flex_debug; | ||
| 497 | int yy_flex_debug = 0; | ||
| 498 | |||
| 499 | /* The intent behind this definition is that it'll catch | ||
| 500 | * any uses of REJECT which flex missed. | ||
| 501 | */ | ||
| 502 | #define REJECT reject_used_but_not_detected | ||
| 503 | #define yymore() yymore_used_but_not_detected | ||
| 504 | #define YY_MORE_ADJ 0 | ||
| 505 | #define YY_RESTORE_YY_MORE_OFFSET | ||
| 506 | char *yytext; | ||
| 507 | #line 1 "vmlex.l" | ||
| 508 | #line 2 "vmlex.l" | ||
| 509 | #include "vmparse.tab.h" | ||
| 510 | #include <stdlib.h> | ||
| 511 | |||
| 512 | #ifndef __GNUC__ | ||
| 513 | #define YY_NO_UNISTD_H | ||
| 514 | #endif | ||
| 515 | #line 515 "lex.yy.c" | ||
| 516 | #line 516 "lex.yy.c" | ||
| 517 | |||
| 518 | #define INITIAL 0 | ||
| 519 | |||
| 520 | #ifndef YY_NO_UNISTD_H | ||
| 521 | /* Special case for "unistd.h", since it is non-ANSI. We include it way | ||
| 522 | * down here because we want the user's section 1 to have been scanned first. | ||
| 523 | * The user has a chance to override it with an option. | ||
| 524 | */ | ||
| 525 | #include <unistd.h> | ||
| 526 | #endif | ||
| 527 | |||
| 528 | #ifndef YY_EXTRA_TYPE | ||
| 529 | #define YY_EXTRA_TYPE void * | ||
| 530 | #endif | ||
| 531 | |||
| 532 | static int yy_init_globals ( void ); | ||
| 533 | |||
| 534 | /* Accessor methods to globals. | ||
| 535 | These are made visible to non-reentrant scanners for convenience. */ | ||
| 536 | |||
| 537 | int yylex_destroy ( void ); | ||
| 538 | |||
| 539 | int yyget_debug ( void ); | ||
| 540 | |||
| 541 | void yyset_debug ( int debug_flag ); | ||
| 542 | |||
| 543 | YY_EXTRA_TYPE yyget_extra ( void ); | ||
| 544 | |||
| 545 | void yyset_extra ( YY_EXTRA_TYPE user_defined ); | ||
| 546 | |||
| 547 | FILE *yyget_in ( void ); | ||
| 548 | |||
| 549 | void yyset_in ( FILE * _in_str ); | ||
| 550 | |||
| 551 | FILE *yyget_out ( void ); | ||
| 552 | |||
| 553 | void yyset_out ( FILE * _out_str ); | ||
| 554 | |||
| 555 | int yyget_leng ( void ); | ||
| 556 | |||
| 557 | char *yyget_text ( void ); | ||
| 558 | |||
| 559 | int yyget_lineno ( void ); | ||
| 560 | |||
| 561 | void yyset_lineno ( int _line_number ); | ||
| 562 | |||
| 563 | /* Macros after this point can all be overridden by user definitions in | ||
| 564 | * section 1. | ||
| 565 | */ | ||
| 566 | |||
| 567 | #ifndef YY_SKIP_YYWRAP | ||
| 568 | #ifdef __cplusplus | ||
| 569 | extern "C" int yywrap ( void ); | ||
| 570 | #else | ||
| 571 | extern int yywrap ( void ); | ||
| 572 | #endif | ||
| 573 | #endif | ||
| 574 | |||
| 575 | #ifndef YY_NO_UNPUT | ||
| 576 | |||
| 577 | static void yyunput ( int c, char *buf_ptr ); | ||
| 578 | |||
| 579 | #endif | ||
| 580 | |||
| 581 | #ifndef yytext_ptr | ||
| 582 | static void yy_flex_strncpy ( char *, const char *, int ); | ||
| 583 | #endif | ||
| 584 | |||
| 585 | #ifdef YY_NEED_STRLEN | ||
| 586 | static int yy_flex_strlen ( const char * ); | ||
| 587 | #endif | ||
| 588 | |||
| 589 | #ifndef YY_NO_INPUT | ||
| 590 | #ifdef __cplusplus | ||
| 591 | static int yyinput ( void ); | ||
| 592 | #else | ||
| 593 | static int input ( void ); | ||
| 594 | #endif | ||
| 595 | |||
| 596 | #endif | ||
| 597 | |||
| 598 | /* Amount of stuff to slurp up with each read. */ | ||
| 599 | #ifndef YY_READ_BUF_SIZE | ||
| 600 | #ifdef __ia64__ | ||
| 601 | /* On IA-64, the buffer size is 16k, not 8k */ | ||
| 602 | #define YY_READ_BUF_SIZE 16384 | ||
| 603 | #else | ||
| 604 | #define YY_READ_BUF_SIZE 8192 | ||
| 605 | #endif /* __ia64__ */ | ||
| 606 | #endif | ||
| 607 | |||
| 608 | /* Copy whatever the last rule matched to the standard output. */ | ||
| 609 | #ifndef ECHO | ||
| 610 | /* This used to be an fputs(), but since the string might contain NUL's, | ||
| 611 | * we now use fwrite(). | ||
| 612 | */ | ||
| 613 | #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) | ||
| 614 | #endif | ||
| 615 | |||
| 616 | /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, | ||
| 617 | * is returned in "result". | ||
| 618 | */ | ||
| 619 | #ifndef YY_INPUT | ||
| 620 | #define YY_INPUT(buf,result,max_size) \ | ||
| 621 | if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ | ||
| 622 | { \ | ||
| 623 | int c = '*'; \ | ||
| 624 | int n; \ | ||
| 625 | for ( n = 0; n < max_size && \ | ||
| 626 | (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ | ||
| 627 | buf[n] = (char) c; \ | ||
| 628 | if ( c == '\n' ) \ | ||
| 629 | buf[n++] = (char) c; \ | ||
| 630 | if ( c == EOF && ferror( yyin ) ) \ | ||
| 631 | YY_FATAL_ERROR( "input in flex scanner failed" ); \ | ||
| 632 | result = n; \ | ||
| 633 | } \ | ||
| 634 | else \ | ||
| 635 | { \ | ||
| 636 | errno=0; \ | ||
| 637 | while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \ | ||
| 638 | { \ | ||
| 639 | if( errno != EINTR) \ | ||
| 640 | { \ | ||
| 641 | YY_FATAL_ERROR( "input in flex scanner failed" ); \ | ||
| 642 | break; \ | ||
| 643 | } \ | ||
| 644 | errno=0; \ | ||
| 645 | clearerr(yyin); \ | ||
| 646 | } \ | ||
| 647 | }\ | ||
| 648 | \ | ||
| 649 | |||
| 650 | #endif | ||
| 651 | |||
| 652 | /* No semi-colon after return; correct usage is to write "yyterminate();" - | ||
| 653 | * we don't want an extra ';' after the "return" because that will cause | ||
| 654 | * some compilers to complain about unreachable statements. | ||
| 655 | */ | ||
| 656 | #ifndef yyterminate | ||
| 657 | #define yyterminate() return YY_NULL | ||
| 658 | #endif | ||
| 659 | |||
| 660 | /* Number of entries by which start-condition stack grows. */ | ||
| 661 | #ifndef YY_START_STACK_INCR | ||
| 662 | #define YY_START_STACK_INCR 25 | ||
| 663 | #endif | ||
| 664 | |||
| 665 | /* Report a fatal error. */ | ||
| 666 | #ifndef YY_FATAL_ERROR | ||
| 667 | #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) | ||
| 668 | #endif | ||
| 669 | |||
| 670 | /* end tables serialization structures and prototypes */ | ||
| 671 | |||
| 672 | /* Default declaration of generated scanner - a define so the user can | ||
| 673 | * easily add parameters. | ||
| 674 | */ | ||
| 675 | #ifndef YY_DECL | ||
| 676 | #define YY_DECL_IS_OURS 1 | ||
| 677 | |||
| 678 | extern int yylex (void); | ||
| 679 | |||
| 680 | #define YY_DECL int yylex (void) | ||
| 681 | #endif /* !YY_DECL */ | ||
| 682 | |||
| 683 | /* Code executed at the beginning of each rule, after yytext and yyleng | ||
| 684 | * have been set up. | ||
| 685 | */ | ||
| 686 | #ifndef YY_USER_ACTION | ||
| 687 | #define YY_USER_ACTION | ||
| 688 | #endif | ||
| 689 | |||
| 690 | /* Code executed at the end of each rule. */ | ||
| 691 | #ifndef YY_BREAK | ||
| 692 | #define YY_BREAK /*LINTED*/break; | ||
| 693 | #endif | ||
| 694 | |||
| 695 | #define YY_RULE_SETUP \ | ||
| 696 | YY_USER_ACTION | ||
| 697 | |||
| 698 | /** The main scanner function which does all the work. | ||
| 699 | */ | ||
| 700 | YY_DECL | ||
| 701 | { | ||
| 702 | yy_state_type yy_current_state; | ||
| 703 | char *yy_cp, *yy_bp; | ||
| 704 | int yy_act; | ||
| 705 | |||
| 706 | if ( !(yy_init) ) | ||
| 707 | { | ||
| 708 | (yy_init) = 1; | ||
| 709 | |||
| 710 | #ifdef YY_USER_INIT | ||
| 711 | YY_USER_INIT; | ||
| 712 | #endif | ||
| 713 | |||
| 714 | if ( ! (yy_start) ) | ||
| 715 | (yy_start) = 1; /* first start state */ | ||
| 716 | |||
| 717 | if ( ! yyin ) | ||
| 718 | yyin = stdin; | ||
| 719 | |||
| 720 | if ( ! yyout ) | ||
| 721 | yyout = stdout; | ||
| 722 | |||
| 723 | if ( ! YY_CURRENT_BUFFER ) { | ||
| 724 | yyensure_buffer_stack (); | ||
| 725 | YY_CURRENT_BUFFER_LVALUE = | ||
| 726 | yy_create_buffer( yyin, YY_BUF_SIZE ); | ||
| 727 | } | ||
| 728 | |||
| 729 | yy_load_buffer_state( ); | ||
| 730 | } | ||
| 731 | |||
| 732 | { | ||
| 733 | #line 17 "vmlex.l" | ||
| 734 | |||
| 735 | |||
| 736 | #line 736 "lex.yy.c" | ||
| 737 | |||
| 738 | while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ | ||
| 739 | { | ||
| 740 | yy_cp = (yy_c_buf_p); | ||
| 741 | |||
| 742 | /* Support of yytext. */ | ||
| 743 | *yy_cp = (yy_hold_char); | ||
| 744 | |||
| 745 | /* yy_bp points to the position in yy_ch_buf of the start of | ||
| 746 | * the current run. | ||
| 747 | */ | ||
| 748 | yy_bp = yy_cp; | ||
| 749 | |||
| 750 | yy_current_state = (yy_start); | ||
| 751 | yy_match: | ||
| 752 | do | ||
| 753 | { | ||
| 754 | YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; | ||
| 755 | if ( yy_accept[yy_current_state] ) | ||
| 756 | { | ||
| 757 | (yy_last_accepting_state) = yy_current_state; | ||
| 758 | (yy_last_accepting_cpos) = yy_cp; | ||
| 759 | } | ||
| 760 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) | ||
| 761 | { | ||
| 762 | yy_current_state = (int) yy_def[yy_current_state]; | ||
| 763 | if ( yy_current_state >= 106 ) | ||
| 764 | yy_c = yy_meta[yy_c]; | ||
| 765 | } | ||
| 766 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; | ||
| 767 | ++yy_cp; | ||
| 768 | } | ||
| 769 | while ( yy_base[yy_current_state] != 116 ); | ||
| 770 | |||
| 771 | yy_find_action: | ||
| 772 | yy_act = yy_accept[yy_current_state]; | ||
| 773 | if ( yy_act == 0 ) | ||
| 774 | { /* have to back up */ | ||
| 775 | yy_cp = (yy_last_accepting_cpos); | ||
| 776 | yy_current_state = (yy_last_accepting_state); | ||
| 777 | yy_act = yy_accept[yy_current_state]; | ||
| 778 | } | ||
| 779 | |||
| 780 | YY_DO_BEFORE_ACTION; | ||
| 781 | |||
| 782 | do_action: /* This label is used only to access EOF actions. */ | ||
| 783 | |||
| 784 | switch ( yy_act ) | ||
| 785 | { /* beginning of action switch */ | ||
| 786 | case 0: /* must back up */ | ||
| 787 | /* undo the effects of YY_DO_BEFORE_ACTION */ | ||
| 788 | *yy_cp = (yy_hold_char); | ||
| 789 | yy_cp = (yy_last_accepting_cpos); | ||
| 790 | yy_current_state = (yy_last_accepting_state); | ||
| 791 | goto yy_find_action; | ||
| 792 | |||
| 793 | case 1: | ||
| 794 | /* rule 1 can match eol */ | ||
| 795 | YY_RULE_SETUP | ||
| 796 | #line 19 "vmlex.l" | ||
| 797 | |||
| 798 | YY_BREAK | ||
| 799 | case 2: | ||
| 800 | /* rule 2 can match eol */ | ||
| 801 | YY_RULE_SETUP | ||
| 802 | #line 20 "vmlex.l" | ||
| 803 | |||
| 804 | YY_BREAK | ||
| 805 | case 3: | ||
| 806 | YY_RULE_SETUP | ||
| 807 | #line 21 "vmlex.l" | ||
| 808 | |||
| 809 | YY_BREAK | ||
| 810 | case 4: | ||
| 811 | YY_RULE_SETUP | ||
| 812 | #line 22 "vmlex.l" | ||
| 813 | { yylval = atoi(yytext); return T_INT; } | ||
| 814 | YY_BREAK | ||
| 815 | case 5: | ||
| 816 | YY_RULE_SETUP | ||
| 817 | #line 24 "vmlex.l" | ||
| 818 | { return T_COLON; } | ||
| 819 | YY_BREAK | ||
| 820 | case 6: | ||
| 821 | YY_RULE_SETUP | ||
| 822 | #line 26 "vmlex.l" | ||
| 823 | { return T_CALL; } | ||
| 824 | YY_BREAK | ||
| 825 | case 7: | ||
| 826 | YY_RULE_SETUP | ||
| 827 | #line 27 "vmlex.l" | ||
| 828 | { return T_RETURN; } | ||
| 829 | YY_BREAK | ||
| 830 | case 8: | ||
| 831 | YY_RULE_SETUP | ||
| 832 | #line 28 "vmlex.l" | ||
| 833 | { return T_LOADB; } | ||
| 834 | YY_BREAK | ||
| 835 | case 9: | ||
| 836 | YY_RULE_SETUP | ||
| 837 | #line 29 "vmlex.l" | ||
| 838 | { return T_STOREB; } | ||
| 839 | YY_BREAK | ||
| 840 | case 10: | ||
| 841 | YY_RULE_SETUP | ||
| 842 | #line 30 "vmlex.l" | ||
| 843 | { return T_SHIFT; } | ||
| 844 | YY_BREAK | ||
| 845 | case 11: | ||
| 846 | YY_RULE_SETUP | ||
| 847 | #line 32 "vmlex.l" | ||
| 848 | { return T_SET; } | ||
| 849 | YY_BREAK | ||
| 850 | case 12: | ||
| 851 | YY_RULE_SETUP | ||
| 852 | #line 33 "vmlex.l" | ||
| 853 | { return T_STOP; } | ||
| 854 | YY_BREAK | ||
| 855 | case 13: | ||
| 856 | YY_RULE_SETUP | ||
| 857 | #line 34 "vmlex.l" | ||
| 858 | { return T_LOAD; } | ||
| 859 | YY_BREAK | ||
| 860 | case 14: | ||
| 861 | YY_RULE_SETUP | ||
| 862 | #line 35 "vmlex.l" | ||
| 863 | { return T_STORE; } | ||
| 864 | YY_BREAK | ||
| 865 | case 15: | ||
| 866 | YY_RULE_SETUP | ||
| 867 | #line 36 "vmlex.l" | ||
| 868 | { return T_BLOAD; } | ||
| 869 | YY_BREAK | ||
| 870 | case 16: | ||
| 871 | YY_RULE_SETUP | ||
| 872 | #line 37 "vmlex.l" | ||
| 873 | { return T_BSTORE; } | ||
| 874 | YY_BREAK | ||
| 875 | case 17: | ||
| 876 | YY_RULE_SETUP | ||
| 877 | #line 38 "vmlex.l" | ||
| 878 | { return T_PUSH; } | ||
| 879 | YY_BREAK | ||
| 880 | case 18: | ||
| 881 | YY_RULE_SETUP | ||
| 882 | #line 39 "vmlex.l" | ||
| 883 | { return T_POP; } | ||
| 884 | YY_BREAK | ||
| 885 | case 19: | ||
| 886 | YY_RULE_SETUP | ||
| 887 | #line 40 "vmlex.l" | ||
| 888 | { return T_DUP; } | ||
| 889 | YY_BREAK | ||
| 890 | case 20: | ||
| 891 | YY_RULE_SETUP | ||
| 892 | #line 41 "vmlex.l" | ||
| 893 | { return T_INVERT; } | ||
| 894 | YY_BREAK | ||
| 895 | case 21: | ||
| 896 | YY_RULE_SETUP | ||
| 897 | #line 42 "vmlex.l" | ||
| 898 | { return T_ADD; } | ||
| 899 | YY_BREAK | ||
| 900 | case 22: | ||
| 901 | YY_RULE_SETUP | ||
| 902 | #line 43 "vmlex.l" | ||
| 903 | { return T_SUB; } | ||
| 904 | YY_BREAK | ||
| 905 | case 23: | ||
| 906 | YY_RULE_SETUP | ||
| 907 | #line 44 "vmlex.l" | ||
| 908 | { return T_MULT; } | ||
| 909 | YY_BREAK | ||
| 910 | case 24: | ||
| 911 | YY_RULE_SETUP | ||
| 912 | #line 45 "vmlex.l" | ||
| 913 | { return T_DIV; } | ||
| 914 | YY_BREAK | ||
| 915 | case 25: | ||
| 916 | YY_RULE_SETUP | ||
| 917 | #line 46 "vmlex.l" | ||
| 918 | { return T_COMPARE; } | ||
| 919 | YY_BREAK | ||
| 920 | case 26: | ||
| 921 | YY_RULE_SETUP | ||
| 922 | #line 47 "vmlex.l" | ||
| 923 | { return T_JUMP; } | ||
| 924 | YY_BREAK | ||
| 925 | case 27: | ||
| 926 | YY_RULE_SETUP | ||
| 927 | #line 48 "vmlex.l" | ||
| 928 | { return T_JUMP_YES; } | ||
| 929 | YY_BREAK | ||
| 930 | case 28: | ||
| 931 | YY_RULE_SETUP | ||
| 932 | #line 49 "vmlex.l" | ||
| 933 | { return T_JUMP_NO; } | ||
| 934 | YY_BREAK | ||
| 935 | case 29: | ||
| 936 | YY_RULE_SETUP | ||
| 937 | #line 50 "vmlex.l" | ||
| 938 | { return T_INPUT; } | ||
| 939 | YY_BREAK | ||
| 940 | case 30: | ||
| 941 | YY_RULE_SETUP | ||
| 942 | #line 51 "vmlex.l" | ||
| 943 | { return T_PRINT; } | ||
| 944 | YY_BREAK | ||
| 945 | case 31: | ||
| 946 | YY_RULE_SETUP | ||
| 947 | #line 52 "vmlex.l" | ||
| 948 | { return T_NOP; } | ||
| 949 | YY_BREAK | ||
| 950 | case YY_STATE_EOF(INITIAL): | ||
| 951 | #line 54 "vmlex.l" | ||
| 952 | { yyterminate(); } | ||
| 953 | YY_BREAK | ||
| 954 | case 32: | ||
| 955 | YY_RULE_SETUP | ||
| 956 | #line 56 "vmlex.l" | ||
| 957 | ECHO; | ||
| 958 | YY_BREAK | ||
| 959 | #line 959 "lex.yy.c" | ||
| 960 | |||
| 961 | case YY_END_OF_BUFFER: | ||
| 962 | { | ||
| 963 | /* Amount of text matched not including the EOB char. */ | ||
| 964 | int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; | ||
| 965 | |||
| 966 | /* Undo the effects of YY_DO_BEFORE_ACTION. */ | ||
| 967 | *yy_cp = (yy_hold_char); | ||
| 968 | YY_RESTORE_YY_MORE_OFFSET | ||
| 969 | |||
| 970 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) | ||
| 971 | { | ||
| 972 | /* We're scanning a new file or input source. It's | ||
| 973 | * possible that this happened because the user | ||
| 974 | * just pointed yyin at a new source and called | ||
| 975 | * yylex(). If so, then we have to assure | ||
| 976 | * consistency between YY_CURRENT_BUFFER and our | ||
| 977 | * globals. Here is the right place to do so, because | ||
| 978 | * this is the first action (other than possibly a | ||
| 979 | * back-up) that will match for the new input source. | ||
| 980 | */ | ||
| 981 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; | ||
| 982 | YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; | ||
| 983 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; | ||
| 984 | } | ||
| 985 | |||
| 986 | /* Note that here we test for yy_c_buf_p "<=" to the position | ||
| 987 | * of the first EOB in the buffer, since yy_c_buf_p will | ||
| 988 | * already have been incremented past the NUL character | ||
| 989 | * (since all states make transitions on EOB to the | ||
| 990 | * end-of-buffer state). Contrast this with the test | ||
| 991 | * in input(). | ||
| 992 | */ | ||
| 993 | if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) | ||
| 994 | { /* This was really a NUL. */ | ||
| 995 | yy_state_type yy_next_state; | ||
| 996 | |||
| 997 | (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; | ||
| 998 | |||
| 999 | yy_current_state = yy_get_previous_state( ); | ||
| 1000 | |||
| 1001 | /* Okay, we're now positioned to make the NUL | ||
| 1002 | * transition. We couldn't have | ||
| 1003 | * yy_get_previous_state() go ahead and do it | ||
| 1004 | * for us because it doesn't know how to deal | ||
| 1005 | * with the possibility of jamming (and we don't | ||
| 1006 | * want to build jamming into it because then it | ||
| 1007 | * will run more slowly). | ||
| 1008 | */ | ||
| 1009 | |||
| 1010 | yy_next_state = yy_try_NUL_trans( yy_current_state ); | ||
| 1011 | |||
| 1012 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; | ||
| 1013 | |||
| 1014 | if ( yy_next_state ) | ||
| 1015 | { | ||
| 1016 | /* Consume the NUL. */ | ||
| 1017 | yy_cp = ++(yy_c_buf_p); | ||
| 1018 | yy_current_state = yy_next_state; | ||
| 1019 | goto yy_match; | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | else | ||
| 1023 | { | ||
| 1024 | yy_cp = (yy_c_buf_p); | ||
| 1025 | goto yy_find_action; | ||
| 1026 | } | ||
| 1027 | } | ||
| 1028 | |||
| 1029 | else switch ( yy_get_next_buffer( ) ) | ||
| 1030 | { | ||
| 1031 | case EOB_ACT_END_OF_FILE: | ||
| 1032 | { | ||
| 1033 | (yy_did_buffer_switch_on_eof) = 0; | ||
| 1034 | |||
| 1035 | if ( yywrap( ) ) | ||
| 1036 | { | ||
| 1037 | /* Note: because we've taken care in | ||
| 1038 | * yy_get_next_buffer() to have set up | ||
| 1039 | * yytext, we can now set up | ||
| 1040 | * yy_c_buf_p so that if some total | ||
| 1041 | * hoser (like flex itself) wants to | ||
| 1042 | * call the scanner after we return the | ||
| 1043 | * YY_NULL, it'll still work - another | ||
| 1044 | * YY_NULL will get returned. | ||
| 1045 | */ | ||
| 1046 | (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; | ||
| 1047 | |||
| 1048 | yy_act = YY_STATE_EOF(YY_START); | ||
| 1049 | goto do_action; | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | else | ||
| 1053 | { | ||
| 1054 | if ( ! (yy_did_buffer_switch_on_eof) ) | ||
| 1055 | YY_NEW_FILE; | ||
| 1056 | } | ||
| 1057 | break; | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | case EOB_ACT_CONTINUE_SCAN: | ||
| 1061 | (yy_c_buf_p) = | ||
| 1062 | (yytext_ptr) + yy_amount_of_matched_text; | ||
| 1063 | |||
| 1064 | yy_current_state = yy_get_previous_state( ); | ||
| 1065 | |||
| 1066 | yy_cp = (yy_c_buf_p); | ||
| 1067 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; | ||
| 1068 | goto yy_match; | ||
| 1069 | |||
| 1070 | case EOB_ACT_LAST_MATCH: | ||
| 1071 | (yy_c_buf_p) = | ||
| 1072 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; | ||
| 1073 | |||
| 1074 | yy_current_state = yy_get_previous_state( ); | ||
| 1075 | |||
| 1076 | yy_cp = (yy_c_buf_p); | ||
| 1077 | yy_bp = (yytext_ptr) + YY_MORE_ADJ; | ||
| 1078 | goto yy_find_action; | ||
| 1079 | } | ||
| 1080 | break; | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | default: | ||
| 1084 | YY_FATAL_ERROR( | ||
| 1085 | "fatal flex scanner internal error--no action found" ); | ||
| 1086 | } /* end of action switch */ | ||
| 1087 | } /* end of scanning one token */ | ||
| 1088 | } /* end of user's declarations */ | ||
| 1089 | } /* end of yylex */ | ||
| 1090 | |||
| 1091 | /* yy_get_next_buffer - try to read in a new buffer | ||
| 1092 | * | ||
| 1093 | * Returns a code representing an action: | ||
| 1094 | * EOB_ACT_LAST_MATCH - | ||
| 1095 | * EOB_ACT_CONTINUE_SCAN - continue scanning from current position | ||
| 1096 | * EOB_ACT_END_OF_FILE - end of file | ||
| 1097 | */ | ||
| 1098 | static int yy_get_next_buffer (void) | ||
| 1099 | { | ||
| 1100 | char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; | ||
| 1101 | char *source = (yytext_ptr); | ||
| 1102 | int number_to_move, i; | ||
| 1103 | int ret_val; | ||
| 1104 | |||
| 1105 | if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) | ||
| 1106 | YY_FATAL_ERROR( | ||
| 1107 | "fatal flex scanner internal error--end of buffer missed" ); | ||
| 1108 | |||
| 1109 | if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) | ||
| 1110 | { /* Don't try to fill the buffer, so this is an EOF. */ | ||
| 1111 | if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) | ||
| 1112 | { | ||
| 1113 | /* We matched a single character, the EOB, so | ||
| 1114 | * treat this as a final EOF. | ||
| 1115 | */ | ||
| 1116 | return EOB_ACT_END_OF_FILE; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | else | ||
| 1120 | { | ||
| 1121 | /* We matched some text prior to the EOB, first | ||
| 1122 | * process it. | ||
| 1123 | */ | ||
| 1124 | return EOB_ACT_LAST_MATCH; | ||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | /* Try to read more data. */ | ||
| 1129 | |||
| 1130 | /* First move last chars to start of buffer. */ | ||
| 1131 | number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); | ||
| 1132 | |||
| 1133 | for ( i = 0; i < number_to_move; ++i ) | ||
| 1134 | *(dest++) = *(source++); | ||
| 1135 | |||
| 1136 | if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) | ||
| 1137 | /* don't do the read, it's not guaranteed to return an EOF, | ||
| 1138 | * just force an EOF | ||
| 1139 | */ | ||
| 1140 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; | ||
| 1141 | |||
| 1142 | else | ||
| 1143 | { | ||
| 1144 | int num_to_read = | ||
| 1145 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; | ||
| 1146 | |||
| 1147 | while ( num_to_read <= 0 ) | ||
| 1148 | { /* Not enough room in the buffer - grow it. */ | ||
| 1149 | |||
| 1150 | /* just a shorter name for the current buffer */ | ||
| 1151 | YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; | ||
| 1152 | |||
| 1153 | int yy_c_buf_p_offset = | ||
| 1154 | (int) ((yy_c_buf_p) - b->yy_ch_buf); | ||
| 1155 | |||
| 1156 | if ( b->yy_is_our_buffer ) | ||
| 1157 | { | ||
| 1158 | int new_size = b->yy_buf_size * 2; | ||
| 1159 | |||
| 1160 | if ( new_size <= 0 ) | ||
| 1161 | b->yy_buf_size += b->yy_buf_size / 8; | ||
| 1162 | else | ||
| 1163 | b->yy_buf_size *= 2; | ||
| 1164 | |||
| 1165 | b->yy_ch_buf = (char *) | ||
| 1166 | /* Include room in for 2 EOB chars. */ | ||
| 1167 | yyrealloc( (void *) b->yy_ch_buf, | ||
| 1168 | (yy_size_t) (b->yy_buf_size + 2) ); | ||
| 1169 | } | ||
| 1170 | else | ||
| 1171 | /* Can't grow it, we don't own it. */ | ||
| 1172 | b->yy_ch_buf = NULL; | ||
| 1173 | |||
| 1174 | if ( ! b->yy_ch_buf ) | ||
| 1175 | YY_FATAL_ERROR( | ||
| 1176 | "fatal error - scanner input buffer overflow" ); | ||
| 1177 | |||
| 1178 | (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; | ||
| 1179 | |||
| 1180 | num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - | ||
| 1181 | number_to_move - 1; | ||
| 1182 | |||
| 1183 | } | ||
| 1184 | |||
| 1185 | if ( num_to_read > YY_READ_BUF_SIZE ) | ||
| 1186 | num_to_read = YY_READ_BUF_SIZE; | ||
| 1187 | |||
| 1188 | /* Read in more data. */ | ||
| 1189 | YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), | ||
| 1190 | (yy_n_chars), num_to_read ); | ||
| 1191 | |||
| 1192 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | if ( (yy_n_chars) == 0 ) | ||
| 1196 | { | ||
| 1197 | if ( number_to_move == YY_MORE_ADJ ) | ||
| 1198 | { | ||
| 1199 | ret_val = EOB_ACT_END_OF_FILE; | ||
| 1200 | yyrestart( yyin ); | ||
| 1201 | } | ||
| 1202 | |||
| 1203 | else | ||
| 1204 | { | ||
| 1205 | ret_val = EOB_ACT_LAST_MATCH; | ||
| 1206 | YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = | ||
| 1207 | YY_BUFFER_EOF_PENDING; | ||
| 1208 | } | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | else | ||
| 1212 | ret_val = EOB_ACT_CONTINUE_SCAN; | ||
| 1213 | |||
| 1214 | if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { | ||
| 1215 | /* Extend the array by 50%, plus the number we really need. */ | ||
| 1216 | int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); | ||
| 1217 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( | ||
| 1218 | (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); | ||
| 1219 | if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) | ||
| 1220 | YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); | ||
| 1221 | /* "- 2" to take care of EOB's */ | ||
| 1222 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); | ||
| 1223 | } | ||
| 1224 | |||
| 1225 | (yy_n_chars) += number_to_move; | ||
| 1226 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; | ||
| 1227 | YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; | ||
| 1228 | |||
| 1229 | (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; | ||
| 1230 | |||
| 1231 | return ret_val; | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | /* yy_get_previous_state - get the state just before the EOB char was reached */ | ||
| 1235 | |||
| 1236 | static yy_state_type yy_get_previous_state (void) | ||
| 1237 | { | ||
| 1238 | yy_state_type yy_current_state; | ||
| 1239 | char *yy_cp; | ||
| 1240 | |||
| 1241 | yy_current_state = (yy_start); | ||
| 1242 | |||
| 1243 | for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) | ||
| 1244 | { | ||
| 1245 | YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); | ||
| 1246 | if ( yy_accept[yy_current_state] ) | ||
| 1247 | { | ||
| 1248 | (yy_last_accepting_state) = yy_current_state; | ||
| 1249 | (yy_last_accepting_cpos) = yy_cp; | ||
| 1250 | } | ||
| 1251 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) | ||
| 1252 | { | ||
| 1253 | yy_current_state = (int) yy_def[yy_current_state]; | ||
| 1254 | if ( yy_current_state >= 106 ) | ||
| 1255 | yy_c = yy_meta[yy_c]; | ||
| 1256 | } | ||
| 1257 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; | ||
| 1258 | } | ||
| 1259 | |||
| 1260 | return yy_current_state; | ||
| 1261 | } | ||
| 1262 | |||
| 1263 | /* yy_try_NUL_trans - try to make a transition on the NUL character | ||
| 1264 | * | ||
| 1265 | * synopsis | ||
| 1266 | * next_state = yy_try_NUL_trans( current_state ); | ||
| 1267 | */ | ||
| 1268 | static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) | ||
| 1269 | { | ||
| 1270 | int yy_is_jam; | ||
| 1271 | char *yy_cp = (yy_c_buf_p); | ||
| 1272 | |||
| 1273 | YY_CHAR yy_c = 1; | ||
| 1274 | if ( yy_accept[yy_current_state] ) | ||
| 1275 | { | ||
| 1276 | (yy_last_accepting_state) = yy_current_state; | ||
| 1277 | (yy_last_accepting_cpos) = yy_cp; | ||
| 1278 | } | ||
| 1279 | while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) | ||
| 1280 | { | ||
| 1281 | yy_current_state = (int) yy_def[yy_current_state]; | ||
| 1282 | if ( yy_current_state >= 106 ) | ||
| 1283 | yy_c = yy_meta[yy_c]; | ||
| 1284 | } | ||
| 1285 | yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; | ||
| 1286 | yy_is_jam = (yy_current_state == 105); | ||
| 1287 | |||
| 1288 | return yy_is_jam ? 0 : yy_current_state; | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | #ifndef YY_NO_UNPUT | ||
| 1292 | |||
| 1293 | static void yyunput (int c, char * yy_bp ) | ||
| 1294 | { | ||
| 1295 | char *yy_cp; | ||
| 1296 | |||
| 1297 | yy_cp = (yy_c_buf_p); | ||
| 1298 | |||
| 1299 | /* undo effects of setting up yytext */ | ||
| 1300 | *yy_cp = (yy_hold_char); | ||
| 1301 | |||
| 1302 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) | ||
| 1303 | { /* need to shift things up to make room */ | ||
| 1304 | /* +2 for EOB chars. */ | ||
| 1305 | int number_to_move = (yy_n_chars) + 2; | ||
| 1306 | char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ | ||
| 1307 | YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; | ||
| 1308 | char *source = | ||
| 1309 | &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; | ||
| 1310 | |||
| 1311 | while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) | ||
| 1312 | *--dest = *--source; | ||
| 1313 | |||
| 1314 | yy_cp += (int) (dest - source); | ||
| 1315 | yy_bp += (int) (dest - source); | ||
| 1316 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = | ||
| 1317 | (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; | ||
| 1318 | |||
| 1319 | if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) | ||
| 1320 | YY_FATAL_ERROR( "flex scanner push-back overflow" ); | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | *--yy_cp = (char) c; | ||
| 1324 | |||
| 1325 | (yytext_ptr) = yy_bp; | ||
| 1326 | (yy_hold_char) = *yy_cp; | ||
| 1327 | (yy_c_buf_p) = yy_cp; | ||
| 1328 | } | ||
| 1329 | |||
| 1330 | #endif | ||
| 1331 | |||
| 1332 | #ifndef YY_NO_INPUT | ||
| 1333 | #ifdef __cplusplus | ||
| 1334 | static int yyinput (void) | ||
| 1335 | #else | ||
| 1336 | static int input (void) | ||
| 1337 | #endif | ||
| 1338 | |||
| 1339 | { | ||
| 1340 | int c; | ||
| 1341 | |||
| 1342 | *(yy_c_buf_p) = (yy_hold_char); | ||
| 1343 | |||
| 1344 | if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) | ||
| 1345 | { | ||
| 1346 | /* yy_c_buf_p now points to the character we want to return. | ||
| 1347 | * If this occurs *before* the EOB characters, then it's a | ||
| 1348 | * valid NUL; if not, then we've hit the end of the buffer. | ||
| 1349 | */ | ||
| 1350 | if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) | ||
| 1351 | /* This was really a NUL. */ | ||
| 1352 | *(yy_c_buf_p) = '\0'; | ||
| 1353 | |||
| 1354 | else | ||
| 1355 | { /* need more input */ | ||
| 1356 | int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); | ||
| 1357 | ++(yy_c_buf_p); | ||
| 1358 | |||
| 1359 | switch ( yy_get_next_buffer( ) ) | ||
| 1360 | { | ||
| 1361 | case EOB_ACT_LAST_MATCH: | ||
| 1362 | /* This happens because yy_g_n_b() | ||
| 1363 | * sees that we've accumulated a | ||
| 1364 | * token and flags that we need to | ||
| 1365 | * try matching the token before | ||
| 1366 | * proceeding. But for input(), | ||
| 1367 | * there's no matching to consider. | ||
| 1368 | * So convert the EOB_ACT_LAST_MATCH | ||
| 1369 | * to EOB_ACT_END_OF_FILE. | ||
| 1370 | */ | ||
| 1371 | |||
| 1372 | /* Reset buffer status. */ | ||
| 1373 | yyrestart( yyin ); | ||
| 1374 | |||
| 1375 | /*FALLTHROUGH*/ | ||
| 1376 | |||
| 1377 | case EOB_ACT_END_OF_FILE: | ||
| 1378 | { | ||
| 1379 | if ( yywrap( ) ) | ||
| 1380 | return 0; | ||
| 1381 | |||
| 1382 | if ( ! (yy_did_buffer_switch_on_eof) ) | ||
| 1383 | YY_NEW_FILE; | ||
| 1384 | #ifdef __cplusplus | ||
| 1385 | return yyinput(); | ||
| 1386 | #else | ||
| 1387 | return input(); | ||
| 1388 | #endif | ||
| 1389 | } | ||
| 1390 | |||
| 1391 | case EOB_ACT_CONTINUE_SCAN: | ||
| 1392 | (yy_c_buf_p) = (yytext_ptr) + offset; | ||
| 1393 | break; | ||
| 1394 | } | ||
| 1395 | } | ||
| 1396 | } | ||
| 1397 | |||
| 1398 | c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ | ||
| 1399 | *(yy_c_buf_p) = '\0'; /* preserve yytext */ | ||
| 1400 | (yy_hold_char) = *++(yy_c_buf_p); | ||
| 1401 | |||
| 1402 | return c; | ||
| 1403 | } | ||
| 1404 | #endif /* ifndef YY_NO_INPUT */ | ||
| 1405 | |||
| 1406 | /** Immediately switch to a different input stream. | ||
| 1407 | * @param input_file A readable stream. | ||
| 1408 | * | ||
| 1409 | * @note This function does not reset the start condition to @c INITIAL . | ||
| 1410 | */ | ||
| 1411 | void yyrestart (FILE * input_file ) | ||
| 1412 | { | ||
| 1413 | |||
| 1414 | if ( ! YY_CURRENT_BUFFER ){ | ||
| 1415 | yyensure_buffer_stack (); | ||
| 1416 | YY_CURRENT_BUFFER_LVALUE = | ||
| 1417 | yy_create_buffer( yyin, YY_BUF_SIZE ); | ||
| 1418 | } | ||
| 1419 | |||
| 1420 | yy_init_buffer( YY_CURRENT_BUFFER, input_file ); | ||
| 1421 | yy_load_buffer_state( ); | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | /** Switch to a different input buffer. | ||
| 1425 | * @param new_buffer The new input buffer. | ||
| 1426 | * | ||
| 1427 | */ | ||
| 1428 | void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) | ||
| 1429 | { | ||
| 1430 | |||
| 1431 | /* TODO. We should be able to replace this entire function body | ||
| 1432 | * with | ||
| 1433 | * yypop_buffer_state(); | ||
| 1434 | * yypush_buffer_state(new_buffer); | ||
| 1435 | */ | ||
| 1436 | yyensure_buffer_stack (); | ||
| 1437 | if ( YY_CURRENT_BUFFER == new_buffer ) | ||
| 1438 | return; | ||
| 1439 | |||
| 1440 | if ( YY_CURRENT_BUFFER ) | ||
| 1441 | { | ||
| 1442 | /* Flush out information for old buffer. */ | ||
| 1443 | *(yy_c_buf_p) = (yy_hold_char); | ||
| 1444 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); | ||
| 1445 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | YY_CURRENT_BUFFER_LVALUE = new_buffer; | ||
| 1449 | yy_load_buffer_state( ); | ||
| 1450 | |||
| 1451 | /* We don't actually know whether we did this switch during | ||
| 1452 | * EOF (yywrap()) processing, but the only time this flag | ||
| 1453 | * is looked at is after yywrap() is called, so it's safe | ||
| 1454 | * to go ahead and always set it. | ||
| 1455 | */ | ||
| 1456 | (yy_did_buffer_switch_on_eof) = 1; | ||
| 1457 | } | ||
| 1458 | |||
| 1459 | static void yy_load_buffer_state (void) | ||
| 1460 | { | ||
| 1461 | (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; | ||
| 1462 | (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; | ||
| 1463 | yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; | ||
| 1464 | (yy_hold_char) = *(yy_c_buf_p); | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | /** Allocate and initialize an input buffer state. | ||
| 1468 | * @param file A readable stream. | ||
| 1469 | * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. | ||
| 1470 | * | ||
| 1471 | * @return the allocated buffer state. | ||
| 1472 | */ | ||
| 1473 | YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) | ||
| 1474 | { | ||
| 1475 | YY_BUFFER_STATE b; | ||
| 1476 | |||
| 1477 | b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); | ||
| 1478 | if ( ! b ) | ||
| 1479 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); | ||
| 1480 | |||
| 1481 | b->yy_buf_size = size; | ||
| 1482 | |||
| 1483 | /* yy_ch_buf has to be 2 characters longer than the size given because | ||
| 1484 | * we need to put in 2 end-of-buffer characters. | ||
| 1485 | */ | ||
| 1486 | b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); | ||
| 1487 | if ( ! b->yy_ch_buf ) | ||
| 1488 | YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); | ||
| 1489 | |||
| 1490 | b->yy_is_our_buffer = 1; | ||
| 1491 | |||
| 1492 | yy_init_buffer( b, file ); | ||
| 1493 | |||
| 1494 | return b; | ||
| 1495 | } | ||
| 1496 | |||
| 1497 | /** Destroy the buffer. | ||
| 1498 | * @param b a buffer created with yy_create_buffer() | ||
| 1499 | * | ||
| 1500 | */ | ||
| 1501 | void yy_delete_buffer (YY_BUFFER_STATE b ) | ||
| 1502 | { | ||
| 1503 | |||
| 1504 | if ( ! b ) | ||
| 1505 | return; | ||
| 1506 | |||
| 1507 | if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ | ||
| 1508 | YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; | ||
| 1509 | |||
| 1510 | if ( b->yy_is_our_buffer ) | ||
| 1511 | yyfree( (void *) b->yy_ch_buf ); | ||
| 1512 | |||
| 1513 | yyfree( (void *) b ); | ||
| 1514 | } | ||
| 1515 | |||
| 1516 | /* Initializes or reinitializes a buffer. | ||
| 1517 | * This function is sometimes called more than once on the same buffer, | ||
| 1518 | * such as during a yyrestart() or at EOF. | ||
| 1519 | */ | ||
| 1520 | static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) | ||
| 1521 | |||
| 1522 | { | ||
| 1523 | int oerrno = errno; | ||
| 1524 | |||
| 1525 | yy_flush_buffer( b ); | ||
| 1526 | |||
| 1527 | b->yy_input_file = file; | ||
| 1528 | b->yy_fill_buffer = 1; | ||
| 1529 | |||
| 1530 | /* If b is the current buffer, then yy_init_buffer was _probably_ | ||
| 1531 | * called from yyrestart() or through yy_get_next_buffer. | ||
| 1532 | * In that case, we don't want to reset the lineno or column. | ||
| 1533 | */ | ||
| 1534 | if (b != YY_CURRENT_BUFFER){ | ||
| 1535 | b->yy_bs_lineno = 1; | ||
| 1536 | b->yy_bs_column = 0; | ||
| 1537 | } | ||
| 1538 | |||
| 1539 | b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; | ||
| 1540 | |||
| 1541 | errno = oerrno; | ||
| 1542 | } | ||
| 1543 | |||
| 1544 | /** Discard all buffered characters. On the next scan, YY_INPUT will be called. | ||
| 1545 | * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. | ||
| 1546 | * | ||
| 1547 | */ | ||
| 1548 | void yy_flush_buffer (YY_BUFFER_STATE b ) | ||
| 1549 | { | ||
| 1550 | if ( ! b ) | ||
| 1551 | return; | ||
| 1552 | |||
| 1553 | b->yy_n_chars = 0; | ||
| 1554 | |||
| 1555 | /* We always need two end-of-buffer characters. The first causes | ||
| 1556 | * a transition to the end-of-buffer state. The second causes | ||
| 1557 | * a jam in that state. | ||
| 1558 | */ | ||
| 1559 | b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; | ||
| 1560 | b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; | ||
| 1561 | |||
| 1562 | b->yy_buf_pos = &b->yy_ch_buf[0]; | ||
| 1563 | |||
| 1564 | b->yy_at_bol = 1; | ||
| 1565 | b->yy_buffer_status = YY_BUFFER_NEW; | ||
| 1566 | |||
| 1567 | if ( b == YY_CURRENT_BUFFER ) | ||
| 1568 | yy_load_buffer_state( ); | ||
| 1569 | } | ||
| 1570 | |||
| 1571 | /** Pushes the new state onto the stack. The new state becomes | ||
| 1572 | * the current state. This function will allocate the stack | ||
| 1573 | * if necessary. | ||
| 1574 | * @param new_buffer The new state. | ||
| 1575 | * | ||
| 1576 | */ | ||
| 1577 | void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) | ||
| 1578 | { | ||
| 1579 | if (new_buffer == NULL) | ||
| 1580 | return; | ||
| 1581 | |||
| 1582 | yyensure_buffer_stack(); | ||
| 1583 | |||
| 1584 | /* This block is copied from yy_switch_to_buffer. */ | ||
| 1585 | if ( YY_CURRENT_BUFFER ) | ||
| 1586 | { | ||
| 1587 | /* Flush out information for old buffer. */ | ||
| 1588 | *(yy_c_buf_p) = (yy_hold_char); | ||
| 1589 | YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); | ||
| 1590 | YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); | ||
| 1591 | } | ||
| 1592 | |||
| 1593 | /* Only push if top exists. Otherwise, replace top. */ | ||
| 1594 | if (YY_CURRENT_BUFFER) | ||
| 1595 | (yy_buffer_stack_top)++; | ||
| 1596 | YY_CURRENT_BUFFER_LVALUE = new_buffer; | ||
| 1597 | |||
| 1598 | /* copied from yy_switch_to_buffer. */ | ||
| 1599 | yy_load_buffer_state( ); | ||
| 1600 | (yy_did_buffer_switch_on_eof) = 1; | ||
| 1601 | } | ||
| 1602 | |||
| 1603 | /** Removes and deletes the top of the stack, if present. | ||
| 1604 | * The next element becomes the new top. | ||
| 1605 | * | ||
| 1606 | */ | ||
| 1607 | void yypop_buffer_state (void) | ||
| 1608 | { | ||
| 1609 | if (!YY_CURRENT_BUFFER) | ||
| 1610 | return; | ||
| 1611 | |||
| 1612 | yy_delete_buffer(YY_CURRENT_BUFFER ); | ||
| 1613 | YY_CURRENT_BUFFER_LVALUE = NULL; | ||
| 1614 | if ((yy_buffer_stack_top) > 0) | ||
| 1615 | --(yy_buffer_stack_top); | ||
| 1616 | |||
| 1617 | if (YY_CURRENT_BUFFER) { | ||
| 1618 | yy_load_buffer_state( ); | ||
| 1619 | (yy_did_buffer_switch_on_eof) = 1; | ||
| 1620 | } | ||
| 1621 | } | ||
| 1622 | |||
| 1623 | /* Allocates the stack if it does not exist. | ||
| 1624 | * Guarantees space for at least one push. | ||
| 1625 | */ | ||
| 1626 | static void yyensure_buffer_stack (void) | ||
| 1627 | { | ||
| 1628 | yy_size_t num_to_alloc; | ||
| 1629 | |||
| 1630 | if (!(yy_buffer_stack)) { | ||
| 1631 | |||
| 1632 | /* First allocation is just for 2 elements, since we don't know if this | ||
| 1633 | * scanner will even need a stack. We use 2 instead of 1 to avoid an | ||
| 1634 | * immediate realloc on the next call. | ||
| 1635 | */ | ||
| 1636 | num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ | ||
| 1637 | (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc | ||
| 1638 | (num_to_alloc * sizeof(struct yy_buffer_state*) | ||
| 1639 | ); | ||
| 1640 | if ( ! (yy_buffer_stack) ) | ||
| 1641 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); | ||
| 1642 | |||
| 1643 | memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); | ||
| 1644 | |||
| 1645 | (yy_buffer_stack_max) = num_to_alloc; | ||
| 1646 | (yy_buffer_stack_top) = 0; | ||
| 1647 | return; | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ | ||
| 1651 | |||
| 1652 | /* Increase the buffer to prepare for a possible push. */ | ||
| 1653 | yy_size_t grow_size = 8 /* arbitrary grow size */; | ||
| 1654 | |||
| 1655 | num_to_alloc = (yy_buffer_stack_max) + grow_size; | ||
| 1656 | (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc | ||
| 1657 | ((yy_buffer_stack), | ||
| 1658 | num_to_alloc * sizeof(struct yy_buffer_state*) | ||
| 1659 | ); | ||
| 1660 | if ( ! (yy_buffer_stack) ) | ||
| 1661 | YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); | ||
| 1662 | |||
| 1663 | /* zero only the new slots.*/ | ||
| 1664 | memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); | ||
| 1665 | (yy_buffer_stack_max) = num_to_alloc; | ||
| 1666 | } | ||
| 1667 | } | ||
| 1668 | |||
| 1669 | /** Setup the input buffer state to scan directly from a user-specified character buffer. | ||
| 1670 | * @param base the character buffer | ||
| 1671 | * @param size the size in bytes of the character buffer | ||
| 1672 | * | ||
| 1673 | * @return the newly allocated buffer state object. | ||
| 1674 | */ | ||
| 1675 | YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) | ||
| 1676 | { | ||
| 1677 | YY_BUFFER_STATE b; | ||
| 1678 | |||
| 1679 | if ( size < 2 || | ||
| 1680 | base[size-2] != YY_END_OF_BUFFER_CHAR || | ||
| 1681 | base[size-1] != YY_END_OF_BUFFER_CHAR ) | ||
| 1682 | /* They forgot to leave room for the EOB's. */ | ||
| 1683 | return NULL; | ||
| 1684 | |||
| 1685 | b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); | ||
| 1686 | if ( ! b ) | ||
| 1687 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); | ||
| 1688 | |||
| 1689 | b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ | ||
| 1690 | b->yy_buf_pos = b->yy_ch_buf = base; | ||
| 1691 | b->yy_is_our_buffer = 0; | ||
| 1692 | b->yy_input_file = NULL; | ||
| 1693 | b->yy_n_chars = b->yy_buf_size; | ||
| 1694 | b->yy_is_interactive = 0; | ||
| 1695 | b->yy_at_bol = 1; | ||
| 1696 | b->yy_fill_buffer = 0; | ||
| 1697 | b->yy_buffer_status = YY_BUFFER_NEW; | ||
| 1698 | |||
| 1699 | yy_switch_to_buffer( b ); | ||
| 1700 | |||
| 1701 | return b; | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | /** Setup the input buffer state to scan a string. The next call to yylex() will | ||
| 1705 | * scan from a @e copy of @a str. | ||
| 1706 | * @param yystr a NUL-terminated string to scan | ||
| 1707 | * | ||
| 1708 | * @return the newly allocated buffer state object. | ||
| 1709 | * @note If you want to scan bytes that may contain NUL values, then use | ||
| 1710 | * yy_scan_bytes() instead. | ||
| 1711 | */ | ||
| 1712 | YY_BUFFER_STATE yy_scan_string (const char * yystr ) | ||
| 1713 | { | ||
| 1714 | |||
| 1715 | return yy_scan_bytes( yystr, (int) strlen(yystr) ); | ||
| 1716 | } | ||
| 1717 | |||
| 1718 | /** Setup the input buffer state to scan the given bytes. The next call to yylex() will | ||
| 1719 | * scan from a @e copy of @a bytes. | ||
| 1720 | * @param yybytes the byte buffer to scan | ||
| 1721 | * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. | ||
| 1722 | * | ||
| 1723 | * @return the newly allocated buffer state object. | ||
| 1724 | */ | ||
| 1725 | YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) | ||
| 1726 | { | ||
| 1727 | YY_BUFFER_STATE b; | ||
| 1728 | char *buf; | ||
| 1729 | yy_size_t n; | ||
| 1730 | int i; | ||
| 1731 | |||
| 1732 | /* Get memory for full buffer, including space for trailing EOB's. */ | ||
| 1733 | n = (yy_size_t) (_yybytes_len + 2); | ||
| 1734 | buf = (char *) yyalloc( n ); | ||
| 1735 | if ( ! buf ) | ||
| 1736 | YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); | ||
| 1737 | |||
| 1738 | for ( i = 0; i < _yybytes_len; ++i ) | ||
| 1739 | buf[i] = yybytes[i]; | ||
| 1740 | |||
| 1741 | buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; | ||
| 1742 | |||
| 1743 | b = yy_scan_buffer( buf, n ); | ||
| 1744 | if ( ! b ) | ||
| 1745 | YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); | ||
| 1746 | |||
| 1747 | /* It's okay to grow etc. this buffer, and we should throw it | ||
| 1748 | * away when we're done. | ||
| 1749 | */ | ||
| 1750 | b->yy_is_our_buffer = 1; | ||
| 1751 | |||
| 1752 | return b; | ||
| 1753 | } | ||
| 1754 | |||
| 1755 | #ifndef YY_EXIT_FAILURE | ||
| 1756 | #define YY_EXIT_FAILURE 2 | ||
| 1757 | #endif | ||
| 1758 | |||
| 1759 | static void yynoreturn yy_fatal_error (const char* msg ) | ||
| 1760 | { | ||
| 1761 | fprintf( stderr, "%s\n", msg ); | ||
| 1762 | exit( YY_EXIT_FAILURE ); | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | /* Redefine yyless() so it works in section 3 code. */ | ||
| 1766 | |||
| 1767 | #undef yyless | ||
| 1768 | #define yyless(n) \ | ||
| 1769 | do \ | ||
| 1770 | { \ | ||
| 1771 | /* Undo effects of setting up yytext. */ \ | ||
| 1772 | int yyless_macro_arg = (n); \ | ||
| 1773 | YY_LESS_LINENO(yyless_macro_arg);\ | ||
| 1774 | yytext[yyleng] = (yy_hold_char); \ | ||
| 1775 | (yy_c_buf_p) = yytext + yyless_macro_arg; \ | ||
| 1776 | (yy_hold_char) = *(yy_c_buf_p); \ | ||
| 1777 | *(yy_c_buf_p) = '\0'; \ | ||
| 1778 | yyleng = yyless_macro_arg; \ | ||
| 1779 | } \ | ||
| 1780 | while ( 0 ) | ||
| 1781 | |||
| 1782 | /* Accessor methods (get/set functions) to struct members. */ | ||
| 1783 | |||
| 1784 | /** Get the current line number. | ||
| 1785 | * | ||
| 1786 | */ | ||
| 1787 | int yyget_lineno (void) | ||
| 1788 | { | ||
| 1789 | |||
| 1790 | return yylineno; | ||
| 1791 | } | ||
| 1792 | |||
| 1793 | /** Get the input stream. | ||
| 1794 | * | ||
| 1795 | */ | ||
| 1796 | FILE *yyget_in (void) | ||
| 1797 | { | ||
| 1798 | return yyin; | ||
| 1799 | } | ||
| 1800 | |||
| 1801 | /** Get the output stream. | ||
| 1802 | * | ||
| 1803 | */ | ||
| 1804 | FILE *yyget_out (void) | ||
| 1805 | { | ||
| 1806 | return yyout; | ||
| 1807 | } | ||
| 1808 | |||
| 1809 | /** Get the length of the current token. | ||
| 1810 | * | ||
| 1811 | */ | ||
| 1812 | int yyget_leng (void) | ||
| 1813 | { | ||
| 1814 | return yyleng; | ||
| 1815 | } | ||
| 1816 | |||
| 1817 | /** Get the current token. | ||
| 1818 | * | ||
| 1819 | */ | ||
| 1820 | |||
| 1821 | char *yyget_text (void) | ||
| 1822 | { | ||
| 1823 | return yytext; | ||
| 1824 | } | ||
| 1825 | |||
| 1826 | /** Set the current line number. | ||
| 1827 | * @param _line_number line number | ||
| 1828 | * | ||
| 1829 | */ | ||
| 1830 | void yyset_lineno (int _line_number ) | ||
| 1831 | { | ||
| 1832 | |||
| 1833 | yylineno = _line_number; | ||
| 1834 | } | ||
| 1835 | |||
| 1836 | /** Set the input stream. This does not discard the current | ||
| 1837 | * input buffer. | ||
| 1838 | * @param _in_str A readable stream. | ||
| 1839 | * | ||
| 1840 | * @see yy_switch_to_buffer | ||
| 1841 | */ | ||
| 1842 | void yyset_in (FILE * _in_str ) | ||
| 1843 | { | ||
| 1844 | yyin = _in_str ; | ||
| 1845 | } | ||
| 1846 | |||
| 1847 | void yyset_out (FILE * _out_str ) | ||
| 1848 | { | ||
| 1849 | yyout = _out_str ; | ||
| 1850 | } | ||
| 1851 | |||
| 1852 | int yyget_debug (void) | ||
| 1853 | { | ||
| 1854 | return yy_flex_debug; | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | void yyset_debug (int _bdebug ) | ||
| 1858 | { | ||
| 1859 | yy_flex_debug = _bdebug ; | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | static int yy_init_globals (void) | ||
| 1863 | { | ||
| 1864 | /* Initialization is the same as for the non-reentrant scanner. | ||
| 1865 | * This function is called from yylex_destroy(), so don't allocate here. | ||
| 1866 | */ | ||
| 1867 | |||
| 1868 | (yy_buffer_stack) = NULL; | ||
| 1869 | (yy_buffer_stack_top) = 0; | ||
| 1870 | (yy_buffer_stack_max) = 0; | ||
| 1871 | (yy_c_buf_p) = NULL; | ||
| 1872 | (yy_init) = 0; | ||
| 1873 | (yy_start) = 0; | ||
| 1874 | |||
| 1875 | /* Defined in main.c */ | ||
| 1876 | #ifdef YY_STDINIT | ||
| 1877 | yyin = stdin; | ||
| 1878 | yyout = stdout; | ||
| 1879 | #else | ||
| 1880 | yyin = NULL; | ||
| 1881 | yyout = NULL; | ||
| 1882 | #endif | ||
| 1883 | |||
| 1884 | /* For future reference: Set errno on error, since we are called by | ||
| 1885 | * yylex_init() | ||
| 1886 | */ | ||
| 1887 | return 0; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | /* yylex_destroy is for both reentrant and non-reentrant scanners. */ | ||
| 1891 | int yylex_destroy (void) | ||
| 1892 | { | ||
| 1893 | |||
| 1894 | /* Pop the buffer stack, destroying each element. */ | ||
| 1895 | while(YY_CURRENT_BUFFER){ | ||
| 1896 | yy_delete_buffer( YY_CURRENT_BUFFER ); | ||
| 1897 | YY_CURRENT_BUFFER_LVALUE = NULL; | ||
| 1898 | yypop_buffer_state(); | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | /* Destroy the stack itself. */ | ||
| 1902 | yyfree((yy_buffer_stack) ); | ||
| 1903 | (yy_buffer_stack) = NULL; | ||
| 1904 | |||
| 1905 | /* Reset the globals. This is important in a non-reentrant scanner so the next time | ||
| 1906 | * yylex() is called, initialization will occur. */ | ||
| 1907 | yy_init_globals( ); | ||
| 1908 | |||
| 1909 | return 0; | ||
| 1910 | } | ||
| 1911 | |||
| 1912 | /* | ||
| 1913 | * Internal utility routines. | ||
| 1914 | */ | ||
| 1915 | |||
| 1916 | #ifndef yytext_ptr | ||
| 1917 | static void yy_flex_strncpy (char* s1, const char * s2, int n ) | ||
| 1918 | { | ||
| 1919 | |||
| 1920 | int i; | ||
| 1921 | for ( i = 0; i < n; ++i ) | ||
| 1922 | s1[i] = s2[i]; | ||
| 1923 | } | ||
| 1924 | #endif | ||
| 1925 | |||
| 1926 | #ifdef YY_NEED_STRLEN | ||
| 1927 | static int yy_flex_strlen (const char * s ) | ||
| 1928 | { | ||
| 1929 | int n; | ||
| 1930 | for ( n = 0; s[n]; ++n ) | ||
| 1931 | ; | ||
| 1932 | |||
| 1933 | return n; | ||
| 1934 | } | ||
| 1935 | #endif | ||
| 1936 | |||
| 1937 | void *yyalloc (yy_size_t size ) | ||
| 1938 | { | ||
| 1939 | return malloc(size); | ||
| 1940 | } | ||
| 1941 | |||
| 1942 | void *yyrealloc (void * ptr, yy_size_t size ) | ||
| 1943 | { | ||
| 1944 | |||
| 1945 | /* The cast to (char *) in the following accommodates both | ||
| 1946 | * implementations that use char* generic pointers, and those | ||
| 1947 | * that use void* generic pointers. It works with the latter | ||
| 1948 | * because both ANSI C and C++ allow castless assignment from | ||
| 1949 | * any pointer type to void*, and deal with argument conversions | ||
| 1950 | * as though doing an assignment. | ||
| 1951 | */ | ||
| 1952 | return realloc(ptr, size); | ||
| 1953 | } | ||
| 1954 | |||
| 1955 | void yyfree (void * ptr ) | ||
| 1956 | { | ||
| 1957 | free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ | ||
| 1958 | } | ||
| 1959 | |||
| 1960 | #define YYTABLES_NAME "yytables" | ||
| 1961 | |||
| 1962 | #line 56 "vmlex.l" | ||
| 1963 | |||
| 1964 | |||
diff --git a/vendor/vm/vm/main.c b/vendor/vm/vm/main.c new file mode 100644 index 0000000..0c24238 --- /dev/null +++ b/vendor/vm/vm/main.c | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #include "vm.h" | ||
| 2 | #include "vmparse.tab.h" | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | |||
| 6 | extern FILE *yyin; | ||
| 7 | int need_close = 0; | ||
| 8 | |||
| 9 | int yyparse(); | ||
| 10 | |||
| 11 | void milan_error(char const * msg) | ||
| 12 | { | ||
| 13 | if(need_close) | ||
| 14 | fclose(yyin); | ||
| 15 | |||
| 16 | fprintf(stderr, msg); | ||
| 17 | putc('\n', stderr); | ||
| 18 | exit(1); | ||
| 19 | } | ||
| 20 | |||
| 21 | int main(int argc, char **argv) | ||
| 22 | { | ||
| 23 | if(argc < 2) { | ||
| 24 | yyin = stdin; | ||
| 25 | printf("Reading input from stdin\n"); | ||
| 26 | } | ||
| 27 | else { | ||
| 28 | yyin = fopen(argv[1], "rt"); | ||
| 29 | if(!yyin) { | ||
| 30 | printf("Unable to read %s\n", argv[1]); | ||
| 31 | return 1; | ||
| 32 | } | ||
| 33 | |||
| 34 | need_close = 1; | ||
| 35 | printf("Reading input from %s\n", argv[1]); | ||
| 36 | } | ||
| 37 | |||
| 38 | if(0 == yyparse()) { | ||
| 39 | run(); | ||
| 40 | } | ||
| 41 | |||
| 42 | if(need_close) { | ||
| 43 | fclose(yyin); | ||
| 44 | } | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
diff --git a/vendor/vm/vm/test/bop1.ms b/vendor/vm/vm/test/bop1.ms new file mode 100644 index 0000000..11cbf4f --- /dev/null +++ b/vendor/vm/vm/test/bop1.ms | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | 4: STOP | ||
| 2 | 1: PUSH 20 | ||
| 3 | 2: ADD | ||
| 4 | 3: PRINT | ||
| 5 | 0: PUSH 10 | ||
| 6 | 2: MULT | ||
diff --git a/vendor/vm/vm/test/bop2.ms b/vendor/vm/vm/test/bop2.ms new file mode 100644 index 0000000..3a1e004 --- /dev/null +++ b/vendor/vm/vm/test/bop2.ms | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | 0: PUSH 10 | ||
| 2 | 1: PUSH -1 | ||
| 3 | 2: BSTORE 2 | ||
| 4 | 3: PUSH 0 | ||
| 5 | 4: BLOAD 1 | ||
| 6 | 5: PRINT | ||
| 7 | 6: STOP | ||
| 8 | |||
diff --git a/vendor/vm/vm/test/fib.ms b/vendor/vm/vm/test/fib.ms new file mode 100644 index 0000000..fe90ddd --- /dev/null +++ b/vendor/vm/vm/test/fib.ms | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | ; Âû÷èñëåíèå N-ãî ÷èñëà Ôèáîíà÷÷è | ||
| 2 | |||
| 3 | SET 0 0 ; Êîíñòàíòà 0 | ||
| 4 | SET 1 1 ; Êîíñòàíòà 1 | ||
| 5 | |||
| 6 | SET 1000 0 ; Ïåðåìåííàÿ n | ||
| 7 | SET 1001 1 ; Ïåðåìåííàÿ a | ||
| 8 | SET 1002 1 ; Ïåðåìåííàÿ b | ||
| 9 | |||
| 10 | ; Ïðîãðàììà | ||
| 11 | |||
| 12 | 0: INPUT | ||
| 13 | 1: STORE 1000 ; n := READ | ||
| 14 | |||
| 15 | 2: LOAD 1000 | ||
| 16 | 3: LOAD 1 | ||
| 17 | 4: COMPARE 3 ; IF n > 1 | ||
| 18 | 5: JUMP_NO 17 | ||
| 19 | |||
| 20 | 6: LOAD 1002 ; STACK <- b | ||
| 21 | 7: LOAD 1001 ; STACK <- a | ||
| 22 | 8: LOAD 1002 | ||
| 23 | 9: STORE 1001 ; a := b | ||
| 24 | 10: ADD | ||
| 25 | 11: STORE 1002 ; b := ñòàðîå_çíà÷åíèå_a + b | ||
| 26 | |||
| 27 | 12: LOAD 1000 | ||
| 28 | 13: LOAD 1 | ||
| 29 | 14: SUB | ||
| 30 | 15: STORE 1000 ; n := n - 1 | ||
| 31 | 16: JUMP 2 | ||
| 32 | |||
| 33 | 17: LOAD 1001 ; WRITE(a) | ||
| 34 | 18: PRINT | ||
| 35 | |||
| 36 | 19: STOP | ||
| 37 | |||
diff --git a/vendor/vm/vm/test/fib2.ms b/vendor/vm/vm/test/fib2.ms new file mode 100644 index 0000000..55f267e --- /dev/null +++ b/vendor/vm/vm/test/fib2.ms | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | SET 0 1 | ||
| 2 | SET 1 1 | ||
| 3 | |||
| 4 | 0: INPUT | ||
| 5 | 1: DUP | ||
| 6 | 2: PUSH 1 | ||
| 7 | 3: COMPARE 3 | ||
| 8 | 4: JUMP_NO 14 | ||
| 9 | 5: LOAD 1 | ||
| 10 | 6: LOAD 0 | ||
| 11 | 7: LOAD 1 | ||
| 12 | 8: STORE 0 | ||
| 13 | 9: ADD | ||
| 14 | 10: STORE 1 | ||
| 15 | 11: PUSH 1 | ||
| 16 | 12: SUB | ||
| 17 | 13: JUMP 1 | ||
| 18 | 14: LOAD 0 | ||
| 19 | 15: PRINT | ||
| 20 | 16: STOP | ||
| 21 | \ No newline at end of file | ||
diff --git a/vendor/vm/vm/vm.c b/vendor/vm/vm/vm.c new file mode 100644 index 0000000..eb7a9c9 --- /dev/null +++ b/vendor/vm/vm/vm.c | |||
| @@ -0,0 +1,458 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "vm.h" | ||
| 5 | |||
| 6 | void milan_error(); | ||
| 7 | |||
| 8 | command vm_program[MAX_PROGRAM_SIZE]; | ||
| 9 | |||
| 10 | int vm_memory[MAX_MEMORY_SIZE]; | ||
| 11 | int vm_stack[MAX_STACK_SIZE]; | ||
| 12 | |||
| 13 | unsigned int vm_stack_pointer = 0; | ||
| 14 | unsigned int vm_base_pointer = 0; | ||
| 15 | unsigned int vm_command_pointer = 0; | ||
| 16 | |||
| 17 | opcode_info opcodes_table[] = { | ||
| 18 | {"NOP", 0}, | ||
| 19 | {"STOP", 0}, | ||
| 20 | {"LOAD", 1}, | ||
| 21 | {"STORE", 1}, | ||
| 22 | {"BLOAD", 1}, | ||
| 23 | {"BSTORE", 1}, | ||
| 24 | {"PUSH", 1}, | ||
| 25 | {"POP", 0}, | ||
| 26 | {"DUP", 0}, | ||
| 27 | {"INVERT", 0}, | ||
| 28 | {"ADD", 0}, | ||
| 29 | {"SUB", 0}, | ||
| 30 | {"MULT", 0}, | ||
| 31 | {"DIV", 0}, | ||
| 32 | {"COMPARE", 1}, | ||
| 33 | {"JUMP", 1}, | ||
| 34 | {"JUMP_YES", 1}, | ||
| 35 | {"JUMP_NO", 1}, | ||
| 36 | {"INPUT", 0}, | ||
| 37 | {"PRINT", 0}, | ||
| 38 | |||
| 39 | {"CALL", 1}, | ||
| 40 | {"RETURN", 1}, | ||
| 41 | {"LOADB", 1}, | ||
| 42 | {"STOREB", 1}, | ||
| 43 | {"SHIFT", 1}, | ||
| 44 | }; | ||
| 45 | |||
| 46 | int opcodes_table_size = sizeof(opcodes_table) / sizeof(opcode_info); | ||
| 47 | |||
| 48 | typedef enum { | ||
| 49 | BAD_DATA_ADDRESS, | ||
| 50 | BAD_CODE_ADDRESS, | ||
| 51 | BAD_RELATION, | ||
| 52 | STACK_OVERFLOW, | ||
| 53 | STACK_UNDERFLOW, | ||
| 54 | DIVISION_BY_ZERO, | ||
| 55 | BAD_INPUT, | ||
| 56 | UNKNOWN_COMMAND | ||
| 57 | } runtime_error; | ||
| 58 | |||
| 59 | void vm_init() | ||
| 60 | { | ||
| 61 | vm_stack_pointer = 0; | ||
| 62 | vm_base_pointer = 0; | ||
| 63 | vm_command_pointer = 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | void vm_error(runtime_error error) | ||
| 67 | { | ||
| 68 | opcode_info* info; | ||
| 69 | |||
| 70 | switch(error) { | ||
| 71 | case BAD_DATA_ADDRESS: | ||
| 72 | fprintf(stderr, "Error: illegal data address\n"); | ||
| 73 | break; | ||
| 74 | |||
| 75 | case BAD_CODE_ADDRESS: | ||
| 76 | fprintf(stderr, "Error: illegal address in JUMP* instruction\n"); | ||
| 77 | break; | ||
| 78 | |||
| 79 | case BAD_RELATION: | ||
| 80 | fprintf(stderr, "Error: illegal comparison operator\n"); | ||
| 81 | break; | ||
| 82 | |||
| 83 | case STACK_OVERFLOW: | ||
| 84 | fprintf(stderr, "Error: stack overflow\n"); | ||
| 85 | break; | ||
| 86 | |||
| 87 | case STACK_UNDERFLOW: | ||
| 88 | fprintf(stderr, "Error: stack underflow\n"); | ||
| 89 | break; | ||
| 90 | |||
| 91 | case DIVISION_BY_ZERO: | ||
| 92 | fprintf(stderr, "Error: division by zero\n"); | ||
| 93 | break; | ||
| 94 | |||
| 95 | case BAD_INPUT: | ||
| 96 | fprintf(stderr, "Error: illegal input\n"); | ||
| 97 | break; | ||
| 98 | |||
| 99 | case UNKNOWN_COMMAND: | ||
| 100 | fprintf(stderr, "Error: unknown command, unable to execute\n"); | ||
| 101 | break; | ||
| 102 | |||
| 103 | default: | ||
| 104 | fprintf(stderr, "Error: runtime error %d\n", error); | ||
| 105 | } | ||
| 106 | |||
| 107 | fprintf(stderr, "Code:\n\n"); | ||
| 108 | |||
| 109 | info = operation_info(vm_program[vm_command_pointer].operation); | ||
| 110 | if(NULL == info) { | ||
| 111 | fprintf(stderr, "%d\t(%d)\t\t%d\n", vm_command_pointer, | ||
| 112 | vm_program[vm_command_pointer].operation, | ||
| 113 | vm_program[vm_command_pointer].arg); | ||
| 114 | } | ||
| 115 | else { | ||
| 116 | if(info->need_arg) { | ||
| 117 | fprintf(stderr, "\t%d\t%s\t\t%d\n", vm_command_pointer, info->name, | ||
| 118 | vm_program[vm_command_pointer].arg); | ||
| 119 | } | ||
| 120 | else { | ||
| 121 | fprintf(stderr, "\t%d\t%s\n", vm_command_pointer, info->name); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | milan_error("VM error"); | ||
| 126 | } | ||
| 127 | |||
| 128 | int vm_load(unsigned int address) | ||
| 129 | { | ||
| 130 | if(address < MAX_MEMORY_SIZE) { | ||
| 131 | return vm_memory[address]; | ||
| 132 | } | ||
| 133 | else { | ||
| 134 | vm_error(BAD_DATA_ADDRESS); | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | void vm_store(unsigned int address, int word) | ||
| 140 | { | ||
| 141 | if(address < MAX_MEMORY_SIZE) { | ||
| 142 | vm_memory[address] = word; | ||
| 143 | } | ||
| 144 | else { | ||
| 145 | vm_error(BAD_DATA_ADDRESS); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | int vm_read() | ||
| 150 | { | ||
| 151 | int n; | ||
| 152 | |||
| 153 | fprintf(stderr, "> "); fflush(stdout); | ||
| 154 | if(scanf("%d", &n)) { | ||
| 155 | return n; | ||
| 156 | } | ||
| 157 | else { | ||
| 158 | vm_error(BAD_INPUT); | ||
| 159 | return 0; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | void vm_write(int n) | ||
| 164 | { | ||
| 165 | fprintf(stderr, "%d\n", n); | ||
| 166 | } | ||
| 167 | |||
| 168 | int vm_pop() | ||
| 169 | { | ||
| 170 | if(vm_stack_pointer > 0) { | ||
| 171 | return vm_stack[--vm_stack_pointer]; | ||
| 172 | } | ||
| 173 | else { | ||
| 174 | vm_error(STACK_UNDERFLOW); | ||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | void vm_push(int word) | ||
| 180 | { | ||
| 181 | if(vm_stack_pointer < MAX_STACK_SIZE) { | ||
| 182 | vm_stack[vm_stack_pointer++] = word; | ||
| 183 | } | ||
| 184 | else { | ||
| 185 | vm_error(STACK_OVERFLOW); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | |||
| 189 | void vm_call(unsigned int address) | ||
| 190 | { | ||
| 191 | if (address >= MAX_PROGRAM_SIZE) | ||
| 192 | vm_error(BAD_CODE_ADDRESS); | ||
| 193 | |||
| 194 | vm_push(vm_command_pointer + 1); | ||
| 195 | vm_push(vm_base_pointer); | ||
| 196 | vm_base_pointer = vm_stack_pointer; | ||
| 197 | vm_command_pointer = address; | ||
| 198 | } | ||
| 199 | |||
| 200 | void vm_return(int shift) | ||
| 201 | { | ||
| 202 | vm_stack_pointer = vm_base_pointer; | ||
| 203 | |||
| 204 | vm_base_pointer = vm_pop(); | ||
| 205 | |||
| 206 | unsigned int return_address = vm_pop(); | ||
| 207 | if (return_address >= MAX_PROGRAM_SIZE) | ||
| 208 | vm_error(BAD_CODE_ADDRESS); | ||
| 209 | vm_command_pointer = return_address; | ||
| 210 | |||
| 211 | while (shift--) vm_pop(); | ||
| 212 | } | ||
| 213 | |||
| 214 | int vm_loadb(int offset) | ||
| 215 | { | ||
| 216 | if (offset < 0 && vm_base_pointer < - offset) vm_error(STACK_UNDERFLOW); | ||
| 217 | if (offset > 0 && vm_base_pointer > MAX_STACK_SIZE - offset) vm_error(STACK_OVERFLOW); | ||
| 218 | |||
| 219 | return vm_stack[vm_base_pointer + offset]; | ||
| 220 | } | ||
| 221 | |||
| 222 | void vm_storeb(int offset, int word) | ||
| 223 | { | ||
| 224 | if (offset < 0 && vm_base_pointer < - offset) vm_error(STACK_UNDERFLOW); | ||
| 225 | if (offset > 0 && vm_base_pointer > MAX_STACK_SIZE - offset) vm_error(STACK_OVERFLOW); | ||
| 226 | |||
| 227 | vm_stack[vm_base_pointer + offset] = word; | ||
| 228 | } | ||
| 229 | |||
| 230 | void vm_shift(int offset) | ||
| 231 | { | ||
| 232 | if (offset < 0 && vm_stack_pointer < - offset) vm_error(STACK_UNDERFLOW); | ||
| 233 | if (offset > 0 && vm_stack_pointer > MAX_STACK_SIZE - offset) vm_error(STACK_OVERFLOW); | ||
| 234 | |||
| 235 | vm_stack_pointer += offset; | ||
| 236 | } | ||
| 237 | |||
| 238 | int vm_run_command() | ||
| 239 | { | ||
| 240 | unsigned int index = vm_command_pointer; | ||
| 241 | |||
| 242 | operation op = vm_program[index].operation; | ||
| 243 | unsigned int arg = vm_program[index].arg; | ||
| 244 | int data; | ||
| 245 | |||
| 246 | // printf ("IP: %u\n", vm_command_pointer); | ||
| 247 | // printf ("BP: %u\n", vm_base_pointer); | ||
| 248 | // printf ("SP: %u\n", vm_stack_pointer); | ||
| 249 | // printf ("Stack:\n"); | ||
| 250 | // for (unsigned int i = 0; i < vm_stack_pointer; ++i) | ||
| 251 | // printf ("0x%04x: %u\n", vm_stack[i]); | ||
| 252 | // printf ("\n"); | ||
| 253 | |||
| 254 | switch(op) { | ||
| 255 | case NOP: | ||
| 256 | /* Ничего не делаем */ | ||
| 257 | break; | ||
| 258 | |||
| 259 | case STOP: | ||
| 260 | return 0; | ||
| 261 | break; | ||
| 262 | |||
| 263 | case LOAD: | ||
| 264 | vm_push(vm_load(arg)); | ||
| 265 | break; | ||
| 266 | |||
| 267 | case STORE: | ||
| 268 | vm_store(arg, vm_pop()); | ||
| 269 | break; | ||
| 270 | |||
| 271 | case BLOAD: | ||
| 272 | vm_push(vm_load(arg + vm_pop())); | ||
| 273 | break; | ||
| 274 | |||
| 275 | case BSTORE: | ||
| 276 | data = vm_pop(); | ||
| 277 | vm_store(arg + data, vm_pop()); | ||
| 278 | break; | ||
| 279 | |||
| 280 | case PUSH: | ||
| 281 | vm_push(arg); | ||
| 282 | break; | ||
| 283 | |||
| 284 | case POP: | ||
| 285 | vm_pop(); | ||
| 286 | break; | ||
| 287 | |||
| 288 | case DUP: | ||
| 289 | data = vm_pop(); | ||
| 290 | vm_push(data); | ||
| 291 | vm_push(data); | ||
| 292 | break; | ||
| 293 | |||
| 294 | case INVERT: | ||
| 295 | vm_push(-vm_pop()); | ||
| 296 | break; | ||
| 297 | |||
| 298 | case ADD: | ||
| 299 | data = vm_pop(); | ||
| 300 | vm_push(vm_pop() + data); | ||
| 301 | break; | ||
| 302 | |||
| 303 | case SUB: | ||
| 304 | data = vm_pop(); | ||
| 305 | vm_push(vm_pop() - data); | ||
| 306 | break; | ||
| 307 | |||
| 308 | case MULT: | ||
| 309 | data = vm_pop(); | ||
| 310 | vm_push(vm_pop() * data); | ||
| 311 | break; | ||
| 312 | |||
| 313 | case DIV: | ||
| 314 | data = vm_pop(); | ||
| 315 | if(0 == data) { | ||
| 316 | vm_error(DIVISION_BY_ZERO); | ||
| 317 | } | ||
| 318 | else { | ||
| 319 | vm_push(vm_pop() / data); | ||
| 320 | } | ||
| 321 | break; | ||
| 322 | |||
| 323 | case COMPARE: | ||
| 324 | data = vm_pop(); | ||
| 325 | switch(arg) { | ||
| 326 | case EQ: | ||
| 327 | vm_push((vm_pop() == data) ? 1 : 0); | ||
| 328 | break; | ||
| 329 | |||
| 330 | case NE: | ||
| 331 | vm_push((vm_pop() != data) ? 1 : 0); | ||
| 332 | break; | ||
| 333 | |||
| 334 | case LT: | ||
| 335 | vm_push((vm_pop() < data) ? 1 : 0); | ||
| 336 | break; | ||
| 337 | |||
| 338 | case GT: | ||
| 339 | vm_push((vm_pop() > data) ? 1 : 0); | ||
| 340 | break; | ||
| 341 | |||
| 342 | case LE: | ||
| 343 | vm_push((vm_pop() <= data) ? 1 : 0); | ||
| 344 | break; | ||
| 345 | |||
| 346 | case GE: | ||
| 347 | vm_push((vm_pop() >= data) ? 1 : 0); | ||
| 348 | break; | ||
| 349 | |||
| 350 | default: | ||
| 351 | vm_error(BAD_RELATION); | ||
| 352 | } | ||
| 353 | break; | ||
| 354 | |||
| 355 | case JUMP: | ||
| 356 | if(arg < MAX_PROGRAM_SIZE) { | ||
| 357 | vm_command_pointer = arg; | ||
| 358 | return 1; | ||
| 359 | } | ||
| 360 | else { | ||
| 361 | vm_error(BAD_CODE_ADDRESS); | ||
| 362 | } | ||
| 363 | |||
| 364 | break; | ||
| 365 | |||
| 366 | case JUMP_YES: | ||
| 367 | if(arg < MAX_PROGRAM_SIZE) { | ||
| 368 | data = vm_pop(); | ||
| 369 | if(data) { | ||
| 370 | vm_command_pointer = arg; | ||
| 371 | return 1; | ||
| 372 | } | ||
| 373 | } | ||
| 374 | else { | ||
| 375 | vm_error(BAD_CODE_ADDRESS); | ||
| 376 | } | ||
| 377 | break; | ||
| 378 | |||
| 379 | case JUMP_NO: | ||
| 380 | if(arg < MAX_PROGRAM_SIZE) { | ||
| 381 | data = vm_pop(); | ||
| 382 | if(!data) { | ||
| 383 | vm_command_pointer = arg; | ||
| 384 | return 1; | ||
| 385 | } | ||
| 386 | } | ||
| 387 | else { | ||
| 388 | vm_error(BAD_CODE_ADDRESS); | ||
| 389 | } | ||
| 390 | break; | ||
| 391 | |||
| 392 | case INPUT: | ||
| 393 | vm_push(vm_read()); | ||
| 394 | break; | ||
| 395 | |||
| 396 | case PRINT: | ||
| 397 | vm_write(vm_pop()); | ||
| 398 | break; | ||
| 399 | |||
| 400 | case CALL: | ||
| 401 | vm_call(arg); | ||
| 402 | return 1; | ||
| 403 | break; | ||
| 404 | |||
| 405 | case RETURN: | ||
| 406 | vm_return(arg); | ||
| 407 | return 1; | ||
| 408 | break; | ||
| 409 | |||
| 410 | case LOADB: | ||
| 411 | vm_push(vm_loadb(arg)); | ||
| 412 | break; | ||
| 413 | |||
| 414 | case STOREB: | ||
| 415 | vm_storeb(arg, vm_pop()); | ||
| 416 | break; | ||
| 417 | |||
| 418 | case SHIFT: | ||
| 419 | vm_shift(arg); | ||
| 420 | break; | ||
| 421 | |||
| 422 | default: | ||
| 423 | vm_error(UNKNOWN_COMMAND); | ||
| 424 | } | ||
| 425 | |||
| 426 | ++vm_command_pointer; | ||
| 427 | return 1; | ||
| 428 | } | ||
| 429 | |||
| 430 | void run() | ||
| 431 | { | ||
| 432 | vm_command_pointer = 0; | ||
| 433 | while(vm_command_pointer < MAX_PROGRAM_SIZE) { | ||
| 434 | if(!vm_run_command()) | ||
| 435 | break; | ||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | opcode_info* operation_info(operation op) | ||
| 440 | { | ||
| 441 | return (op < opcodes_table_size) ? &opcodes_table[op] : NULL; | ||
| 442 | } | ||
| 443 | |||
| 444 | void put_command(unsigned int address, operation op, int arg) | ||
| 445 | { | ||
| 446 | if(address < MAX_PROGRAM_SIZE) { | ||
| 447 | vm_program[address].operation = op; | ||
| 448 | vm_program[address].arg = arg; | ||
| 449 | } | ||
| 450 | else { | ||
| 451 | milan_error("Illegal address in put_command()"); | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | void set_mem(unsigned int address, int value) | ||
| 456 | { | ||
| 457 | vm_memory[address] = value; | ||
| 458 | } | ||
diff --git a/vendor/vm/vm/vm.h b/vendor/vm/vm/vm.h new file mode 100644 index 0000000..9b63cef --- /dev/null +++ b/vendor/vm/vm/vm.h | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | #ifndef _MILAN_VM_H | ||
| 2 | #define _MILAN_VM_H | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | /* Константы */ | ||
| 7 | |||
| 8 | /* Размер памяти команд */ | ||
| 9 | #define MAX_PROGRAM_SIZE 65536 | ||
| 10 | |||
| 11 | /* Размер памяти данных */ | ||
| 12 | #define MAX_MEMORY_SIZE 65536 | ||
| 13 | |||
| 14 | /* Размер стека */ | ||
| 15 | #define MAX_STACK_SIZE 8192 | ||
| 16 | |||
| 17 | /* Команды виртуальной машины */ | ||
| 18 | typedef enum { | ||
| 19 | NOP = 0, /* Нет операции */ | ||
| 20 | STOP, /* Остановка */ | ||
| 21 | LOAD, /* Загрузка слова из памяти данных */ | ||
| 22 | STORE, /* Запись слова в память данных */ | ||
| 23 | BLOAD, /* Загрузка слова из памяти данных с учётом смещения */ | ||
| 24 | BSTORE, /* Запись слова в память данныз с учётом смещения */ | ||
| 25 | PUSH, /* Заталкивание слова в стек */ | ||
| 26 | POP, /* Выталкивание слова из стека */ | ||
| 27 | DUP, /* Дублирование слова на вершине стека */ | ||
| 28 | INVERT, /* Изменение знака числа на вершине стека */ | ||
| 29 | ADD, /* Сложение */ | ||
| 30 | SUB, /* Вычитание */ | ||
| 31 | MULT, /* Умножение */ | ||
| 32 | DIV, /* Целочисленное деление */ | ||
| 33 | COMPARE, /* Сравнение */ | ||
| 34 | JUMP, /* Безусловный переход */ | ||
| 35 | JUMP_YES, /* Условный переход, если на вершине стека не 0 */ | ||
| 36 | JUMP_NO, /* Условный переход, если на вершине стека 0 */ | ||
| 37 | INPUT, /* Чтение слова со стандартного устройства ввода */ | ||
| 38 | PRINT, /* Запись слова на стандартное устройство вывода */ | ||
| 39 | |||
| 40 | CALL, /* Выхов функции */ | ||
| 41 | RETURN, /* Возвращение из функции */ | ||
| 42 | LOADB, /* Загрузка слова из стека относительно начала рамки с учётом смещения */ | ||
| 43 | STOREB, /* Запись слова в стек относительно начала рамки с учётом смещения */ | ||
| 44 | SHIFT, /* Сдвиг указателя стека */ | ||
| 45 | } operation; | ||
| 46 | |||
| 47 | /* Операции сравнения */ | ||
| 48 | typedef enum { | ||
| 49 | EQ, /* = */ | ||
| 50 | NE, /* !- */ | ||
| 51 | LT, /* < */ | ||
| 52 | GT, /* > */ | ||
| 53 | LE, /* <= */ | ||
| 54 | GE /* >= */ | ||
| 55 | } compare_type; | ||
| 56 | |||
| 57 | /* Структура ячейки памяти команд */ | ||
| 58 | typedef struct { | ||
| 59 | operation operation; /* Код команды */ | ||
| 60 | int arg; /* Аргумент */ | ||
| 61 | } command; | ||
| 62 | |||
| 63 | /* Информация о команде */ | ||
| 64 | typedef struct opcode_info { | ||
| 65 | char *name; /* Текстовое представление команды */ | ||
| 66 | int need_arg; /* Признак, равный 1, если команде нужен аргумент */ | ||
| 67 | } opcode_info; | ||
| 68 | |||
| 69 | /* Получение информации о команде с кодом op. | ||
| 70 | * Освобождать память, на которую указывает возвращаемый | ||
| 71 | * указатель, не нужно. | ||
| 72 | */ | ||
| 73 | |||
| 74 | opcode_info* operation_info(operation op); | ||
| 75 | |||
| 76 | /* Запись команды в память команд по адресу address. */ | ||
| 77 | |||
| 78 | void put_command(unsigned int address, operation op, int arg); | ||
| 79 | |||
| 80 | /* Запуск программы. | ||
| 81 | * | ||
| 82 | * Исполнение программы начинается с адреса 0 и заканчивается, | ||
| 83 | * когда встретится команда STOP или будет обнаружена ошибка | ||
| 84 | * времени исполнения. | ||
| 85 | */ | ||
| 86 | |||
| 87 | void run(); | ||
| 88 | |||
| 89 | /* Запись значения value в память данных по адресу address. */ | ||
| 90 | |||
| 91 | void set_mem(unsigned int address, int value); | ||
| 92 | |||
| 93 | #endif | ||
| 94 | |||
diff --git a/vendor/vm/vm/vmlex.l b/vendor/vm/vm/vmlex.l new file mode 100644 index 0000000..2f22e00 --- /dev/null +++ b/vendor/vm/vm/vmlex.l | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | %{ | ||
| 2 | #include "vmparse.tab.h" | ||
| 3 | #include <stdlib.h> | ||
| 4 | |||
| 5 | #ifndef __GNUC__ | ||
| 6 | #define YY_NO_UNISTD_H | ||
| 7 | #endif | ||
| 8 | %} | ||
| 9 | |||
| 10 | %option noyywrap | ||
| 11 | |||
| 12 | WHITESPACE [ \t]+ | ||
| 13 | EOL \n | ||
| 14 | INT -?[0-9]+ | ||
| 15 | COMMENT ;[^\n]*\n | ||
| 16 | |||
| 17 | %% | ||
| 18 | |||
| 19 | {EOL} | ||
| 20 | {COMMENT} | ||
| 21 | {WHITESPACE} | ||
| 22 | {INT} { yylval = atoi(yytext); return T_INT; } | ||
| 23 | |||
| 24 | : { return T_COLON; } | ||
| 25 | |||
| 26 | CALL { return T_CALL; } | ||
| 27 | RETURN { return T_RETURN; } | ||
| 28 | LOADB { return T_LOADB; } | ||
| 29 | STOREB { return T_STOREB; } | ||
| 30 | SHIFT { return T_SHIFT; } | ||
| 31 | |||
| 32 | SET { return T_SET; } | ||
| 33 | STOP { return T_STOP; } | ||
| 34 | LOAD { return T_LOAD; } | ||
| 35 | STORE { return T_STORE; } | ||
| 36 | BLOAD { return T_BLOAD; } | ||
| 37 | BSTORE { return T_BSTORE; } | ||
| 38 | PUSH { return T_PUSH; } | ||
| 39 | POP { return T_POP; } | ||
| 40 | DUP { return T_DUP; } | ||
| 41 | INVERT { return T_INVERT; } | ||
| 42 | ADD { return T_ADD; } | ||
| 43 | SUB { return T_SUB; } | ||
| 44 | MULT { return T_MULT; } | ||
| 45 | DIV { return T_DIV; } | ||
| 46 | COMPARE { return T_COMPARE; } | ||
| 47 | JUMP { return T_JUMP; } | ||
| 48 | JUMP_YES { return T_JUMP_YES; } | ||
| 49 | JUMP_NO { return T_JUMP_NO; } | ||
| 50 | INPUT { return T_INPUT; } | ||
| 51 | PRINT { return T_PRINT; } | ||
| 52 | NOP { return T_NOP; } | ||
| 53 | |||
| 54 | <<EOF>> { yyterminate(); } | ||
| 55 | |||
| 56 | %% | ||
diff --git a/vendor/vm/vm/vmparse.y b/vendor/vm/vm/vmparse.y new file mode 100644 index 0000000..4c019c5 --- /dev/null +++ b/vendor/vm/vm/vmparse.y | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | %{ | ||
| 2 | #include "vm.h" | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | |||
| 6 | #define YYSTYPE int | ||
| 7 | |||
| 8 | int yylex(); | ||
| 9 | void yyerror(char const *); | ||
| 10 | %} | ||
| 11 | |||
| 12 | %token T_INT | ||
| 13 | %token T_SET | ||
| 14 | %token T_NOP | ||
| 15 | %token T_STOP | ||
| 16 | %token T_LOAD | ||
| 17 | %token T_STORE | ||
| 18 | %token T_BLOAD | ||
| 19 | %token T_BSTORE | ||
| 20 | %token T_PUSH | ||
| 21 | %token T_POP | ||
| 22 | %token T_DUP | ||
| 23 | %token T_INVERT | ||
| 24 | %token T_ADD | ||
| 25 | %token T_SUB | ||
| 26 | %token T_MULT | ||
| 27 | %token T_DIV | ||
| 28 | %token T_COMPARE | ||
| 29 | %token T_JUMP | ||
| 30 | %token T_JUMP_YES | ||
| 31 | %token T_JUMP_NO | ||
| 32 | %token T_INPUT | ||
| 33 | %token T_PRINT | ||
| 34 | %token T_COLON | ||
| 35 | |||
| 36 | %token T_CALL | ||
| 37 | %token T_RETURN | ||
| 38 | %token T_LOADB | ||
| 39 | %token T_STOREB | ||
| 40 | %token T_SHIFT | ||
| 41 | |||
| 42 | %% | ||
| 43 | |||
| 44 | program : line program | ||
| 45 | | line | ||
| 46 | ; | ||
| 47 | |||
| 48 | line : T_INT T_COLON T_NOP { put_command($1, NOP, 0); } | ||
| 49 | | T_INT T_COLON T_STOP { put_command($1, STOP, 0); } | ||
| 50 | | T_INT T_COLON T_LOAD T_INT { put_command($1, LOAD, $4); } | ||
| 51 | | T_INT T_COLON T_STORE T_INT { put_command($1, STORE, $4); } | ||
| 52 | | T_INT T_COLON T_BLOAD T_INT { put_command($1, BLOAD, $4); } | ||
| 53 | | T_INT T_COLON T_BSTORE T_INT { put_command($1, BSTORE, $4); } | ||
| 54 | | T_INT T_COLON T_PUSH T_INT { put_command($1, PUSH, $4); } | ||
| 55 | | T_INT T_COLON T_POP { put_command($1, POP, 0); } | ||
| 56 | | T_INT T_COLON T_DUP { put_command($1, DUP, 0); } | ||
| 57 | | T_INT T_COLON T_INVERT { put_command($1, INVERT, 0); } | ||
| 58 | | T_INT T_COLON T_ADD { put_command($1, ADD, 0); } | ||
| 59 | | T_INT T_COLON T_SUB { put_command($1, SUB, 0); } | ||
| 60 | | T_INT T_COLON T_MULT { put_command($1, MULT, 0); } | ||
| 61 | | T_INT T_COLON T_DIV { put_command($1, DIV, 0); } | ||
| 62 | | T_INT T_COLON T_COMPARE T_INT { put_command($1, COMPARE, $4); } | ||
| 63 | | T_INT T_COLON T_JUMP T_INT { put_command($1, JUMP, $4); } | ||
| 64 | | T_INT T_COLON T_JUMP_YES T_INT { put_command($1, JUMP_YES, $4); } | ||
| 65 | | T_INT T_COLON T_JUMP_NO T_INT { put_command($1, JUMP_NO, $4); } | ||
| 66 | | T_INT T_COLON T_INPUT { put_command($1, INPUT, 0); } | ||
| 67 | | T_INT T_COLON T_PRINT { put_command($1, PRINT, 0); } | ||
| 68 | |||
| 69 | | T_INT T_COLON T_CALL T_INT { put_command($1, CALL, $4); } | ||
| 70 | | T_INT T_COLON T_RETURN T_INT { put_command($1, RETURN, $4); } | ||
| 71 | | T_INT T_COLON T_LOADB T_INT { put_command($1, LOADB, $4); } | ||
| 72 | | T_INT T_COLON T_STOREB T_INT { put_command($1, STOREB, $4); } | ||
| 73 | | T_INT T_COLON T_SHIFT T_INT { put_command($1, SHIFT, $4); } | ||
| 74 | |||
| 75 | | T_SET T_INT T_INT { set_mem($2, $3); } | ||
| 76 | ; | ||
| 77 | %% | ||
| 78 | |||
| 79 | void yyerror(char const *str) | ||
| 80 | { | ||
| 81 | printf("Error: %s\n", str); | ||
| 82 | } | ||
| 83 | |||
