view tests/agcl/ffcalc/good/ffc-wa.cpp @ 20:bb115deb6fb2

Improve agfiles rule. (1) It didn't depend on $(AGCL) and it absolutely should have. (2) allow AGFORCE=1 to make it rebuild whether or not it looks out of date. (3) Document this.
author David A. Holland
date Mon, 13 Jun 2022 00:02:15 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
	   FOUR FUNCTION CALCULATOR: FFCALC.SYN
*/
#include "Number.h"

int Number::nCreated = 0;
char Number::buf[100];


/*
 * 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 FFC-WA_H
#include "ffc-wa.h"
#endif

#ifndef FFC-WA_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])



ffc-wa_pcb_type ffc-wa_pcb;
#define PCB ffc-wa_pcb
static void ag_delete_wrappers(void);
#ifndef DELETE_WRAPPERS
#define DELETE_WRAPPERS ag_delete_wrappers()
#endif

#line - "ffc-wa.syn"
 /* -- EMBEDDED C ---------------------------------- */

#define SYNTAX_ERROR printf("%s, line %d, column %d\n", \
  (PCB).error_message, (PCB).line, (PCB).column), fflush(stdout)

  Number value[64];                      /* registers */
  int main(void) {
    ffcalcr();
    return 0;
  }
#line - "ffc-wa.cpp"

#ifndef CONVERT_CASE
#define CONVERT_CASE(c) (c)
#endif
#ifndef TAB_SPACING
#define TAB_SPACING 8
#endif

static void ag_rp_1(Number &x) {
#line - "ffc-wa.syn"
  printf("%s\n", x.asString()),fflush(stdout);
#line - "ffc-wa.cpp"
}

static void ag_rp_2(int n, Number &x) {
#line - "ffc-wa.syn"
                  printf("%c = %s\n",n+'A', fflush(stdout), (value[n]=x).asString());
#line - "ffc-wa.cpp"
}

static Number ag_rp_3(Number &x, Number &t) {
#line - "ffc-wa.syn"
		printf("x = %s\n", x.asString());
		printf("t = %s\n", t.asString());
		fflush(stdout);
    x+=t;
		printf("x = %s\n", x.asString());
		fflush(stdout);
		return x;
 
#line - "ffc-wa.cpp"
}

static Number ag_rp_4(Number &x, Number &t) {
#line - "ffc-wa.syn"
  return x-=t;
#line - "ffc-wa.cpp"
}

static Number ag_rp_5(Number &t, Number &f) {
#line - "ffc-wa.syn"
  return t*=f;
#line - "ffc-wa.cpp"
}

static Number ag_rp_6(Number &t, Number &f) {
#line - "ffc-wa.syn"
  return t/=f;
#line - "ffc-wa.cpp"
}

static Number ag_rp_7(int n) {
#line - "ffc-wa.syn"
  return value[n];
#line - "ffc-wa.cpp"
}

static Number ag_rp_8(double x) {
#line - "ffc-wa.syn"
  return Number(x);
#line - "ffc-wa.cpp"
}

static Number ag_rp_9(Number &x) {
#line - "ffc-wa.syn"
  return x;
#line - "ffc-wa.cpp"
}

static Number ag_rp_10(Number &f) {
#line - "ffc-wa.syn"
  return -f;
#line - "ffc-wa.cpp"
}

static int ag_rp_11(int c) {
#line - "ffc-wa.syn"
  return c-'A';
#line - "ffc-wa.cpp"
}

static double ag_rp_12(double i, double f) {
#line - "ffc-wa.syn"
  return i+f;
#line - "ffc-wa.cpp"
}

static double ag_rp_13(double f) {
#line - "ffc-wa.syn"
  return f;
#line - "ffc-wa.cpp"
}

static double ag_rp_14(int d) {
#line - "ffc-wa.syn"
  return d-'0';
#line - "ffc-wa.cpp"
}

