view anagram/agcore/cf.cpp @ 8:ec2b657edf13

Add explicit lint-comment-style fallthrough annotations. GCC now assumes that if you don't have these you're making a mistake, which is annoying. XXX: This changeset updates the AG output files only (by hand) and is XXX: abusive - rebuilding them will erase the change. However, I need XXX: to get things to build before I can try to get AG to issue the XXX: annotations itself, so this seems like a reasonable expedient.
author David A. Holland
date Mon, 30 May 2022 23:51:43 -0400
parents 13d2b8934445
children 5581ef01f993
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
 *
 * cf.syn - Configuration file module
 */

#include "port.h"

#include "agstring.h"
#include "assert.h"
#include "cf-defs.h"
#include "cint.h"
#include "config.h"
#include "configparam.h"
#include "error.h"
#include "file.h"
#include "operations.h"
#include "stacks.h"
#include "textfile.h"

//#define INCLUDE_LOGGING
#include "log.h"

/*
 * AnaGram, A System for Syntax Directed Programming
 * File generated by: Version 2.40-current, built Oct 30 2007
 *
 * 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 CF_H_1198348333
#include "cf.h"
#endif

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


#define CHANGE_REDUCTION(x) cf_change_reduction(cf_##x##_token)
int cf_change_reduction(cf_token_type);


int cf_value(void);

#define TOKEN_NAMES cf_token_names
const char *const cf_token_names[104] = {
  "config file",
  "config file",
  "equals",
  "'='",
  "",
  "",
  "minus",
  "'-'",
  "plus",
  "'+'",
  "tilde",
  "'~'",
  "",
  "'('",
  "",
  "')'",
  "blank",
  "",
  "",
  "global parameter",
  "end of line",
  "",
  "",
  "",
  "eof",
  "name",
  "data type",
  "keyword string",
  "number",
  "abstract declarator",
  "",
  "direct abstract declarator",
  "",
  "",
  "star",
  "'*'",
  "",
  "letter",
  "",
  "blank char",
  "c comment",
  "continuation",
  "comment",
  "",
  "carriage return",
  "",
  "newline",
  "white",
  "vertical space",
  "\"//\"",
  "",
  "",
  "",
  "decimal number",
  "",
  "",
  "octal number",
  "'0'",
  "",
  "hex number",
  "\"0x\"",
  "\"0X\"",
  "",
  "simple number",
  "",
  "",
  "keyword string head",
  "string",
  "double quote",
  "",
  "",
  "",
  "string char",
  "simple string char",
  "",
  "\"\\\\a\"",
  "\"\\\\b\"",
  "\"\\\\f\"",
  "\"\\\\n\"",
  "\"\\\\r\"",
  "\"\\\\t\"",
  "\"\\\\v\"",
  "\"\\\\\\\\\"",
  "\"\\\\?\"",
  "\"\\\\\\'\"",
  "\"\\\\\\\"\"",
  "",
  "",
  "backslash",
  "",
  "",
  "",
  "",
  "\"\\\\x\"",
  "any digit",
  "nonoctal digit",
  "",
  "\"*/\"",
  "\"/*\"",
  "",
  "",
  "",
  "",
  "",

};


#line 265 "cf.syn"
#define PARSER_STACK_OVERFLOW assert(0)
#define REDUCTION_TOKEN_ERROR assert(0)
#define SYNTAX_ERROR cf_syn_error()
#define GET_CONTEXT CONTEXT.x = PCB.column, CONTEXT.y = PCB.line

static void cf_error(const char *, int = 1);

class CfErrorHandler : public ConfigParam::ErrorHandler {
public:
  virtual ~CfErrorHandler() {}
  virtual void badParam(const char *s){cf_error(s);}
} cfErrorHandler;



static cf_pcb_type cfcb;
#define PCB cfcb

static AgString config_file;

static void read_one_config(const AgString &dir) {
  LOGSECTION("read_one_config");
  LOGV(dir);

  char delim[2];
  delim[0] = PATH_DELIMITER;
  delim[1] = 0;

  config_file = dir.concat(delim).concat("AnaGram.cfg");
  LOGV(config_file);

  text_file tf(config_file);
  cfcb.pointer = input_base = (unsigned char *) tf;
  if (input_base) cf();
}

void read_config(const AgString mydir) {
  LOGSECTION("read_config");
  LOGV(mydir);
  LOGV(work_dir_name);

  read_one_config(mydir);
  read_one_config(work_dir_name);
}

static void cf_error(const char *msg, int contextFlag) {
  int line, column;
  if (contextFlag) {
    line = CONTEXT.y;
    column = CONTEXT.x;
  }
  else {
    line = PCB.line;
    column = PCB.column;
  }
  errorList.push(Error(line, column, config_file, msg));
}

