view helpgen/readhelp.c @ 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 5581ef01f993
children
line wrap: on
line source

/*
 * AnaGram, a System for Syntax Directed Programming
 * Copyright 1993 Parsifal Software. All Rights Reserved.
 * Copyright 2006 David A. Holland. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * readhelp.syn - Toplevel syntax for help source file.
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "utils.h"
#include "topic.h"
#include "helpgen.h"

/*
 * AnaGram, A System for Syntax Directed Programming
 * File generated by: Version 2.40-current, built Jun 12 2022
 *
 * 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 READHELP_H_1655092739
#include "readhelp.h"
#endif

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



readhelp_pcb_type readhelp_pcb;
#define PCB readhelp_pcb

#line 124 "../../src/helpgen/readhelp.syn"
static char string_space[4096];
static size_t string_pos;

static void startstr(void) {
  string_pos = 0;
}

static void addstr(int ch) { 
  if (string_pos >= sizeof(string_space)-1) {
    fprintf(stderr, "String buffer overflow - make string_space larger\n");
    exit(1);
  }
  string_space[string_pos++] = ch;
}

static const char *getstr(void) {
  string_space[string_pos] = 0;
  return string_space;
}
#line 88 "readhelp.c"
#line 149 "../../src/helpgen/readhelp.syn"
static struct topic *curtopic;

static void startblock(void) {
  assert(curtopic == NULL);
  curtopic = topic_create();
}

static void endblock(void) {
  help_addtopic(curtopic);
  curtopic = NULL;
}

static void see_xref(const char *ref) {
  topic_addref(curtopic, ref);
}

#line 106 "readhelp.c"
#line 172 "../../src/helpgen/readhelp.syn"
#define GET_CONTEXT CONTEXT = PCB.pointer

static unsigned char *inputdata;

static void block(long head, long tail) {
  long length = tail - head;
  assert(length >= 0);
  if (length > 0) {
    topic_setbody(curtopic, (const char *)(inputdata+head), length);
  }
}

static off_t getlength(int fd) {
  struct stat st;
  if (fstat(fd, &st) < 0) {
    fprintf(stderr, "fstat failed: %s", strerror(errno));
    exit(1);
  }
  return st.st_size;
}

void load(const char *path) {
  char *buf;
  off_t len;
  int fd, r;

  fd = open(path, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "%s: %s\n", path, strerror(errno));
    exit(1);
  }

  len = getlength(fd);
  buf = domalloc(len+1);
  r = read(fd, buf, len);
  if (r < 0) {
    fprintf(stderr, "%s: read: %s\n", path, strerror(errno));
    exit(1);
  }
  if (r < len) {
    fprintf(stderr, "%s: read: short count %d of %ld\n", path, r, (long) len);
    exit(1);
  }
  buf[r] = 0;
  close(fd);

  inputdata = (unsigned char *) buf;
  PCB.pointer = inputdata;
  readhelp();
  inputdata = NULL;
  free(buf);
}

#line 161 "readhelp.c"

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

#define ag_rp_1(c) (c)

#define ag_rp_2(c) (startstr(), addstr(c))

#define ag_rp_3(c) (addstr(c))

#define ag_rp_4(c) (addstr(' '), addstr(c))

#define ag_rp_5() (getstr())

#define ag_rp_6(t) (topic_addtitle(curtopic, t))

#define ag_rp_7(t) (topic_addtitle(curtopic, t))

#define ag_rp_8() (CONTEXT - inputdata)

#define ag_rp_9() (see_xref(getstr()))

#define ag_rp_10() (startstr())

#define ag_rp_11(c) (addstr(c))

#define ag_rp_12(c) (addstr(' '), addstr(c))

#define ag_rp_13() (addstr(' '))

#define ag_rp_14() (CONTEXT - inputdata)

#define ag_rp_15() (CONTEXT - inputdata)

static void ag_rp_16(void) {
#line 105 "../../src/helpgen/readhelp.syn"
 startblock(); 
#line 203 "readhelp.c"
}

#define ag_rp_17() (endblock())

#define ag_rp_18(bb, be) (block(bb,be))

#define ag_rp_19() (block(0,0))


#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 readhelp_vs_type const ag_null_value NULL_VALUE_INITIALIZER;

static const unsigned char ag_rpx[] = {
    0,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  2,
    3,  4,  5,  6,  7,  0,  0,  8,  0,  0,  0,  9, 10, 11, 12, 13,  0,  0,
   14,  0,  0, 15, 16, 17,  0,  0, 18, 19
};

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

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

static const unsigned char ag_key_ch[] = {
    0, 47,255, 35,255
};

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

static const unsigned char ag_key_parm[] = {
    0,  6,  0, 32,  0
};

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

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

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

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

static const unsigned char ag_tcv[] = {
   39,  2,  2,  2,  2,  2,  2,  2,  2,  4, 12,  2,  2, 10,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  4,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2, 20,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2, 28, 27,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
    2,  2,  2,  2
};

#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 = (readhelp_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 = (readhelp_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 = (readhelp_token_type) ag_key_pt[ag_k1+1];
      break;
    }
    case ag_set_key:
      ag_save = (int) ((PCB).la_ptr - (PCB).pointer);
      (PCB).token_number = (readhelp_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 = (readhelp_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 = (readhelp_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 = (readhelp_token_type) (PCB).drt;
  (PCB).ssx = (PCB).dssx;
  (PCB).sn = (PCB).dsn;
  (PCB).drt = -1;
}


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

};


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


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

};


static const unsigned char ag_sbt[] = {
     0,   9,  20,  26,  28,  34,  44,  51,  58,  62,  66,  80,  89,  95,
    97,  99, 109, 120, 128, 133, 142, 154, 163, 171, 176, 180, 185, 197,
   212, 214, 223
};


static const unsigned char ag_sbe[] = {
     6,  15,  21,  27,  31,  40,  48,  56,  60,  64,  73,  85,  94,  96,
    98, 106, 113, 124, 129, 138, 148, 158, 166, 173, 178, 183, 191, 204,
   213, 218, 223
};


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

static const unsigned char ag_ptt[] = {
    0,  1,  3,  3,  8,  8,  9,  9, 11, 11,  5, 13, 15, 15, 16, 16, 14, 17,
   17, 17, 18, 19, 19, 23, 23, 21, 21, 22, 22, 25, 26, 26, 26, 26, 29, 29,
   30, 30, 31, 31, 34, 33, 36, 36, 35, 35, 37, 38, 38, 38
};


static void ag_ra(void)
{
  switch(ag_rpx[(PCB).ag_ap]) {
    case 1: V(0,(int *)) = ag_rp_1(V(0,(int *))); break;
    case 2: ag_rp_2(V(0,(int *))); break;
    case 3: ag_rp_3(V(1,(int *))); break;
    case 4: ag_rp_4(V(2,(int *))); break;
    case 5: V(0,(const char * *)) = ag_rp_5(); break;
    case 6: ag_rp_6(V(0,(const char * *))); break;
    case 7: ag_rp_7(V(3,(const char * *))); break;
    case 8: V(0,(long *)) = ag_rp_8(); break;
    case 9: ag_rp_9(); break;
    case 10: ag_rp_10(); break;
    case 11: ag_rp_11(V(1,(int *))); break;
    case 12: ag_rp_12(V(2,(int *))); break;
    case 13: ag_rp_13(); break;
    case 14: V(0,(long *)) = ag_rp_14(); break;
    case 15: V(0,(long *)) = ag_rp_15(); break;
    case 16: ag_rp_16(); break;
    case 17: ag_rp_17(); break;
    case 18: ag_rp_18(V(1,(long *)), V(2,(long *))); break;
    case 19: ag_rp_19(); break;
  }
  (PCB).la_ptr = (PCB).pointer;
}

#define TOKEN_NAMES readhelp_token_names
const char *const readhelp_token_names[40] = {
  "file",
  "letter",
  "",
  "blanks",
  "blank",
  "eol",
  "\"//\"",
  "text",
  "",
  "",
  "cr",
  "",
  "nl",
  "new line",
  "continue",
  "",
  "",
  "name",
  "title",
  "titles",
  "','",
  "text lines",
  "text unit",
  "",
  "",
  "cross reference",
  "cross reference text",
  "right",
  "left",
  "block body",
  "blank lines",
  "end block",
  "\"##\"",
  "block",
  "",
  "real block body",
  "",
  "file",
  "blocks",
  "eof",

};

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


}
static int ag_action_1_r_proc(void);
static int ag_action_2_r_proc(void);
static int ag_action_3_r_proc(void);
static int ag_action_4_r_proc(void);
static int ag_action_1_s_proc(void);
static int ag_action_3_s_proc(void);
static int ag_action_1_proc(void);
static int ag_action_2_proc(void);
static int ag_action_3_proc(void);
static int ag_action_4_proc(void);
static int ag_action_5_proc(void);
static int ag_action_6_proc(void);
static int ag_action_7_proc(void);
static int ag_action_8_proc(void);
static int ag_action_9_proc(void);
static int ag_action_10_proc(void);
static int ag_action_11_proc(void);
static int ag_action_8_proc(void);


static int (*const  ag_r_procs_scan[])(void) = {
  ag_action_1_r_proc,
  ag_action_2_r_proc,
  ag_action_3_r_proc,
  ag_action_4_r_proc
};

static int (*const  ag_s_procs_scan[])(void) = {
  ag_action_1_s_proc,
  ag_action_2_r_proc,
  ag_action_3_s_proc,
  ag_action_4_r_proc
};

static int (*const  ag_gt_procs_scan[])(void) = {
  ag_action_1_proc,
  ag_action_2_proc,
  ag_action_3_proc,
  ag_action_4_proc,
  ag_action_5_proc,
  ag_action_6_proc,
  ag_action_7_proc,
  ag_action_8_proc,
  ag_action_9_proc,
  ag_action_10_proc,
  ag_action_11_proc,
  ag_action_8_proc
};


static int ag_action_10_proc(void) {
  int ag_t = (PCB).token_number;
  (PCB).btsx = 0, (PCB).drt = -1;
  do {
    ag_track();
    (PCB).token_number = (readhelp_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 == (readhelp_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 {
    (*(int *) &(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 = (readhelp_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 == (readhelp_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 = (readhelp_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 = (readhelp_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 = (readhelp_token_type) ag_ptt[(PCB).ag_ap];
  return 1;
}

static int ag_action_2_proc(void) {
  (PCB).btsx = 0, (PCB).drt = -1;
  if ((PCB).ssx >= 128) {
    (PCB).exit_flag = AG_STACK_ERROR_CODE;
    PARSER_STACK_OVERFLOW;
  }
  (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).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 = (readhelp_token_type) ag_ptt[(PCB).ag_ap];
  (PCB).btsx = 0, (PCB).drt = -1;
  (*(int *) &(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);
    (PCB).ag_ap = ag_pstt[ag_t1];
    if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
  }
  return 0;
}

static int ag_action_3_proc(void) {
  int ag_sd = ag_fl[(PCB).ag_ap] - 1;
  (PCB).btsx = 0, (PCB).drt = -1;
  (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).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 = (readhelp_token_type) ag_ptt[(PCB).ag_ap];
  ag_ra();
  while ((PCB).exit_flag == AG_RUNNING_CODE) {
    unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
    unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
    do {
      unsigned ag_tx = (ag_t1 + ag_t2)/2;
      if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
      else ag_t2 = ag_tx;
    } while (ag_t1 < ag_t2);
    (PCB).ag_ap = ag_pstt[ag_t1];
    if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break;
  }
  return 0;
}

static int ag_action_8_proc(void) {
  ag_undo();
  (PCB).la_ptr =  (PCB).pointer;
  (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
  ag_diagnose();
  SYNTAX_ERROR;
  {(PCB).la_ptr = (PCB).pointer + 1; ag_track();}
  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 = (readhelp_token_type) ag_ptt[(PCB).ag_ap];
  ag_ra();
  while ((PCB).exit_flag == AG_RUNNING_CODE) {
    unsigned ag_t1 = ag_sbe[(PCB).sn] + 1;
    unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1;
    do {
      unsigned ag_tx = (ag_t1 + ag_t2)/2;
      if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1;
      else ag_t2 = ag_tx;
    } while (ag_t1 < ag_t2);
    (PCB).ag_ap = ag_pstt[ag_t1];
    if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
  }
  return (PCB).exit_flag == AG_RUNNING_CODE;
}

static int ag_action_6_proc(void) {
  int ag_sd = ag_fl[(PCB).ag_ap];
  (PCB).reduction_token = (readhelp_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);
    (PCB).ag_ap = ag_pstt[ag_t1];
    if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break;
  }
  return (PCB).exit_flag == AG_RUNNING_CODE;
}


void init_readhelp(void) {
  (PCB).la_ptr = (PCB).pointer;
  (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 readhelp(void) {
  init_readhelp();
  (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 = (readhelp_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];
    (ag_gt_procs_scan[ag_astt[ag_t1]])();
  }
}