static double ag_rp_15(double x, int d) {
#line - "ffc-wa.syn"
  return 10*x + d-'0';
#line - "ffc-wa.cpp"
}

static double ag_rp_16(int d) {
#line - "ffc-wa.syn"
  return (d-'0')/10.;
#line - "ffc-wa.cpp"
}

static double ag_rp_17(int d, double f) {
#line - "ffc-wa.syn"
  return (d-'0' + f)/10.;
#line - "ffc-wa.cpp"
}


#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 const char ag_wdf[] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 0, 0, 4, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4
};

#undef  VW
#define VW(i,t) *(t) (&(PCB).vs[(PCB).ssx + (i)])
#undef  VNO
#define VNO new(&(PCB).vs[(PCB).ssx])
#undef  VRO
#define VRO(to,v) ag_replace_object((to) &(PCB).vs[(PCB).ssx], v)
#undef  VWD
#define VWD(i,t) ag_delete_object((t) &(PCB).vs[(PCB).ssx + (i)]);
#undef  VDO
#define VDO(to, v) ag_delete_object((to) &(PCB).vs[(PCB).ssx], v)

template <class NewObject, class OldObject>
static inline void ag_replace_object(AgObjectWrapper<OldObject> *p, const NewObject &o) {
  delete p;
  new(p) AgObjectWrapper<NewObject >(o);
}

template <class Object>
static inline void ag_delete_object(AgObjectWrapper<Object> *p) {
  delete p;
}

template <class NewObject, class OldObject>
static inline const NewObject &ag_delete_object(AgObjectWrapper<OldObject> *p, const NewObject &o) {
  delete p;
  return o;
}


#undef AG_WRAP_4
#define AG_WRAP_4 AgObjectWrapper<Number >

static void ag_delete_wrappers(void) {
  if ((PCB).ag_resynch_active) return;
  (PCB).ag_resynch_active = 1;
  int sn = (PCB).sn;
  int sx = (PCB).ssx;
  while (sx--) {
    switch (ag_wdf[sn]) {
      case 4: ag_delete_object((AG_WRAP_4 *) &(PCB).vs[sx]); break;
      default: break;
    }
    sn = (PCB).ss[sx];
  }
}

static ffc-wa_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,  3,  4,  0,  5,  6,  7,
    8,  9, 10,  0,  0,  0,  0,  0,  0, 11, 12,  0,  0,  0, 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,255, 42,255
};

static const unsigned char ag_key_act[] = {
  0,3,4,3,4
};

static const unsigned char ag_key_parm[] = {
    0, 23,  0, 27,  0
};

static const unsigned char ag_key_jmp[] = {
    0,  0,  0,  2,  0
};

static const unsigned char ag_key_index[] = {
    1,  3,  1,  0,  3,  3,  0,  1,  1,  1,  1,  0,  0,  1,  0,  0,  0,  0,
    0,  0,  1,  1,  0,  1,  0,  1,  0,  1,  0,  0,  1,  0,  1,  1,  0,  0,
    0
};

static const unsigned char ag_key_ends[] = {
42,0, 47,0, 
};
#define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0)

static const unsigned char ag_tcv[] = {
   10, 34, 34, 34, 34, 34, 34, 34, 34, 34, 22, 37, 22, 22, 22, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 22, 34, 34,
   34, 34, 34, 34, 34, 45, 44, 41, 39, 34, 40, 30, 42, 33, 33, 33, 33, 33,
   33, 33, 33, 33, 33, 34, 34, 34, 38, 34, 34, 34, 46, 46, 46, 46, 46, 46,
   46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
   46, 46, 34, 34, 34, 34, 34, 34, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
   46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
   34, 34, 34, 34, 34
};