static void cf_syn_error(void) {
  reset_stk();
  cf_error(PCB.error_message, 0);
}

#line 246 "cf.cpp"

#ifndef CONVERT_CASE
#define CONVERT_CASE(c) (c)
#endif
#ifndef TAB_SPACING
#define TAB_SPACING 8
#endif
int cf_value(void) {
  int returnValue;
  returnValue = (PCB).vs[(PCB).ssx];
  return returnValue;
}

static void ag_rp_1(void) {
#line 88 "cf.syn"
  ConfigParam::set(1, cfErrorHandler);
#line 263 "cf.cpp"
}

static void ag_rp_2(void) {
#line 89 "cf.syn"
  ConfigParam::set(0, cfErrorHandler);
#line 269 "cf.cpp"
}

static void ag_rp_3(void) {
#line 90 "cf.syn"
  ConfigParam::set(cfErrorHandler);
#line 275 "cf.cpp"
}

static void ag_rp_4(void) {
#line 91 "cf.syn"
  ConfigParam::set(cfErrorHandler);
#line 281 "cf.cpp"
}

static void ag_rp_5(int n) {
#line 92 "cf.syn"
  ConfigParam::set(n, cfErrorHandler);
#line 287 "cf.cpp"
}

static void ag_rp_6(void) {
#line 96 "cf.syn"
  concat_string();
#line 293 "cf.cpp"
}

static void ag_rp_7(void) {
#line 101 "cf.syn"
  concat_string();
#line 299 "cf.cpp"
}

static int ag_rp_8(void) {
#line 105 "cf.syn"
  return scs('('),0;
#line 305 "cf.cpp"
}

static void ag_rp_9(void) {
#line 106 "cf.syn"
  concat_string(), acs(')');
#line 311 "cf.cpp"
}

static void ag_rp_10(void) {
#line 110 "cf.syn"
  concat_string();
#line 317 "cf.cpp"
}

static void ag_rp_11(void) {
#line 113 "cf.syn"
  sss(" *");
#line 323 "cf.cpp"
}

static void ag_rp_12(void) {
#line 117 "cf.syn"
  concat_string();
#line 329 "cf.cpp"
}

static void ag_rp_13(int a) {
#line 120 "cf.syn"
  scs(a);
#line 335 "cf.cpp"
}

static void ag_rp_14(int a) {
#line 121 "cf.syn"
  acs(a);
#line 341 "cf.cpp"
}

static void ag_rp_15(int a) {
#line 122 "cf.syn"
  acs(' '), acs(a);
#line 347 "cf.cpp"
}

static int ag_rp_16(int d) {
#line 159 "cf.syn"
  return d - '0';
#line 353 "cf.cpp"
}

static int ag_rp_17(int n, int d) {
#line 160 "cf.syn"
  return 10*n + d - '0';
#line 359 "cf.cpp"
}

static int ag_rp_18(void) {
#line 163 "cf.syn"
  return 0;
#line 365 "cf.cpp"
}

static int ag_rp_19(int n, int d) {
#line 164 "cf.syn"
  return 8*n + d - '0';
#line 371 "cf.cpp"
}

static int ag_rp_20(void) {
#line 167 "cf.syn"
  return 0;
#line 377 "cf.cpp"
}

static int ag_rp_21(void) {
#line 168 "cf.syn"
  return 0;
#line 383 "cf.cpp"
}

static int ag_rp_22(int n, int d) {
#line 169 "cf.syn"
  return 16*n + d - '0';
#line 389 "cf.cpp"
}

static int ag_rp_23(int n, int d) {
#line 170 "cf.syn"
  return 16*n + (d&7) + 9;
#line 395 "cf.cpp"
}

static int ag_rp_24(int s, int n) {
#line 178 "cf.syn"
  return s*n;
#line 401 "cf.cpp"
}

static int ag_rp_25(void) {
#line 181 "cf.syn"
  return 1;
#line 407 "cf.cpp"
}

static int ag_rp_26(void) {
#line 182 "cf.syn"
  return -1;
#line 413 "cf.cpp"
}

static void ag_rp_27(void) {
#line 191 "cf.syn"
  ics();
#line 419 "cf.cpp"
}

static int ag_rp_28(void) {
#line 198 "cf.syn"
  return '\a';
#line 425 "cf.cpp"
}

static int ag_rp_29(void) {
#line 199 "cf.syn"
  return '\b';
#line 431 "cf.cpp"
}

static int ag_rp_30(void) {
#line 200 "cf.syn"
  return '\f';
#line 437 "cf.cpp"
}

static int ag_rp_31(void) {
#line 201 "cf.syn"
  return '\n';
#line 443 "cf.cpp"
}

static int ag_rp_32(void) {
#line 202 "cf.syn"
  return '\r';
#line 449 "cf.cpp"
}

