Mercurial > ~dholland > hg > ag > index.cgi
view tests/agcl/ffcalc/good/ffcm-b.c @ 9:60b08b68c750
Switch to static inline as an expedient build fix.
Should probably set this up with working C99 inline but for the moment
I don't have the energy.
author | David A. Holland |
---|---|
date | Mon, 30 May 2022 23:56:45 -0400 |
parents | 13d2b8934445 |
children |
line wrap: on
line source
/* FOUR FUNCTION CALCULATOR: FFCALC.SYN */ /* * AnaGram, A System for Syntax Directed Programming * File generated by: ... * * AnaGram Parsing Engine * Copyright 1993-2002 Parsifal Software. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ #ifndef FFCM-B_H #include "ffcm-b.h" #endif #ifndef FFCM-B_H #error Mismatched header file #endif #include <ctype.h> #include <stdio.h> #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) #define CONTEXT ((PCB).cs[(PCB).ssx]) ffcm-b_pcb_type ffcm-b_pcb; #define PCB ffcm-b_pcb /* Line -, ffcm-b.syn */ /* -- EMBEDDED C ---------------------------------- */ double value[64]; /* registers */ void main(void) { ffcalc(); } #ifndef CONVERT_CASE static const char agCaseTable[31] = { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; static int agConvertCase(int c) { if (c >= 'a' && c <= 'z') return c ^= 0x20; if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0]; return c; } #define CONVERT_CASE(c) agConvertCase(c) #endif #ifndef TAB_SPACING #define TAB_SPACING 8 #endif #define ag_rp_1(x) (printf("%g\n",x)) static void ag_rp_2(double n, double x) { /* Line -, ffcm-b.syn */ printf("%c = %g\n",n+'A',value[n]=x); } #define ag_rp_3(x, t) (x+t) #define ag_rp_4(x, t) (x-t) #define ag_rp_5(t, f) (t*f) #define ag_rp_6(t, f) (t/f) #define ag_rp_7(n) (value[n]) #define ag_rp_8(x) (x) #define ag_rp_9(f) (-f) #define ag_rp_10(i, f) (i+f) #define ag_rp_11(f) (f) #define ag_rp_12(d) (d-'0') #define ag_rp_13(x, d) (10*x + d-'0') #define ag_rp_14(d) ((d-'0')/10.) #define ag_rp_15(d, f) ((d-'0' + f)/10.) #define ag_rp_16(c) (n_chars = 0, name[n_chars++]=c) #define ag_rp_17(c) (name[n_chars++]=c) #define READ_COUNTS #define WRITE_COUNTS #undef V #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) #undef VS #define VS(i) (PCB).vs[(PCB).ssx + i] #ifndef GET_CONTEXT #define GET_CONTEXT CONTEXT = (PCB).input_context #endif typedef enum { ag_action_1, ag_action_2, ag_action_3, ag_action_4, ag_action_5, ag_action_6, ag_action_7, ag_action_8, ag_action_9, ag_action_10, ag_action_11, ag_action_12 } ag_parser_action; #ifndef NULL_VALUE_INITIALIZER #define NULL_VALUE_INITIALIZER = { 0 } #endif static ffcm-b_vs_type const ag_null_value NULL_VALUE_INITIALIZER; static const unsigned char ag_rpx[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 4, 0, 5, 6, 7, 0, 8, 9, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 11, 12, 13, 14, 15, 16, 17 }; static const unsigned char ag_key_itt[] = { 0 }; static const unsigned short ag_key_pt[] = { 0 }; static const unsigned char ag_key_ch[] = { 0, 47, 65,255, 42,255, 47, 65, 84,255, 65,255, 47, 84,255, 47,255, 84, 255 }; static const unsigned char ag_key_act[] = { 0,3,3,4,3,4,3,3,3,4,3,4,3,3,4,3,4,3,4 }; static const unsigned char ag_key_parm[] = { 0, 26, 45, 0, 30, 0, 26, 45, 44, 0, 45, 0, 26, 44, 0, 26, 0, 44, 0 }; static const unsigned char ag_key_jmp[] = { 0, 0, 2, 0, 5, 0, 7, 9, 12, 0, 14, 0, 17, 19, 0, 21, 0, 23, 0 }; static const unsigned char ag_key_index[] = { 1, 4, 6, 10, 4, 4, 0, 12, 15, 15, 12, 0, 0, 15, 15, 17, 0, 0, 0, 0, 10, 0, 12, 12, 0, 15, 0, 15, 0, 17, 15, 0, 0, 15, 0, 1, 12, 15, 0, 0, 17, 17 }; static const unsigned char ag_key_ends[] = { 42,0, 68,68,0, 47,0, 42,0, 68,68,0, 79,0, 68,68,0, 42,0, 79,0, 42,0, 79,0, }; #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0) static const unsigned char ag_tcv[] = { 11, 38, 38, 38, 38, 38, 38, 38, 38, 38, 25, 41, 25, 25, 25, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 25, 38, 38, 38, 38, 38, 38, 38, 52, 51, 48, 46, 38, 47, 32, 49, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 38, 38, 38, 42, 38, 38, 38, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 38, 38, 38, 38, 38, 38, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38 }; #ifndef SYNTAX_ERROR #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ (PCB).error_message, (PCB).line, (PCB).column) #endif #ifndef FIRST_LINE #define FIRST_LINE 1 #endif #ifndef FIRST_COLUMN #define FIRST_COLUMN 1 #endif #ifndef PARSER_STACK_OVERFLOW #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ "\nParser stack overflow, line %d, column %d\n",\ (PCB).line, (PCB).column);} #endif #ifndef REDUCTION_TOKEN_ERROR #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ "\nReduction token error, line %d, column %d\n", \ (PCB).line, (PCB).column);} #endif typedef enum {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; #ifndef GET_INPUT #define GET_INPUT ((PCB).input_code = getchar()) #endif static int ag_look_ahead(void) { if ((PCB).rx < (PCB).fx) { return CONVERT_CASE((PCB).lab[(PCB).rx++]); } GET_INPUT; (PCB).fx++; return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code); } static void ag_get_key_word(int ag_k) { int save_index = (PCB).rx; const unsigned char *sp; int ag_ch; while (1) { switch (ag_key_act[ag_k]) { case ag_cf_end_key: sp = ag_key_ends + ag_key_jmp[ag_k]; do { if ((ag_ch = *sp++) == 0) { int ag_k1 = ag_key_parm[ag_k]; int ag_k2 = ag_key_pt[ag_k1]; if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail; (PCB).rx--; (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1 + 1]; return; } } while (ag_look_ahead() == ag_ch); goto ag_fail; case ag_end_key: sp = ag_key_ends + ag_key_jmp[ag_k]; do { if ((ag_ch = *sp++) == 0) { (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; return; } } while (ag_look_ahead() == ag_ch); case ag_no_match_key: ag_fail: (PCB).rx = save_index; return; case ag_cf_set_key: { int ag_k1 = ag_key_parm[ag_k]; int ag_k2 = ag_key_pt[ag_k1]; ag_k = ag_key_jmp[ag_k]; if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break; save_index = --(PCB).rx; (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1+1]; break; } case ag_set_key: save_index = (PCB).rx; (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; case ag_jmp_key: ag_k = ag_key_jmp[ag_k]; ag_ch = ag_look_ahead(); break; case ag_accept_key: (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; return; case ag_cf_accept_key: { int ag_k1 = ag_key_parm[ag_k]; int ag_k2 = ag_key_pt[ag_k1]; if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index; else { (PCB).rx--; (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1+1]; } return; } default: /* not reachable; here to suppress compiler warnings */ goto ag_fail; } if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++; if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) { (PCB).rx = save_index; return; } } } #ifndef AG_NEWLINE #define AG_NEWLINE 10 #endif #ifndef AG_RETURN #define AG_RETURN 13 #endif #ifndef AG_FORMFEED #define AG_FORMFEED 12 #endif #ifndef AG_TABCHAR #define AG_TABCHAR 9 #endif static void ag_track(void) { int ag_k = 0; while (ag_k < (PCB).rx) { int ag_ch = (PCB).lab[ag_k++]; switch (ag_ch) { case AG_NEWLINE: (PCB).column = 1, (PCB).line++; case AG_RETURN: case AG_FORMFEED: break; case AG_TABCHAR: (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); break; default: (PCB).column++; } } ag_k = 0; while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++]; (PCB).fx = ag_k; (PCB).rx = 0; } static void ag_prot(void) { int ag_k; ag_k = 128 - ++(PCB).btsx; if (ag_k <= (PCB).ssx) { (PCB).exit_flag = AG_STACK_ERROR_CODE; PARSER_STACK_OVERFLOW; return; } (PCB).bts[(PCB).btsx] = (PCB).sn; (PCB).bts[ag_k] = (PCB).ssx; (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; } static void ag_undo(void) { if ((PCB).drt == -1) return; while ((PCB).btsx) { int ag_k = 128 - (PCB).btsx; (PCB).sn = (PCB).bts[(PCB).btsx--]; (PCB).ssx = (PCB).bts[ag_k]; (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; } (PCB).token_number = (ffcm-b_token_type) (PCB).drt; (PCB).ssx = (PCB).dssx; (PCB).sn = (PCB).dsn; (PCB).drt = -1; } static const unsigned char ag_tstt[] = { 52,47,45,41,36,35,32,26,25,11,0,1,39,40, 52,51,49,48,47,46,42,41,38,36,35,32,30,25,0,28,29, 26,25,0,1, 52,47,45,41,36,35,32,16,11,0,2,3,4,5,6,8,9,10,12,14,17,19,20,23,31,43,50, 52,51,49,48,47,46,42,41,38,36,35,32,25,0, 30,0, 35,0,33, 51,49,48,47,46,44,41,35,32,26,25,0,34, 52,47,36,35,32,26,25,0,1,39,40, 52,47,36,35,32,26,25,0,1,39,40, 51,49,48,47,46,44,41,26,25,0,1,39,40, 52,47,36,35,32,0,2,3,19,20,23,31,43,50, 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, 52,47,36,35,32,26,25,0,1,39,40, 51,49,48,47,46,42,41,36,35,26,25,0,1,39,40, 49,48,0,21,22, 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, 49,48,47,46,42,41,0,13, 47,46,41,0,18,19, 41,0,7, 52,47,45,41,36,35,32,16,11,0,2,3,5,6,8,12,14,17,19,20,23,31,43,50, 11,0, 51,49,48,47,46,44,41,35,26,25,0,33, 35,0,33, 51,47,46,0,18,19,24, 52,47,36,35,32,26,25,0,1,39,40, 52,47,36,35,32,0,2,3,19,20,23,31,43,50, 52,47,36,35,32,26,25,0,1,39,40, 52,47,36,35,32,0,2,3,19,20,23,31,43,50, 47,46,44,0,15,18,19, 52,47,36,35,32,26,25,0,1,39,40, 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, 52,47,36,35,32,0,2,3,17,19,20,23,31,43,50, 52,47,36,35,32,26,25,0,1,39,40, 52,47,36,35,32,0,2,3,17,19,20,23,31,43,50, 52,47,45,41,36,35,32,26,25,11,0,1,39,40, 51,49,48,47,46,44,41,26,25,0,1,39,40, 36,26,25,0,1,39,40, 36,0,3,43, 47,46,41,0,18,19, 51,49,48,47,46,44,41,0,21,22, 51,49,48,47,46,44,41,0,21,22, }; static unsigned const char ag_astt[460] = { 8,8,8,8,8,8,8,1,1,8,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,1,7,1,1,1,9,5,3,1,1, 1,8,2,2,1,1,8,7,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9, 9,5,3,7,1,7,2,5,5,5,5,5,5,5,10,1,5,5,7,3,5,5,5,5,5,1,1,7,1,1,3,5,5,5,5,5,1, 1,7,1,1,3,5,5,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1,1,1,1,2,2,1, 7,1,2,1,1,1,1,1,1,1,1,5,5,5,5,5,1,1,7,1,1,3,5,5,5,5,5,5,5,10,10,1,1,7,1,1, 3,1,1,5,1,1,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,1,4,4,4,4,1,4,7,1,1,1,4,7,1,1,1, 7,3,1,1,1,8,2,2,1,1,5,7,1,1,1,1,3,1,1,1,1,1,1,1,1,1,3,7,4,4,4,4,4,4,4,1,4, 4,7,2,1,5,2,1,1,1,7,1,1,2,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1, 1,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1,1,1,1,1,7,1,1,1,5,5,5,5, 5,1,1,7,1,1,3,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,1,1,1,2,2,1,7,1,2,1,1,1,1,1,1, 1,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,5,5,5,5,5,5,5,1,1,5, 7,1,1,3,5,5,5,5,5,5,5,1,1,7,1,1,3,5,1,1,7,1,1,3,2,7,3,1,1,1,4,7,1,1,4,1,1, 4,4,4,4,7,1,1,4,1,1,4,4,4,4,7,1,1 }; static const unsigned char ag_pstt[] = { 3,3,3,3,3,3,3,1,2,3,0,2,2,3, 4,4,4,4,4,4,4,4,4,4,4,4,5,4,1,4,5, 1,56,58,56, 9,8,13,19,38,34,6,19,21,3,15,17,0,19,19,20,20,21,18,16,15,11,15,12,7,14,10, 25,25,25,25,25,25,25,25,25,25,25,25,25,27, 28,5, 22,6,33, 30,30,30,30,30,30,30,35,23,30,30,7,32, 57,57,57,57,57,1,2,8,2,2,65, 57,57,57,57,57,1,2,9,2,2,70, 57,57,57,57,57,57,57,1,2,10,2,2,68, 9,8,38,34,6,11,22,19,11,22,12,7,14,10, 9,8,38,34,6,12,15,19,24,15,11,15,12,7,14,10, 57,57,57,57,57,1,2,13,2,2,63, 57,57,57,57,57,57,57,39,39,1,2,14,2,2,61, 25,27,13,28,26, 9,8,38,34,6,16,15,19,29,15,11,15,12,7,14,10, 19,19,19,19,30,19,17,31, 8,33,9,18,34,32, 35,19,3, 9,8,13,19,38,34,6,19,7,20,15,17,19,19,5,18,16,15,11,15,12,7,14,10, 8,21, 36,36,36,36,36,36,36,22,36,36,22,37, 22,31,29, 36,8,33,24,34,32,21, 57,57,57,57,57,1,2,25,2,2,67, 9,8,38,34,6,26,18,19,11,18,12,7,14,10, 57,57,57,57,57,1,2,27,2,2,66, 9,8,38,34,6,28,17,19,11,17,12,7,14,10, 8,33,37,29,38,34,32, 57,57,57,57,57,1,2,30,2,2,60, 9,8,38,34,6,31,15,19,39,15,11,15,12,7,14,10, 9,8,38,34,6,32,40,19,40,11,40,12,7,14,10, 57,57,57,57,57,1,2,33,2,2,64, 9,8,38,34,6,34,41,19,41,11,41,12,7,14,10, 57,57,57,57,57,57,57,1,2,57,35,2,2,59, 57,57,57,57,57,57,57,1,2,36,2,2,69, 57,1,2,37,2,2,62, 38,38,11,14, 8,33,10,39,34,32, 15,25,27,15,15,15,15,40,28,26, 14,25,27,14,14,14,14,41,28,26, }; static const unsigned short ag_sbt[] = { 0, 14, 31, 35, 62, 76, 78, 81, 94, 105, 116, 129, 143, 159, 170, 185, 190, 206, 214, 220, 223, 247, 249, 261, 264, 271, 282, 296, 307, 321, 328, 339, 355, 370, 381, 396, 410, 423, 430, 434, 440, 450, 460 }; static const unsigned short ag_sbe[] = { 10, 28, 33, 44, 75, 77, 79, 92, 101, 112, 125, 134, 148, 166, 181, 187, 195, 212, 217, 221, 232, 248, 259, 262, 267, 278, 287, 303, 312, 324, 335, 344, 360, 377, 386, 406, 419, 426, 431, 437, 447, 457, 460 }; static const unsigned char ag_fl[] = { 2,0,1,2,1,2,0,1,2,1,3,4,1,1,3,3,1,3,3,1,1,3,2,1,1,2,0,1,3,3,0,1,2,2,1, 2,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0,1,2,2,2,2,2,2,2,2,2,2,2, 2 }; static const unsigned char ag_ptt[] = { 0, 6, 6, 8, 9, 9, 10, 10, 4, 5, 5, 5, 5, 12, 12, 12, 17, 17, 17, 20, 20, 20, 20, 1, 28, 28, 29, 29, 1, 50, 34, 34, 50, 50, 31, 31, 33, 33, 43, 43, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 37, 37, 39, 39, 40, 40, 7, 13, 3, 15, 14, 18, 19, 21, 22, 2, 24, 23 }; static void ag_ra(void) { switch(ag_rpx[(PCB).ag_ap]) { case 1: ag_rp_1(V(0,(double *))); break; case 2: ag_rp_2(V(0,(double *)), V(2,(double *))); break; case 3: V(0,(double *)) = ag_rp_3(V(0,(double *)), V(2,(double *))); break; case 4: V(0,(double *)) = ag_rp_4(V(0,(double *)), V(2,(double *))); break; case 5: V(0,(double *)) = ag_rp_5(V(0,(double *)), V(2,(double *))); break; case 6: V(0,(double *)) = ag_rp_6(V(0,(double *)), V(2,(double *))); break; case 7: V(0,(double *)) = ag_rp_7(V(0,(double *))); break; case 8: V(0,(double *)) = ag_rp_8(V(1,(double *))); break; case 9: V(0,(double *)) = ag_rp_9(V(1,(double *))); break; case 10: V(0,(double *)) = ag_rp_10(V(0,(double *)), V(2,(double *))); break; case 11: V(0,(double *)) = ag_rp_11(V(1,(double *))); break; case 12: V(0,(double *)) = ag_rp_12(V(0,(int *))); break; case 13: V(0,(double *)) = ag_rp_13(V(0,(double *)), V(1,(int *))); break; case 14: V(0,(double *)) = ag_rp_14(V(0,(int *))); break; case 15: V(0,(double *)) = ag_rp_15(V(0,(int *)), V(1,(double *))); break; case 16: V(0,(double *)) = ag_rp_16(V(0,(int *))); break; case 17: V(0,(double *)) = ag_rp_17(V(1,(int *))); break; } } #define TOKEN_NAMES ffcm-b_token_names const char *const ffcm-b_token_names[53] = { "calculator", "white space", "real", "name", "calculator", "calculation", "", "'\\n'", "", "", "", "eof", "expression", "'='", "\"ADD\"", "\"TO\"", "error", "term", "'+'", "'-'", "factor", "'*'", "'/'", "'('", "')'", "", "\"/*\"", "", "", "", "\"*/\"", "integer part", "'.'", "fraction part", "", "digit", "letter", "", "", "", "", "'\\n'", "'='", "name", "\"TO\"", "\"ADD\"", "'+'", "'-'", "'*'", "'/'", "real", "')'", "'('", }; #ifndef MISSING_FORMAT #define MISSING_FORMAT "Missing %s" #endif #ifndef UNEXPECTED_FORMAT #define UNEXPECTED_FORMAT "Unexpected %s" #endif #ifndef UNNAMED_TOKEN #define UNNAMED_TOKEN "input" #endif static void ag_diagnose(void) { int ag_snd = (PCB).sn; int ag_k = ag_sbt[ag_snd]; if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); } else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 && *TOKEN_NAMES[ag_tstt[ag_k]]) { sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); } else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); } else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') { char buf[20]; sprintf(buf, "\'%c\'", (char) (*(PCB).lab)); sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); } else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); (PCB).error_message = (PCB).ag_msg; } static int ag_action_1_r_proc(void); static int ag_action_2_r_proc(void); static int ag_action_3_r_proc(void); static int ag_action_4_r_proc(void); static int ag_action_1_s_proc(void); static int ag_action_3_s_proc(void); static int ag_action_1_proc(void); static int ag_action_2_proc(void); static int ag_action_3_proc(void); static int ag_action_4_proc(void); static int ag_action_5_proc(void); static int ag_action_6_proc(void); static int ag_action_7_proc(void); static int ag_action_8_proc(void); static int ag_action_9_proc(void); static int ag_action_10_proc(void); static int ag_action_11_proc(void); static int ag_action_8_proc(void); static int (*const ag_r_procs_scan[])(void) = { ag_action_1_r_proc, ag_action_2_r_proc, ag_action_3_r_proc, ag_action_4_r_proc }; static int (*const ag_s_procs_scan[])(void) = { ag_action_1_s_proc, ag_action_2_r_proc, ag_action_3_s_proc, ag_action_4_r_proc }; static int (*const ag_gt_procs_scan[])(void) = { ag_action_1_proc, ag_action_2_proc, ag_action_3_proc, ag_action_4_proc, ag_action_5_proc, ag_action_6_proc, ag_action_7_proc, ag_action_8_proc, ag_action_9_proc, ag_action_10_proc, ag_action_11_proc, ag_action_8_proc }; static int ag_action_1_er_proc(void); static int ag_action_2_er_proc(void); static int ag_action_3_er_proc(void); static int ag_action_4_er_proc(void); static int (*const ag_er_procs_scan[])(void) = { ag_action_1_er_proc, ag_action_2_er_proc, ag_action_3_er_proc, ag_action_4_er_proc }; static void ag_error_resynch(void) { int ag_k; int ag_ssx = (PCB).ssx; ag_diagnose(); SYNTAX_ERROR; if ((PCB).exit_flag != AG_RUNNING_CODE) return; while (1) { ag_k = ag_sbt[(PCB).sn]; while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; if (ag_tstt[ag_k] || (PCB).ssx == 0) break; (PCB).sn = (PCB).ss[--(PCB).ssx]; } if (ag_tstt[ag_k] == 0) { (PCB).sn = PCB.ss[(PCB).ssx = ag_ssx]; (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return; } ag_k = ag_sbt[(PCB).sn]; while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; (PCB).ag_ap = ag_pstt[ag_k]; (ag_er_procs_scan[ag_astt[ag_k]])(); while (1) { ag_k = ag_sbt[(PCB).sn]; while (ag_tstt[ag_k] != (unsigned char) (PCB).token_number && ag_tstt[ag_k]) ag_k++; if (ag_tstt[ag_k] && ag_astt[ag_k] != ag_action_10) break; if ((PCB).token_number == 11) {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} {(PCB).rx = 1; ag_track();} if ((PCB).rx < (PCB).fx) { (PCB).input_code = (PCB).lab[(PCB).rx++]; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} else { GET_INPUT; (PCB).lab[(PCB).fx++] = (PCB).input_code; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); (PCB).rx++; } if (ag_key_index[(PCB).sn]) { unsigned ag_k = ag_key_index[(PCB).sn]; int ag_ch = CONVERT_CASE((PCB).input_code); if (ag_ch < 255) { while (ag_key_ch[ag_k] < ag_ch) ag_k++; if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); } } } (PCB).rx = 0; } static int ag_action_10_proc(void) { int ag_t = (PCB).token_number; (PCB).btsx = 0, (PCB).drt = -1; do { ag_track(); if ((PCB).rx < (PCB).fx) { (PCB).input_code = (PCB).lab[(PCB).rx++]; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} else { GET_INPUT; (PCB).lab[(PCB).fx++] = (PCB).input_code; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); (PCB).rx++; } if (ag_key_index[(PCB).sn]) { unsigned ag_k = ag_key_index[(PCB).sn]; int ag_ch = CONVERT_CASE((PCB).input_code); if (ag_ch < 255) { while (ag_key_ch[ag_k] < ag_ch) ag_k++; if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); } } } while ((PCB).token_number == (ffcm-b_token_type) ag_t); (PCB).rx = 0; return 1; } static int ag_action_11_proc(void) { int ag_t = (PCB).token_number; (PCB).btsx = 0, (PCB).drt = -1; do { (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; (PCB).ssx--; ag_track(); ag_ra(); if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; (PCB).ssx++; if ((PCB).rx < (PCB).fx) { (PCB).input_code = (PCB).lab[(PCB).rx++]; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} else { GET_INPUT; (PCB).lab[(PCB).fx++] = (PCB).input_code; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); (PCB).rx++; } if (ag_key_index[(PCB).sn]) { unsigned ag_k = ag_key_index[(PCB).sn]; int ag_ch = CONVERT_CASE((PCB).input_code); if (ag_ch < 255) { while (ag_key_ch[ag_k] < ag_ch) ag_k++; if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); } } } while ((PCB).token_number == (ffcm-b_token_type) ag_t); (PCB).rx = 0; return 1; } static int ag_action_3_r_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; (PCB).btsx = 0, (PCB).drt = -1; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; ag_ra(); return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_3_s_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; (PCB).btsx = 0, (PCB).drt = -1; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; ag_ra(); return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_4_r_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; return 1; } static int ag_action_2_proc(void) { (PCB).btsx = 0, (PCB).drt = -1; if ((PCB).ssx >= 128) { (PCB).exit_flag = AG_STACK_ERROR_CODE; PARSER_STACK_OVERFLOW; } (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; (PCB).ss[(PCB).ssx] = (PCB).sn; (PCB).ssx++; (PCB).sn = (PCB).ag_ap; ag_track(); return 0; } static int ag_action_9_proc(void) { if ((PCB).drt == -1) { (PCB).drt=(PCB).token_number; (PCB).dssx=(PCB).ssx; (PCB).dsn=(PCB).sn; } ag_prot(); (PCB).vs[(PCB).ssx] = ag_null_value; (PCB).ss[(PCB).ssx] = (PCB).sn; (PCB).ssx++; (PCB).sn = (PCB).ag_ap; (PCB).rx = 0; return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_2_r_proc(void) { (PCB).ssx++; (PCB).sn = (PCB).ag_ap; return 0; } static int ag_action_7_proc(void) { --(PCB).ssx; (PCB).rx = 0; (PCB).exit_flag = AG_SUCCESS_CODE; return 0; } static int ag_action_1_proc(void) { ag_track(); (PCB).exit_flag = AG_SUCCESS_CODE; return 0; } static int ag_action_1_r_proc(void) { (PCB).exit_flag = AG_SUCCESS_CODE; return 0; } static int ag_action_1_s_proc(void) { (PCB).exit_flag = AG_SUCCESS_CODE; return 0; } static int ag_action_4_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; (PCB).btsx = 0, (PCB).drt = -1; (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; else (PCB).ss[(PCB).ssx] = (PCB).sn; ag_track(); while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; } return 0; } static int ag_action_3_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; (PCB).btsx = 0, (PCB).drt = -1; (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; else (PCB).ss[(PCB).ssx] = (PCB).sn; ag_track(); (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; ag_ra(); while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; } return 0; } static int ag_action_8_proc(void) { int ag_k = ag_sbt[(PCB).sn]; while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; if (ag_tstt[ag_k] == 0) ag_undo(); (PCB).rx = 0; ag_error_resynch(); return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_5_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap]; (PCB).btsx = 0, (PCB).drt = -1; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; else { (PCB).ss[(PCB).ssx] = (PCB).sn; } (PCB).rx = 0; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; ag_ra(); while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; } return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_6_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap]; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; if ((PCB).drt == -1) { (PCB).drt=(PCB).token_number; (PCB).dssx=(PCB).ssx; (PCB).dsn=(PCB).sn; } if (ag_sd) { (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; } else { ag_prot(); (PCB).vs[(PCB).ssx] = ag_null_value; (PCB).ss[(PCB).ssx] = (PCB).sn; } (PCB).rx = 0; while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; } return (PCB).exit_flag == AG_RUNNING_CODE; } static int ag_action_2_er_proc(void) { (PCB).btsx = 0, (PCB).drt = -1; (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; (PCB).ssx++; (PCB).sn = (PCB).ag_ap; return 0; } static int ag_action_1_er_proc(void) { (PCB).btsx = 0, (PCB).drt = -1; (PCB).exit_flag = AG_SUCCESS_CODE; return 0; } static int ag_action_4_er_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; (PCB).btsx = 0, (PCB).drt = -1; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; else (PCB).ss[(PCB).ssx] = (PCB).sn; while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; } return 0; } static int ag_action_3_er_proc(void) { int ag_sd = ag_fl[(PCB).ag_ap] - 1; (PCB).btsx = 0, (PCB).drt = -1; if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; else (PCB).ss[(PCB).ssx] = (PCB).sn; (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; ag_ra(); while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); (PCB).ag_ap = ag_pstt[ag_t1]; if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; } return 0; } void init_ffcm-b(void) { (PCB).rx = (PCB).fx = 0; (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; (PCB).exit_flag = AG_RUNNING_CODE; (PCB).line = FIRST_LINE; (PCB).column = FIRST_COLUMN; (PCB).btsx = 0, (PCB).drt = -1; } void ffcm-b(void) { init_ffcm-b(); (PCB).exit_flag = AG_RUNNING_CODE; while ((PCB).exit_flag == AG_RUNNING_CODE) { unsigned ag_t1 = ag_sbt[(PCB).sn]; if (ag_tstt[ag_t1]) { unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; if ((PCB).rx < (PCB).fx) { (PCB).input_code = (PCB).lab[(PCB).rx++]; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} else { GET_INPUT; (PCB).lab[(PCB).fx++] = (PCB).input_code; (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); (PCB).rx++; } if (ag_key_index[(PCB).sn]) { unsigned ag_k = ag_key_index[(PCB).sn]; int ag_ch = CONVERT_CASE((PCB).input_code); if (ag_ch < 255) { while (ag_key_ch[ag_k] < ag_ch) ag_k++; if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); } } do { unsigned ag_tx = (ag_t1 + ag_t2)/2; if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) ag_t1 = ag_tx + 1; else ag_t2 = ag_tx; } while (ag_t1 < ag_t2); if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) ag_t1 = ag_sbe[(PCB).sn]; } (PCB).ag_ap = ag_pstt[ag_t1]; (ag_gt_procs_scan[ag_astt[ag_t1]])(); } }