#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 = (ffc-wa_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 = (ffc-wa_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 = (ffc-wa_token_type) ag_key_pt[ag_k1+1];
      break;
    }
    case ag_set_key:
      save_index = (PCB).rx;
      (PCB).token_number = (ffc-wa_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 =  (ffc-wa_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 =  (ffc-wa_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 = (ffc-wa_token_type) (PCB).drt;
  (PCB).ssx = (PCB).dssx;
  (PCB).sn = (PCB).dsn;
  (PCB).drt = -1;
}


static const unsigned char ag_tstt[] = {
46,45,40,37,33,30,23,22,10,0,1,35,36,
46,45,44,42,41,40,39,38,37,34,33,30,27,22,0,25,26,
23,22,0,1,
46,45,40,37,33,30,10,0,2,3,4,5,7,8,9,11,12,14,16,17,20,28,29,43,
46,45,44,42,41,40,39,38,37,34,33,30,22,0,
27,0,
33,0,31,
44,42,41,40,39,37,33,30,23,22,0,32,
46,45,40,33,30,23,22,0,1,35,36,
46,45,40,33,30,23,22,0,1,35,36,
44,42,41,40,39,37,23,22,0,1,35,36,
46,45,40,33,30,0,2,12,16,17,20,28,29,43,
46,45,40,33,30,0,2,11,12,14,16,17,20,28,29,43,
44,42,41,40,39,38,37,23,22,0,1,35,36,
42,41,0,18,19,
38,0,13,
40,39,0,15,16,
37,0,6,
46,45,40,37,33,30,10,0,2,4,5,7,11,12,14,16,17,20,28,29,43,
10,0,
33,0,31,
33,0,31,
44,40,39,0,15,16,21,
46,45,40,33,30,23,22,0,1,35,36,
46,45,40,33,30,0,2,12,16,17,20,28,29,43,
46,45,40,33,30,23,22,0,1,35,36,
46,45,40,33,30,0,2,12,16,17,20,28,29,43,
46,45,40,33,30,23,22,0,1,35,36,
46,45,40,33,30,0,2,11,12,14,16,17,20,28,29,43,
46,45,40,33,30,0,2,12,14,16,17,20,28,29,43,
46,45,40,33,30,23,22,0,1,35,36,
46,45,40,33,30,0,2,12,14,16,17,20,28,29,43,
46,45,40,37,33,30,23,22,10,0,1,35,36,
44,42,41,40,39,37,23,22,0,1,35,36,
40,39,0,15,16,
42,41,0,18,19,
42,41,0,18,19,

};


static unsigned const char ag_astt[376] = {
  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,1,8,7,2,0,1,1,1,1,1,1,1,1,1,1,1,2,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,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,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,2,1,2,1,1,1,1,1,2,1,7,2,1,2,1,1,
  1,1,2,1,1,5,5,5,5,5,5,5,1,1,7,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,1,7,3,1,1,1,
  8,2,1,5,7,2,1,1,3,1,1,1,1,1,1,2,1,1,3,7,1,4,2,1,5,2,1,1,1,7,1,1,2,5,5,5,5,
  5,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,2,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,
  7,2,2,1,2,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,7,2,1,2,1,1,1,1,2,1,1,1,
  1,1,2,1,7,2,2,1,1,1,1,2,1,1,5,5,5,5,5,1,1,7,1,1,3,1,1,1,2,1,7,2,2,1,1,1,1,
  2,1,1,5,5,5,5,5,5,1,1,5,7,1,1,3,5,5,5,5,5,5,1,1,7,1,1,3,1,1,4,1,1,1,1,4,1,
  1,1,1,4,1,1
};


static const unsigned char ag_pstt[] = {
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,51,53,51,
13,9,8,17,33,6,19,3,18,0,17,17,18,18,19,16,15,14,11,14,12,27,7,10,
23,23,23,23,23,23,23,23,23,23,23,23,23,25,
26,5,
20,6,32,
29,29,29,29,29,29,34,21,29,29,7,31,
52,52,52,52,52,1,2,8,2,2,57,
52,52,52,52,52,1,2,9,2,2,62,
52,52,52,52,52,52,1,2,10,2,2,60,
13,9,8,33,6,11,18,17,11,20,12,27,7,10,
13,9,8,33,6,12,18,22,17,14,11,14,12,27,7,10,
52,52,52,52,52,52,52,1,2,13,2,2,63,
23,25,11,26,24,
27,17,28,
8,30,9,31,29,
32,17,3,
13,9,8,17,33,6,7,18,18,17,17,5,16,15,14,11,14,12,27,7,10,
8,19,
20,35,36,
20,30,28,
33,8,30,22,31,29,19,
52,52,52,52,52,1,2,23,2,2,59,
13,9,8,33,6,24,18,17,11,16,12,27,7,10,
52,52,52,52,52,1,2,25,2,2,58,
13,9,8,33,6,26,18,17,11,15,12,27,7,10,
52,52,52,52,52,1,2,27,2,2,55,
13,9,8,33,6,28,18,34,17,14,11,14,12,27,7,10,
13,9,8,33,6,29,18,17,35,11,35,12,27,7,10,
52,52,52,52,52,1,2,30,2,2,56,
13,9,8,33,6,31,18,17,36,11,36,12,27,7,10,
52,52,52,52,52,52,1,2,52,32,2,2,54,
52,52,52,52,52,52,1,2,33,2,2,61,
8,30,10,31,29,
23,25,13,26,24,
23,25,12,26,24,

};


static const unsigned short ag_sbt[] = {
     0,  13,  30,  34,  58,  72,  74,  77,  89, 100, 111, 123, 137, 153,
   166, 171, 174, 179, 182, 203, 205, 208, 211, 218, 229, 243, 254, 268,
   279, 295, 310, 321, 336, 349, 361, 366, 371, 376
};


static const unsigned short ag_sbe[] = {
     9,  27,  32,  41,  71,  73,  75,  87,  96, 107, 119, 128, 142, 162,
   168, 172, 176, 180, 189, 204, 206, 209, 214, 225, 234, 250, 259, 275,
   284, 300, 317, 326, 345, 357, 363, 368, 373, 376
};


static const unsigned char ag_fl[] = {
  2,0,1,2,1,2,0,1,2,1,3,1,3,3,1,3,3,1,1,3,2,1,1,2,0,1,3,1,3,0,1,2,2,1,2,
  1,2,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
};

static const unsigned char ag_ptt[] = {
    0,  5,  5,  7,  8,  8,  9,  9,  3,  4,  4, 11, 11, 11, 14, 14, 14, 17,
   17, 17, 17,  1, 25, 25, 26, 26,  1, 12, 43, 32, 32, 43, 43, 29, 29, 31,
   31, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 35, 35, 36, 36,
    6, 13, 15, 16, 18, 19,  2, 21, 20, 28
};


static void ag_ra(void)
{
  switch(ag_rpx[(PCB).ag_ap]) {
    case 1: ag_rp_1(VW(0, AG_WRAP_4 *)); 
            VWD(0, AG_WRAP_4 *); break;
    case 2: ag_rp_2(V(0,(int *)), VW(2, AG_WRAP_4 *)); 
            VWD(2, AG_WRAP_4 *); break;
    case 3: VRO(AG_WRAP_4 *, ag_rp_3(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *))); 
            VWD(2, AG_WRAP_4 *); break;
    case 4: VRO(AG_WRAP_4 *, ag_rp_4(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *))); 
            VWD(2, AG_WRAP_4 *); break;
    case 5: VRO(AG_WRAP_4 *, ag_rp_5(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *))); 
            VWD(2, AG_WRAP_4 *); break;
    case 6: VRO(AG_WRAP_4 *, ag_rp_6(VW(0, AG_WRAP_4 *), VW(2, AG_WRAP_4 *))); 
            VWD(2, AG_WRAP_4 *); break;
    case 7: VNO AG_WRAP_4(ag_rp_7(V(0,(int *)))); break;
    case 8: VNO AG_WRAP_4(ag_rp_8(V(0,(double *)))); break;
    case 9: VNO AG_WRAP_4(ag_rp_9(VW(1, AG_WRAP_4 *))); 
            VWD(1, AG_WRAP_4 *); break;
    case 10: VNO AG_WRAP_4(ag_rp_10(VW(1, AG_WRAP_4 *))); 
            VWD(1, AG_WRAP_4 *); break;
    case 11: V(0,(int *)) = ag_rp_11(V(0,(int *))); break;
    case 12: V(0,(double *)) = ag_rp_12(V(0,(double *)), V(2,(double *))); break;
    case 13: V(0,(double *)) = ag_rp_13(V(1,(double *))); break;
    case 14: V(0,(double *)) = ag_rp_14(V(0,(int *))); break;
    case 15: V(0,(double *)) = ag_rp_15(V(0,(double *)), V(1,(int *))); break;
    case 16: V(0,(double *)) = ag_rp_16(V(0,(int *))); break;
    case 17: V(0,(double *)) = ag_rp_17(V(0,(int *)), V(1,(double *))); break;
  }
}