static int ag_rp_33(void) {
#line 203 "cf.syn"
  return '\t';
#line 455 "cf.cpp"
}

static int ag_rp_34(void) {
#line 204 "cf.syn"
  return '\v';
#line 461 "cf.cpp"
}

static int ag_rp_35(void) {
#line 205 "cf.syn"
  return '\\';
#line 467 "cf.cpp"
}

static int ag_rp_36(void) {
#line 206 "cf.syn"
  return '\?';
#line 473 "cf.cpp"
}

static int ag_rp_37(void) {
#line 207 "cf.syn"
  return '\'';
#line 479 "cf.cpp"
}

static int ag_rp_38(void) {
#line 208 "cf.syn"
  return '"';
#line 485 "cf.cpp"
}

static int ag_rp_39(int n) {
#line 209 "cf.syn"
  return n==0?cf_error("Null character in string"),0 : n;
#line 491 "cf.cpp"
}

static int ag_rp_40(int n) {
#line 212 "cf.syn"
  return n&7;
#line 497 "cf.cpp"
}

static int ag_rp_41(int n, int d) {
#line 215 "cf.syn"
  return n*8 + (d&7);
#line 503 "cf.cpp"
}

static int ag_rp_42(int n, int d) {
#line 218 "cf.syn"
  return n*8 + (d&7);
#line 509 "cf.cpp"
}

static int ag_rp_43(int n) {
#line 222 "cf.syn"
  return n==0?cf_error("Null character in string"),0 : n;
#line 515 "cf.cpp"
}

static int ag_rp_44(int n) {
#line 225 "cf.syn"
  return n;
#line 521 "cf.cpp"
}

static void ag_rp_45(int c) {
#line 228 "cf.syn"
  acs(c);
#line 527 "cf.cpp"
}

static void ag_rp_46(int c) {
#line 229 "cf.syn"
  acs(c);
#line 533 "cf.cpp"
}

static void ag_rp_47(int c) {
#line 230 "cf.syn"
  acs(c);
#line 539 "cf.cpp"
}

static void ag_rp_48(int c) {
#line 231 "cf.syn"
  acs(c);
#line 545 "cf.cpp"
}

static void ag_rp_49(int c) {
#line 232 "cf.syn"
  acs(c);
#line 551 "cf.cpp"
}

static void ag_rp_50(int n) {
#line 235 "cf.syn"
  acs(n);
#line 557 "cf.cpp"
}

static void ag_rp_51(int n) {
#line 236 "cf.syn"
  acs(n);
#line 563 "cf.cpp"
}

static void ag_rp_52(int n) {
#line 239 "cf.syn"
  acs(n);
#line 569 "cf.cpp"
}

static void ag_rp_53(int n) {
#line 240 "cf.syn"
  acs(n);
#line 575 "cf.cpp"
}

static void ag_rp_54(void) {
#line 251 "cf.syn"
 if (nest_comments) PCB.reduction_token = cf_c_comment_text_token; 
#line 581 "cf.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 int const ag_null_value NULL_VALUE_INITIALIZER;

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

static const unsigned char ag_key_itt[] = {
 0
};

static const unsigned short ag_key_pt[] = {
0
};

static const unsigned char ag_key_ch[] = {
    0, 42, 47,255, 47,255, 42, 47,255, 47,255, 42, 47,255, 88,120,255, 47,
   48,255, 88,120,255, 48,255, 88,120,255, 47, 48,255, 34, 39, 63, 92, 97,
   98,102,110,114,116,118,120,255, 92,255
};

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

static const unsigned char ag_key_parm[] = {
    0, 98, 49,  0,  0,  0, 97, 98,  0, 49,  0, 98, 49,  0, 61, 60,  0,  0,
    0,  0, 61, 60,  0,  0,  0, 61, 60,  0, 98,  0,  0, 85, 84, 83, 82, 75,
   76, 77, 78, 79, 80, 81, 93,  0,  0,  0
};

static const unsigned char ag_key_jmp[] = {
    0,  0,  0,  0,  1,  0,  0,  2,  0,  4,  0,  0,  0,  0,  0,  0,  0, 11,
   14,  0,  0,  0,  0, 20,  0,  0,  0,  0,  6, 25,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0, 31,  0
};

static const unsigned char ag_key_index[] = {
    4,  6,  4,  9,  0,  4,  4,  0,  0,  0,  9,  4,  0,  9,  0,  0,  0,  0,
   17,  4,  0, 17, 23,  0,  0,  4, 28, 17, 17, 23, 44,  9,  0, 28,  4,  4,
    4,  4,  0, 44, 44, 23, 44, 44, 44,  4,  4,  9,  0,  9, 44,  4,  0,  4
};

static const unsigned char ag_key_ends[] = {
47,0, 42,0, 47,0, 42,0, 
};

#define AG_TCV(x) ag_tcv[(x)]

static const unsigned char ag_tcv[] = {
   24,103,103,103,103,103,103,103,103, 39, 46, 48, 48, 44,103,103,103,103,
  103,103,103,103,103,103,103,103, 24,103,103,103,103,103, 39,103, 68,103,
  103,103,103,103, 13, 15, 35,  9,103,  7,103,103, 57,101,101,101,101,101,
  101,101,102,102,103,103,103,  3,103,103,103, 62, 62, 62, 62, 62, 62,100,
  100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,
  100,103, 88,103,103,100,103, 62, 62, 62, 62, 62, 62,100,100,100,100,100,
  100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,103,103,103,
   11,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,
  103,103,103,103
};

#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


#ifndef INPUT_CODE
#define INPUT_CODE(T) (T)
#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;

static void ag_get_key_word(int ag_k) {
  int ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
  const  unsigned char *ag_p;
  int ag_ch;
  while (1) {
    switch (ag_key_act[ag_k]) {
    case ag_cf_end_key: {
      const  unsigned char *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 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail;
          (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1 + 1];
          return;
        }
      } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
      goto ag_fail;
    }
    case ag_end_key: {
      const  unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k];
      do {
        if ((ag_ch = *sp++) == 0) {
          (PCB).token_number = (cf_token_type) ag_key_parm[ag_k];
          return;
        }
      } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch);
    }
    /* FALLTHROUGH */
    case ag_no_match_key:
