view tests/agcl/oldagsrc/good/cf.cpp @ 24:a4899cdfc2d6 default tip

Obfuscate the regexps to strip off the IBM compiler's copyright banners. I don't want bots scanning github to think they're real copyright notices because that could cause real problems.
author David A. Holland
date Mon, 13 Jun 2022 00:40:23 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
  AnaGram Syntax Analyzer.
  Copyright (c) Parsifal Software, 1993-1999.
  All Rights Reserved.

  Configuration file module
*/

//#define INCLUDE_LOGGING

#include "arrays.h"       //ARRAYS
#include "assert.h"       //ASSERT
#include "cint.h"
#include "config.h"
#include "data.h"         //DATA
#include "error.h"
#include "log.hpp"
#include "myalloc.h"      //MYALLOC
#include "pf.h"           //PF
#include "tfile.h"        //TFILE
#include <ctype.h>       //CTYPE
#include <stdlib.h>       //STDLIB
#include <string.h>       //STRING

#undef MODULE
#define MODULE 50

/*
 * 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 CF_H
#include "cf.h"
#endif

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


#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 - "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 *);

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



static cf_pcb_type cfcb;
#define PCB cfcb

extern unsigned char *input_base;

static AgString config_file;

void read_config(const AgString path) {
  LOGSECTION("read_config");
  LOGV(path);
  config_file = path.lastCut(PATH_DELIMITER).leftI().concat("AnaGram.cfg");
  text_file tf(config_file);
  cfcb.pointer = input_base = (unsigned char *) tf;
  if (input_base) cf();
  config_file = "AnaGram.cfg";
  tf = text_file(config_file);
  cfcb.pointer = input_base = (unsigned char *) tf;
  LOGS("Starting parse");
  if (input_base) cf();
}

static void cf_error(const char *msg) {
  errorList.push(Error(config_file, msg, 1));
}

Error::Error(AgString f, AgString msg, int contextFlag)
  : file(f),
    line(contextFlag? ERROR_CONTEXT.y : PCB.line),
    column(contextFlag? ERROR_CONTEXT.y :PCB.column),
    key(warn),
    message(msg)
{
  // Nothing here
}


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


       int   allow_macros = 1;
       int   auto_init = 1;
       int   auto_resynch = 0;
       int   backtrack = 1;
       int   bottom_margin = 3;
       int   bright_background = 1;

       int   case_sensitive = 1;
    AgString compile_command("");
       int   const_data = 1;
    AgString context_type;
    AgString coverage_file_name("#.nrc");

       int   declare_pcb = 1;
       int   default_input_type;
       int   default_token_type;
       int   default_reductions = 1;
       int   diagnose_errors = 1;
       int   distinguish_lexemes = 0;

    AgString edit_command("ed #.syn");
       int   enable_mouse = 1;
    AgString enum_constant_name("$_%_token");
       int   error_frame = 0;
       int   error_trace = 0;
       int   escape_backslashes = 0;
       int   event_driven = 0;

       int   far_tables = 0;

       int   grammar_token = 0;
    AgString header_file_name("#.h");
       int   input_values = 0;
       int   iso_latin_1 = 1;

       int   line_length = 80;
       int   line_numbers = 0;
    AgString line_numbers_path;
       int   lines_and_columns = 1;

       int   main_program = 1;
       int   max_conflicts = 50;
    //AgString mutex_type;

       int   near_functions = 0;
       int   nest_comments = 0;

       int   old_style = 0;

       int   page_length = 66;
    AgString parser_file_name("#.c");
    AgString parser_name("#");
       int   parser_stack_alignment;
       int   parser_stack_size = 32;
       int   pointer_input = 0;
    AgString pointer_type("unsigned char *");
    AgString print_file_name("LPT1");

       int   quick_reference = 0;

       int   reduction_choices =0;
       int   reentrant_parser = 0;
       int   rule_coverage = 0;

       int   tab_spacing = 8;
       int   test_file_binary = 0;
    AgString test_file_mask("*.*");
       int   test_range = 1;
       int   token_names = 0;
       int   top_margin = 3;
       int   traditional_engine = 0;

       int   video_mode = -1;

       int trial_copy_code = 0;

int error_token;
int eof_token = 0;

#line - "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 - "cf.syn"
  ConfigParam::set(1, cfErrorHandler);
#line - "cf.cpp"
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static void ag_rp_54(void) {
#line - "cf.syn"
if (nest_comments) PCB.reduction_token = cf_c_comment_text_token;
#line - "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);
    }
    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];
    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]])();
  }
}