#define TOKEN_NAMES ffc-wa_token_names
const char *const ffc-wa_token_names[47] = {
  "calculator",
  "white space",
  "real",
  "calculator",
  "calculation",
  "",
  "'\\n'",
  "",
  "",
  "",
  "eof",
  "expression",
  "name",
  "'='",
  "term",
  "'+'",
  "'-'",
  "factor",
  "'*'",
  "'/'",
  "'('",
  "')'",
  "",
  "\"/*\"",
  "",
  "",
  "",
  "\"*/\"",
  "",
  "integer part",
  "'.'",
  "fraction part",
  "",
  "digit",
  "",
  "",
  "",
  "'\\n'",
  "'='",
  "'+'",
  "'-'",
  "'*'",
  "'/'",
  "real",
  "')'",
  "'('",
  "",

};


static const unsigned char ag_ctn[] = {
    0,0,  1,1,  0,0,  0,0,  0,0,  1,2, 43,1, 43,1,  0,0, 17,1, 17,1, 17,1,
   17,1, 12,1, 14,1,  4,1, 11,1,  0,0,  0,0,  0,0, 31,1, 43,2, 11,1,  0,0,
   14,2,  0,0, 14,2,  0,0,  4,2, 11,2,  0,0, 11,2,  0,0,  0,0, 11,1, 14,1,
   14,1
};