ag_fail:
      (PCB).la_ptr = (PCB).pointer + ag_save;
      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 + CONVERT_CASE(*(PCB).la_ptr)]) break;
      ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
      (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1+1];
      break;
    }
    case ag_set_key:
      ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
      (PCB).token_number = (cf_token_type) ag_key_parm[ag_k];
      /* FALLTHROUGH */
    case ag_jmp_key:
      ag_k = ag_key_jmp[ag_k];
      break;
    case ag_accept_key:
      (PCB).token_number = (cf_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 + CONVERT_CASE(*(PCB).la_ptr)])
        (PCB).la_ptr = (PCB).pointer + ag_save;
      else (PCB).token_number = (cf_token_type) ag_key_pt[ag_k1+1];
      return;
    }
    }
    ag_ch = CONVERT_CASE(*(PCB).la_ptr++);
    ag_p = &ag_key_ch[ag_k];
    if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++;
    if (ag_ch > 255 || *ag_p != ag_ch) {
      (PCB).la_ptr = (PCB).pointer + ag_save;
      return;
    }
    ag_k = (int) (ag_p - ag_key_ch);
  }
}


#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 = (int) ((PCB).la_ptr - (PCB).pointer);
  while (ag_k--) {
    switch (*(PCB).pointer++) {
    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++;
    }
  }
}


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];
  (PCB).cs[ag_k] = (PCB).cs[(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).cs[(PCB).ssx] = (PCB).cs[ag_k];
  }
  (PCB).token_number = (cf_token_type) (PCB).drt;
  (PCB).ssx = (PCB).dssx;
  (PCB).sn = (PCB).dsn;
  (PCB).drt = -1;
}



static const int ag_rtt[] = {
   40, 96,  0
};

static const unsigned char ag_tstt[] = {
100,98,62,49,46,44,39,24,11,0,1,16,17,18,40,96,
103,102,101,100,98,97,88,68,62,57,48,46,44,39,35,15,13,11,9,7,3,0,40,96,
98,39,0,16,40,96,
100,62,49,46,44,24,11,0,10,19,20,21,22,23,25,36,42,45,
103,102,101,100,88,68,62,57,48,46,44,39,35,15,13,11,9,7,3,0,51,52,
100,98,62,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96,
102,101,100,98,62,57,49,46,44,39,35,24,15,13,3,0,16,17,18,40,96,
46,0,
46,44,0,45,
100,62,0,25,36,
3,0,2,
100,98,62,49,48,46,44,39,24,11,0,16,40,42,45,47,96,
100,62,11,0,10,19,25,36,
49,46,44,24,0,20,42,45,
24,0,
103,102,101,100,88,68,62,57,48,39,35,15,13,11,9,7,3,0,
46,0,
46,44,0,43,45,
102,101,100,98,68,62,61,60,57,49,46,44,39,35,13,9,7,0,16,40,41,42,43,45,96,
102,101,100,98,62,57,39,0,16,40,96,
46,0,
102,101,100,98,68,62,61,60,57,49,46,44,39,9,7,0,4,5,16,17,40,41,42,43,45,96,
102,101,100,68,62,61,60,57,9,7,0,6,8,25,26,27,28,36,64,65,66,
46,44,0,45,
46,0,
100,98,62,49,48,46,44,39,24,11,0,16,40,42,45,47,96,
98,39,0,16,17,40,96,
102,101,98,61,60,57,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96,
102,101,98,61,60,57,49,46,44,39,0,4,5,16,17,40,41,42,43,45,96,
102,101,61,60,57,0,53,56,59,63,
103,102,101,100,93,88,85,84,83,82,81,80,79,78,77,76,75,62,57,48,39,35,15,13,
  11,9,7,3,0,67,69,70,71,72,74,86,87,89,90,91,92,
35,13,0,12,29,30,31,32,33,34,
46,0,
98,39,0,16,40,96,
102,101,62,57,0,
101,57,0,
102,101,57,0,
98,49,46,44,39,24,0,16,17,18,40,96,
101,57,0,
101,57,0,
101,57,0,
61,60,0,59,
102,62,0,
102,101,62,57,0,
103,100,93,88,85,84,83,82,81,80,79,78,77,76,75,68,48,39,35,15,13,11,9,7,3,0,
  72,74,86,87,89,90,91,92,
98,49,46,44,39,35,13,0,4,5,16,17,40,41,42,43,45,96,
100,98,62,49,46,44,39,35,24,15,13,0,16,17,18,40,96,
100,62,0,25,36,
35,13,0,12,29,30,31,32,33,34,
35,13,0,12,31,32,33,34,
102,101,62,57,0,
98,49,46,44,39,24,0,16,17,18,40,96,
15,0,14,
98,49,46,44,39,24,15,0,16,17,18,40,96,

};


static unsigned const char ag_astt[595] = {
  8,1,8,8,8,8,1,5,8,7,0,1,1,1,1,1,3,3,3,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
  7,2,1,1,9,5,3,3,1,2,2,1,8,1,8,1,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
  5,1,1,1,1,1,1,1,1,7,1,3,5,1,5,1,8,1,1,7,3,3,1,1,1,3,1,3,1,1,10,10,10,1,10,
  10,5,5,5,1,5,5,5,5,5,7,1,1,3,1,1,3,7,8,1,7,1,2,2,7,2,1,1,4,1,5,1,5,1,9,8,1,
  9,5,5,7,3,3,1,1,3,1,2,2,1,5,1,3,1,1,1,8,1,5,7,1,1,1,3,7,9,9,9,9,9,9,9,9,9,
  9,9,9,9,9,9,9,9,5,1,7,8,1,7,3,1,5,5,5,1,5,5,5,5,5,1,8,1,9,5,5,5,5,7,3,3,3,
  1,3,1,1,2,2,2,1,2,2,9,5,3,3,1,3,7,5,5,5,1,5,5,5,5,5,1,8,1,1,5,5,7,3,3,1,1,
  1,3,1,3,1,1,5,5,2,2,2,5,5,5,1,1,7,2,2,1,2,2,2,1,1,2,1,8,1,7,1,3,7,5,1,5,1,
  9,8,1,9,5,5,7,3,3,1,1,3,1,1,1,5,1,1,1,1,5,5,1,5,5,5,1,8,1,1,7,3,3,1,1,1,3,
  1,3,1,1,5,5,1,5,5,5,1,8,1,1,7,3,3,1,1,1,3,1,3,1,1,2,2,2,2,2,7,1,1,1,1,2,2,
  2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,7,1,1,1,1,2,2,2,1,1,2,
  2,2,1,1,5,2,2,1,2,1,1,1,3,7,1,9,5,3,3,1,10,10,10,10,5,10,10,5,10,10,10,5,1,
  5,5,5,1,5,7,1,1,2,1,1,2,2,7,2,2,5,2,2,5,2,2,7,1,2,2,5,10,10,10,10,5,2,2,1,
  1,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,7,2,2,2,1,1,2,2,2,1,1,8,1,1,5,
  5,7,3,3,1,1,1,3,1,3,1,1,5,1,5,5,5,5,1,5,5,5,5,7,1,1,2,1,1,2,2,5,2,1,1,1,7,
  2,1,1,1,1,1,1,1,1,5,2,2,1,2,1,10,10,10,10,4,1,5,5,5,1,5,7,1,1,3,1,1,1,7,2,
  1,5,5,5,1,5,5,7,1,1,3,1,1
};