#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;


{
  int ag_sx, ag_t;

  ag_sx = (PCB).ssx;
  (PCB).ss[ag_sx] = (PCB).sn;
  do {
    while (ag_sx && ag_ctn[2*(ag_snd = (PCB).ss[ag_sx])] == 0) ag_sx--;
    if (ag_sx) {
      ag_t = ag_ctn[2*ag_snd];
      ag_sx -= ag_ctn[2*ag_snd +1];
      ag_snd = (PCB).ss[ag_sx];
    }
    else {
      ag_snd = 0;
      ag_t = ag_ptt[0];
    }
  } while (ag_sx && *TOKEN_NAMES[ag_t]==0);
  if (*TOKEN_NAMES[ag_t] == 0) ag_t = 0;
  (PCB).error_frame_ssx = ag_sx;
  (PCB).error_frame_token = (ffc-wa_token_type) ag_t;
}


}
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_rns(int ag_t, int *ag_sx, int ag_snd) {
  while (1) {
    int ag_act, ag_k = ag_sbt[ag_snd], ag_lim = ag_sbt[ag_snd+1];
    int ag_p;

    while (ag_k < ag_lim && ag_tstt[ag_k] != ag_t) ag_k++;
    if (ag_k == ag_lim) break;
    ag_act = ag_astt[ag_k];
    ag_p = ag_pstt[ag_k];
    if (ag_act == ag_action_2) return ag_p;
    if (ag_act == ag_action_10 || ag_act == ag_action_11) {
      (*ag_sx)--;
      return ag_snd;
    }
    if (ag_act != ag_action_3 &&
      ag_act != ag_action_4) break;
    *ag_sx -= (ag_fl[ag_p] - 1);
    ag_snd = (PCB).ss[*ag_sx];
    ag_t = ag_ptt[ag_p];
  }
  return 0;
}

static int ag_jns(int ag_t) {
  int ag_k;

  ag_k = ag_sbt[(PCB).sn];
  while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
  while (1) {
    int ag_p = ag_pstt[ag_k];
    int ag_sd;

    switch (ag_astt[ag_k]) {
    case ag_action_2:
      (PCB).ss[(PCB).ssx] = (PCB).sn;
      return ag_p;
    case ag_action_10:
    case ag_action_11:
      return (PCB).ss[(PCB).ssx--];
    case ag_action_9:
      (PCB).ss[(PCB).ssx] = (PCB).sn;
      (PCB).ssx++;
      (PCB).sn = ag_p;
      ag_k = ag_sbt[(PCB).sn];
      while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
      continue;
    case ag_action_3:
    case ag_action_4:
      ag_sd = ag_fl[ag_p] - 1;
      if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
      else (PCB).ss[(PCB).ssx] = (PCB).sn;
      ag_t = ag_ptt[ag_p];
      ag_k = ag_sbt[(PCB).sn+1];
      while (ag_tstt[--ag_k] != ag_t);
      continue;
    case ag_action_5:
    case ag_action_6:
      if (ag_fl[ag_p]) break;
      (PCB).sn = ag_rns(ag_ptt[ag_p],&(PCB).ssx, (PCB).sn);
      (PCB).ss[++(PCB).ssx] = (PCB).sn;
      ag_k = ag_sbt[(PCB).sn];
      while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
      continue;
    }
    break;
  }
  return 0;
}


static int ag_atx(int ag_t, int *ag_sx, int ag_snd) {
  int ag_k, ag_f;
  int ag_save_btsx = (PCB).btsx;
  int ag_flag = 1;

  while (1) {
    int ag_a;

    (PCB).bts[128 - ++(PCB).btsx] = *ag_sx;
    (PCB).ss[128 - (PCB).btsx] = (PCB).ss[*ag_sx];
    (PCB).ss[*ag_sx] = ag_snd;
    ag_k = ag_sbt[ag_snd];
    while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++;
    ag_a = ag_astt[ag_k];
    if (ag_a == ag_action_2 ||
        ag_a == ag_action_3 ||
        ag_a == ag_action_10 ||
        ag_a == ag_action_11 ||
        ag_a == ag_action_1 ||
        ag_a == ag_action_4) break;
    if ((ag_a == ag_action_5 ||
        ag_a == ag_action_6) &&
        (ag_k = ag_fl[ag_f = ag_pstt[ag_k]]) == 0) {
        ag_snd = ag_rns(ag_ptt[ag_f],ag_sx, (PCB).ss[*ag_sx]);
        (*ag_sx)++;
        continue;
    }
    if (ag_a == ag_action_9) {
      ag_snd = ag_pstt[ag_k];
      (*ag_sx)++;
      continue;
    }
    ag_flag = 0;
    break;
  }
  while ((PCB).btsx > ag_save_btsx) {
    *ag_sx = (PCB).bts[128 - (PCB).btsx];
    (PCB).ss[*ag_sx] = (PCB).ss[128 - (PCB).btsx--];
  }
  return ag_flag;
}


static int ag_tst_tkn(void) {
  int ag_rk, ag_sx, ag_snd = (PCB).sn;

  if ((PCB).rx < (PCB).fx) {
    (PCB).input_code = (PCB).lab[(PCB).rx++];
    (PCB).token_number = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
  else {
    GET_INPUT;
    (PCB).lab[(PCB).fx++] = (PCB).input_code;
    (PCB).token_number = (ffc-wa_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);
    }
  }
  for (ag_rk = 0; ag_rk < (PCB).ag_lrss; ag_rk += 2) {
    ag_sx = (PCB).ag_rss[ag_rk];
    if (ag_sx > (PCB).ssx || ag_sx > (PCB).ag_min_depth) continue;
    (PCB).sn = (PCB).ag_rss[ag_rk + 1];
    if (ag_atx((PCB).token_number, &ag_sx, (PCB).sn)) break;
  }
  (PCB).sn = ag_snd;
  return ag_rk;
}