static const unsigned char ag_pstt[] = {
3,1,3,3,3,3,2,10,3,0,0,2,2,3,2,1,
118,118,118,118,1,116,118,118,118,118,118,118,118,118,118,118,118,118,118,
  118,118,1,119,1,
1,9,11,9,9,1,
38,38,4,7,7,14,5,3,9,13,11,13,12,14,10,6,8,7,
15,15,15,15,15,15,15,15,15,62,62,15,15,15,15,15,15,15,15,4,15,64,
1,1,1,4,16,16,18,5,6,6,18,18,18,6,17,6,16,1,
39,39,39,1,39,39,10,10,10,19,10,10,10,10,10,6,19,19,41,19,1,
57,7,
20,20,8,20,
38,38,9,22,6,
21,21,22,
16,1,16,4,59,24,24,58,16,16,11,58,58,23,24,58,1,
38,38,5,19,9,14,10,6,
4,7,7,18,13,25,8,7,
20,14,
61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,61,63,
26,16,
16,16,17,47,16,
44,44,44,1,44,44,44,44,44,4,16,16,9,44,44,44,44,18,9,9,45,17,45,16,1,
40,40,40,1,40,40,9,11,9,9,1,
56,20,
1,1,1,1,1,1,1,1,1,4,16,16,18,1,1,21,3,3,18,18,18,3,17,3,16,1,
77,77,38,85,38,77,77,77,27,28,22,80,79,31,23,24,25,6,29,79,30,
32,32,23,32,
54,24,
15,1,15,4,59,24,24,58,15,15,25,58,58,23,24,58,1,
1,33,51,33,33,33,1,
1,1,1,1,1,1,4,16,16,18,27,5,5,18,18,18,5,17,5,16,1,
1,1,1,1,1,1,4,16,16,18,28,4,4,18,18,18,4,17,4,16,1,
65,65,70,69,67,29,36,35,34,37,
107,108,108,107,41,38,98,97,96,95,94,93,92,91,90,89,88,108,108,107,107,107,
  107,107,107,107,107,107,30,44,43,42,44,107,107,99,40,39,112,105,114,
46,45,26,31,27,49,27,48,49,47,
55,32,
1,9,52,9,9,1,
71,71,72,71,75,
68,68,74,
66,66,66,73,
1,10,10,10,2,10,37,2,2,76,2,1,
100,100,38,
102,102,104,
101,101,103,
70,69,41,50,
111,111,83,
110,110,110,110,82,
109,109,41,38,98,97,96,95,94,93,92,91,90,89,88,51,109,109,109,109,109,109,
  109,109,109,44,109,109,99,40,39,113,105,115,
1,4,16,16,18,1,1,45,7,7,18,18,18,7,17,7,16,1,
10,1,10,10,10,10,2,10,10,10,10,46,2,2,35,2,1,
38,38,33,34,6,
46,45,48,31,52,49,52,48,49,47,
46,45,28,31,30,48,37,47,
71,71,72,71,106,
1,10,10,10,2,10,51,2,2,81,2,1,
53,52,32,
1,10,10,10,2,10,10,53,2,2,12,2,1,

};


static const unsigned short ag_sbt[] = {
     0,  16,  40,  46,  64,  86, 104, 125, 127, 131, 136, 139, 156, 164,
   172, 174, 192, 194, 199, 224, 235, 237, 263, 284, 288, 290, 307, 314,
   335, 356, 366, 407, 417, 419, 425, 430, 433, 437, 449, 452, 455, 458,
   462, 465, 470, 504, 522, 539, 544, 554, 562, 567, 579, 582, 595
};


static const unsigned short ag_sbe[] = {
     9,  37,  42,  53,  83,  93, 119, 126, 129, 133, 137, 149, 159, 168,
   173, 191, 193, 196, 216, 231, 236, 252, 273, 286, 289, 300, 309, 324,
   345, 361, 394, 409, 418, 421, 429, 432, 436, 443, 451, 454, 457, 460,
   464, 469, 495, 511, 533, 541, 546, 556, 566, 573, 580, 589, 595
};


static const unsigned char ag_fl[] = {
  1,0,1,2,2,2,2,2,1,2,0,1,2,1,2,2,1,0,1,1,3,1,2,3,3,3,1,2,1,1,2,1,3,1,2,
  2,1,2,1,2,3,2,1,1,1,2,1,2,1,0,1,2,3,1,2,3,3,2,2,2,1,2,0,1,2,1,2,1,2,1,
  1,2,2,1,1,1,3,0,1,1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,
  1,2,1,1,2,2,2,1,2,1,2,2,1,2,2
};

static const unsigned char ag_ptt[] = {
    0,  5,  5,  2,  6,  8, 10, 12, 17, 17, 18, 18, 14, 21, 21, 22, 22, 23,
   23, 23,  1, 19, 19, 19, 19, 19, 26, 26, 29, 29, 29, 32, 31, 33, 33, 34,
   30, 30, 36, 36, 36, 25, 16, 16,  4,  4,  4, 41, 41, 45, 45, 43, 43, 47,
   47, 47, 20, 20, 20, 20, 51, 51, 52, 52, 42, 53, 53, 56, 56, 59, 59, 59,
   59, 63, 63, 63, 28, 65, 65, 64, 64, 27, 67, 67, 67, 66, 72, 72, 74, 74,
   74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 87, 89, 86, 91, 91, 90, 92, 69,
   69, 69, 69, 69, 70, 70, 71, 71, 40, 96, 96, 40
};