static void ag_set_error_procs(void);

static void ag_auto_resynch(void) {
  int ag_sx, ag_rk;
  int ag_rk1, ag_rk2, ag_tk1;
  DELETE_WRAPPERS;
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  if ((PCB).ag_error_depth && (PCB).ag_min_depth >= (PCB).ag_error_depth) {
    (PCB).ssx = (PCB).ag_error_depth;
    (PCB).sn = (PCB).ss[(PCB).ssx];
  }
  else {
    ag_diagnose();
    SYNTAX_ERROR;
    if ((PCB).exit_flag != AG_RUNNING_CODE) return;
    (PCB).ag_error_depth = (PCB).ag_min_depth = 0;
    (PCB).ag_lrss = 0;
    (PCB).ss[ag_sx = (PCB).ssx] = (PCB).sn;
    (PCB).ag_min_depth = (PCB).ag_rss[(PCB).ag_lrss++] = ag_sx;
    (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn;
    while (ag_sx && (PCB).ag_lrss < 2*128) {
      int ag_t = 0, ag_x, ag_s, ag_sxs = ag_sx;

      while (ag_sx && (ag_t = ag_ctn[2*(PCB).sn]) == 0) (PCB).sn = (PCB).ss[--ag_sx];
      if (ag_t) (PCB).sn = (PCB).ss[ag_sx -= ag_ctn[2*(PCB).sn +1]];
      else {
        if (ag_sx == 0) (PCB).sn = 0;
        ag_t = ag_ptt[0];
      }
      if ((ag_s = ag_rns(ag_t, &ag_sx, (PCB).sn)) == 0) break;
      for (ag_x = 0; ag_x < (PCB).ag_lrss; ag_x += 2)
        if ((PCB).ag_rss[ag_x] == ag_sx + 1 && (PCB).ag_rss[ag_x+1] == ag_s) break;
      if (ag_x == (PCB).ag_lrss) {
        (PCB).ag_rss[(PCB).ag_lrss++] = ++ag_sx;
        (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn = ag_s;
      }
      else if (ag_sx >= ag_sxs) ag_sx--;
    }
    ag_set_error_procs();
  }
  (PCB).rx = 0;
  if ((PCB).ssx > (PCB).ag_min_depth) (PCB).ag_min_depth = (PCB).ssx;
  while (1) {
    ag_rk1 = ag_tst_tkn();
    if ((PCB).token_number == 10)
      {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;}
    if (ag_rk1 < (PCB).ag_lrss) break;
    {(PCB).rx = 1; ag_track();}
  }
  ag_tk1 = (PCB).token_number;
  ag_track();
  ag_rk2 = ag_tst_tkn();
  if (ag_rk2 < ag_rk1) {ag_rk = ag_rk2; ag_track();}
  else {ag_rk = ag_rk1; (PCB).token_number = (ffc-wa_token_type) ag_tk1; (PCB).rx = 0;}
  (PCB).ag_min_depth = (PCB).ssx = (PCB).ag_rss[ag_rk++];
  (PCB).sn = (PCB).ss[(PCB).ssx] = (PCB).ag_rss[ag_rk];
  (PCB).sn = ag_jns((PCB).token_number);
  if ((PCB).ag_error_depth == 0 || (PCB).ag_error_depth > (PCB).ssx)
    (PCB).ag_error_depth = (PCB).ssx;
  if (++(PCB).ssx >= 128) {
    (PCB).exit_flag = AG_STACK_ERROR_CODE;
    PARSER_STACK_OVERFLOW;
    return;
  }
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  (PCB).ag_tmp_depth = (PCB).ag_min_depth;
  (PCB).rx = 0;
  return;
}


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 = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
    else {
      GET_INPUT;
      (PCB).lab[(PCB).fx++] = (PCB).input_code;
      (PCB).token_number = (ffc-wa_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 == (ffc-wa_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 = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
    else {
      GET_INPUT;
      (PCB).lab[(PCB).fx++] = (PCB).input_code;
      (PCB).token_number = (ffc-wa_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 == (ffc-wa_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 = (ffc-wa_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 = (ffc-wa_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 = (ffc-wa_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 = (ffc-wa_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 ((*(PCB).s_procs[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 = (ffc-wa_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 ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break;
  }
  return 0;
}

static int ag_action_8_proc(void) {
  ag_undo();
  (PCB).rx = 0;
  ag_auto_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 = (ffc-wa_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 ((*(PCB).r_procs[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 = (ffc-wa_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 ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break;
  }
  return (PCB).exit_flag == AG_RUNNING_CODE;
}


static void ag_check_depth(int ag_fl) {
  int ag_sx = (PCB).ssx - ag_fl;
  if ((PCB).ag_error_depth && ag_sx < (PCB).ag_tmp_depth) (PCB).ag_tmp_depth = ag_sx;
}

static int ag_action_3_er_proc(void) {
  ag_check_depth(ag_fl[(PCB).ag_ap] - 1);
  return ag_action_4_r_proc();
}

static int ag_action_2_e_proc(void) {
  ag_action_2_proc();
  (PCB).ag_min_depth = (PCB).ag_tmp_depth;
  return 0;
}

static int ag_action_4_e_proc(void) {
  ag_check_depth(ag_fl[(PCB).ag_ap] - 1);
  (PCB).ag_min_depth = (PCB).ag_tmp_depth;
  return ag_action_4_proc();
}

static int ag_action_6_e_proc(void) {
  ag_check_depth(ag_fl[(PCB).ag_ap]);
  return ag_action_6_proc();
}

static int ag_action_11_e_proc(void) {
  return ag_action_10_proc();
}

static int (*ag_r_procs_error[])(void) = {
  ag_action_1_r_proc,
  ag_action_2_r_proc,
  ag_action_3_er_proc,
  ag_action_3_er_proc
};

static int (*ag_s_procs_error[])(void) = {
  ag_action_1_s_proc,
  ag_action_2_r_proc,
  ag_action_3_er_proc,
  ag_action_3_er_proc
};

static int (*ag_gt_procs_error[])(void) = {
  ag_action_1_proc,
  ag_action_2_e_proc,
  ag_action_4_e_proc,
  ag_action_4_e_proc,
  ag_action_6_e_proc,
  ag_action_6_e_proc,
  ag_action_7_proc,
  ag_action_8_proc,
  ag_action_9_proc,
  ag_action_10_proc,
  ag_action_11_e_proc,
  ag_action_8_proc
};

static void ag_set_error_procs(void) {
  (PCB).gt_procs = ag_gt_procs_error;
  (PCB).r_procs = ag_r_procs_error;
  (PCB).s_procs = ag_s_procs_error;
}


void init_ffc-wa(void) {
  (PCB).rx = (PCB).fx = 0;
  (PCB).gt_procs = ag_gt_procs_scan;
  (PCB).r_procs = ag_r_procs_scan;
  (PCB).s_procs = ag_s_procs_scan;
  (PCB).ag_error_depth = (PCB).ag_min_depth = (PCB).ag_tmp_depth = 0;
  (PCB).ag_resynch_active = 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 ffc-wa(void) {
  init_ffc-wa();
  (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 = (ffc-wa_token_type) AG_TCV((PCB).input_code);}
      else {
        GET_INPUT;
        (PCB).lab[(PCB).fx++] = (PCB).input_code;
        (PCB).token_number = (ffc-wa_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];
    (*(PCB).gt_procs[ag_astt[ag_t1]])();
  }
}