static const unsigned char  *ag_valid(int ag_k) {
  const unsigned char  *ag_tp = &ag_tstt[ag_sbt[(PCB).sn+1]];
  while (*--ag_tp != (unsigned char) ag_k) if (*ag_tp == 0) return NULL;
  return ag_tp;
}

int cf_change_reduction(cf_token_type ag_k) {
  if (!ag_valid(ag_k)) return 0;
  (PCB).reduction_token = ag_k;
  return 1;
}

static void ag_default(const  int *ag_tp) {
  (PCB).ag_dsn = (PCB).sn;
  (PCB).ag_dtl = ag_tp;
  while (!ag_valid((cf_token_type) *ag_tp)) ag_tp++;
  (PCB).reduction_token = (cf_token_type) *ag_tp;
}



static void ag_ra(void)
{
  switch(ag_rpx[(PCB).ag_ap]) {
    case 1: ag_rp_1(); break;
    case 2: ag_rp_2(); break;
    case 3: ag_rp_3(); break;
    case 4: ag_rp_4(); break;
    case 5: ag_rp_5(VS(2)); break;
    case 6: ag_rp_6(); break;
    case 7: ag_rp_7(); break;
    case 8: VS(0) = ag_rp_8(); break;
    case 9: ag_rp_9(); break;
    case 10: ag_rp_10(); break;
    case 11: ag_rp_11(); break;
    case 12: ag_rp_12(); break;
    case 13: ag_rp_13(VS(0)); break;
    case 14: ag_rp_14(VS(1)); break;
    case 15: ag_rp_15(VS(2)); break;
    case 16: VS(0) = ag_rp_16(VS(0)); break;
    case 17: VS(0) = ag_rp_17(VS(0), VS(1)); break;
    case 18: VS(0) = ag_rp_18(); break;
    case 19: VS(0) = ag_rp_19(VS(0), VS(1)); break;
    case 20: VS(0) = ag_rp_20(); break;
    case 21: VS(0) = ag_rp_21(); break;
    case 22: VS(0) = ag_rp_22(VS(0), VS(1)); break;
    case 23: VS(0) = ag_rp_23(VS(0), VS(1)); break;
    case 24: VS(0) = ag_rp_24(VS(0), VS(1)); break;
    case 25: VS(0) = ag_rp_25(); break;
    case 26: VS(0) = ag_rp_26(); break;
    case 27: ag_rp_27(); break;
    case 28: VS(0) = ag_rp_28(); break;
    case 29: VS(0) = ag_rp_29(); break;
    case 30: VS(0) = ag_rp_30(); break;
    case 31: VS(0) = ag_rp_31(); break;
    case 32: VS(0) = ag_rp_32(); break;
    case 33: VS(0) = ag_rp_33(); break;
    case 34: VS(0) = ag_rp_34(); break;
    case 35: VS(0) = ag_rp_35(); break;
    case 36: VS(0) = ag_rp_36(); break;
    case 37: VS(0) = ag_rp_37(); break;
    case 38: VS(0) = ag_rp_38(); break;
    case 39: VS(0) = ag_rp_39(VS(0)); break;
    case 40: VS(0) = ag_rp_40(VS(1)); break;
    case 41: VS(0) = ag_rp_41(VS(0), VS(1)); break;
    case 42: VS(0) = ag_rp_42(VS(0), VS(1)); break;
    case 43: VS(0) = ag_rp_43(VS(0)); break;
    case 44: VS(0) = ag_rp_44(VS(1)); break;
    case 45: ag_rp_45(VS(0)); break;
    case 46: ag_rp_46(VS(0)); break;
    case 47: ag_rp_47(VS(1)); break;
    case 48: ag_rp_48(VS(1)); break;
    case 49: ag_rp_49(VS(1)); break;
    case 50: ag_rp_50(VS(0)); break;
    case 51: ag_rp_51(VS(1)); break;
    case 52: ag_rp_52(VS(0)); break;
    case 53: ag_rp_53(VS(1)); break;
    case 54: ag_default(&ag_rtt[0]); ag_rp_54(); break;
  }
  (PCB).la_ptr = (PCB).pointer;
}


static const unsigned char ag_ctn[] = {
    0,0, 40,1,  0,0,  0,0, 42,1, 10,1, 25,1, 20,1, 20,1, 19,1, 19,1, 20,1,
   22,1, 22,1,  0,0,  0,0,  0,0, 41,1,  0,0,  0,0, 20,2,  2,1, 19,2, 47,1,
   47,1, 20,1,  0,0,  8,1,  6,1, 28,1, 27,1, 26,1, 47,2,  0,0, 59,1, 56,1,
   53,1, 28,2, 72,1, 72,1, 72,1,  0,0, 67,1, 67,1, 67,1, 31,1, 34,1,  0,0,
   31,1, 29,1, 59,1, 27,3, 31,2,  0,0
};

#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(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') {
    char buf[20];
    sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer)));
    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 = (cf_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:
      GET_CONTEXT;
      (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:
      GET_CONTEXT;
      (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 GET_CONTEXT;
      (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;

  (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
  (PCB).la_ptr++;
  if (ag_key_index[(PCB).sn]) {
    unsigned ag_k = ag_key_index[(PCB).sn];
    int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
    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;
  (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).la_ptr =  (PCB).pointer;
  if ((PCB).ssx > (PCB).ag_min_depth) (PCB).ag_min_depth = (PCB).ssx;
  while (1) {
    ag_rk1 = ag_tst_tkn();
    if ((PCB).token_number == 24)
      {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;}
    if (ag_rk1 < (PCB).ag_lrss) break;
    {(PCB).la_ptr = (PCB).pointer + 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 = (cf_token_type) ag_tk1; (PCB).la_ptr =  (PCB).pointer;}
  (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;
  }
  GET_CONTEXT;
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  (PCB).ag_tmp_depth = (PCB).ag_min_depth;
  (PCB).la_ptr =  (PCB).pointer;
  return;
}


static int ag_action_10_proc(void) {
  int ag_t = (PCB).token_number;
  (PCB).btsx = 0, (PCB).drt = -1;
  do {
    ag_track();
    (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
    (PCB).la_ptr++;
    if (ag_key_index[(PCB).sn]) {
      unsigned ag_k = ag_key_index[(PCB).sn];
      int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
      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 == (cf_token_type) ag_t);
  (PCB).la_ptr =  (PCB).pointer;
  return 1;
}

static int ag_action_11_proc(void) {
  int ag_t = (PCB).token_number;

  (PCB).btsx = 0, (PCB).drt = -1;
  do {
    (PCB).vs[(PCB).ssx] = *(PCB).pointer;
    (PCB).ssx--;
    ag_track();
    ag_ra();
    if ((PCB).exit_flag != AG_RUNNING_CODE) return 0;
    (PCB).ssx++;
    (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
    (PCB).la_ptr++;
    if (ag_key_index[(PCB).sn]) {
      unsigned ag_k = ag_key_index[(PCB).sn];
      int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
      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 == (cf_token_type) ag_t);
  (PCB).la_ptr =  (PCB).pointer;
  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 = (cf_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 = (cf_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 = (cf_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;
  }
  (PCB).vs[(PCB).ssx] = *(PCB).pointer;
  GET_CONTEXT;
  (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;
  GET_CONTEXT;
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  (PCB).ssx++;
  (PCB).sn = (PCB).ag_ap;
  (PCB).la_ptr =  (PCB).pointer;
  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).la_ptr =  (PCB).pointer;
  (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 = (cf_token_type) ag_ptt[(PCB).ag_ap];
  (PCB).btsx = 0, (PCB).drt = -1;
  (PCB).vs[(PCB).ssx] = *(PCB).pointer;
  if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  else GET_CONTEXT;
  (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);
    if (ag_tstt[ag_t1] != (PCB).reduction_token) {
      (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; 
      REDUCTION_TOKEN_ERROR; break;}
      (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;
  (PCB).vs[(PCB).ssx] = *(PCB).pointer;
  if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  else GET_CONTEXT;
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  ag_track();
  (PCB).reduction_token = (cf_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);
    if (ag_tstt[ag_t1] != (PCB).reduction_token) {
      (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; 
      REDUCTION_TOKEN_ERROR; break;}
      (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).la_ptr =  (PCB).pointer;
  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 {
    GET_CONTEXT;
    (PCB).ss[(PCB).ssx] = (PCB).sn;
  }
  (PCB).la_ptr =  (PCB).pointer;
  (PCB).reduction_token = (cf_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);
    if (ag_tstt[ag_t1] != (PCB).reduction_token) {
      (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; 
      REDUCTION_TOKEN_ERROR; break;}
      (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 = (cf_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;
    GET_CONTEXT;
    (PCB).ss[(PCB).ssx] = (PCB).sn;
  }
  (PCB).la_ptr =  (PCB).pointer;
  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);
    if (ag_tstt[ag_t1] != (PCB).reduction_token) {
      (PCB).exit_flag = AG_REDUCTION_ERROR_CODE; 
      REDUCTION_TOKEN_ERROR; break;}
      (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_cf(void) {
  (PCB).la_ptr = (PCB).pointer;
  (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 cf(void) {
  init_cf();
  (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;
      (PCB).token_number = (cf_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr));
      (PCB).la_ptr++;
      if (ag_key_index[(PCB).sn]) {
        unsigned ag_k = ag_key_index[(PCB).sn];
        int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer));
        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]])();
  }
}