view tests/agcl/examples/good/ex.cpp @ 22:5581ef01f993

Regen all the AG output. This also fixes the line number output in the tools (cgbigen/helpgen/help2html), apparently because those files weren't regenerated last go.
author David A. Holland
date Mon, 13 Jun 2022 00:06:39 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, a System for Syntax Directed Programming
 * C Macro preprocessor
 * Constant Expression Evaluator Module
 *
 * Copyright 1993-2000 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.
 */

#include "mpp.h"

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

#ifndef EX_H
#error Mismatched header file
#endif

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



long ex_value(void);

#define INPUT_VALUE(type) *(type *) &(PCB).input_value

#line - "ex.syn"
                                      // Embedded C
#include <stdio.h>


// Macro Definitions

#define PCB (*ex_pcb)
#define SYNTAX_ERROR syntax_error("Syntax error in constant expression");


// Static data

static ex_pcb_type *ex_pcb;            // Pointer to active pcb


/*

decode() is a simple function to recover the numeric value of a
token. Its task is somewhat simplified by the fact that the only
values allowed in this example are longs.

*/

static long decode(const char *fmt, unsigned ndx) {
  long v;
  sscanf(td[ndx], fmt, &v);
  return v;
}


// Members of expression_evaluator Class


// Constructor

/*
  Each expression_evaluator has its own parser control block.
  Therefore, before calling ex() or its initializer init_ex() it is
  necessary to make sure the pcb pointer for ex() is correctly set.
*/

expression_evaluator::expression_evaluator() {
  ex_pcb = &pcb;                       // set up pointer to pcb
  init_ex();                           // init parser
}


// Reset expression_evaluator

token_sink& reset(expression_evaluator &x) {
  ex_pcb = &x.pcb;                     // set up pointer to pcb
  init_ex();                           // init parser
  return x;
}


// Xmit Token to expression_evaluator

/*
  There could be space tokens in the input to the expression
  evaluator, but they are never significant so it is acceptable to
  filter them out on input.

  If the expression_evaluator has encountered an error, there is no
  point in giving it any further input.

  Otherwise, the input_code and input_value fields of the pcb are set
  up, the pcb pointer for ex is set, and ex() is called to deal with
  the token.

  When looping, it is only necessary to set up ex_pcb at the
  beginning of the loop.
*/

token_sink& expression_evaluator::operator << (token t) {
  if (t.id == SPACE || pcb.exit_flag != AG_RUNNING_CODE) return *this;
  pcb.input_code = t.id;
  pcb.input_value = t;
  ex_pcb = &pcb;
  ex();
  return *this;
}

token_sink &expression_evaluator::operator << (token *tp) {
  ex_pcb = &pcb;
  while (pcb.exit_flag == AG_RUNNING_CODE) {
    if (pcb.input_code == SPACE) continue;
    pcb.input_code = tp->id;
    pcb.input_value = *tp++;
    ex();
  }
  return *this;
}


// Return Value of expression_evaluator

/*
  The (long) cast operator is overloaded to provide a mechanism to
  retrieve the value of the expression evaluated by the
  expression_evaluator.

  If there was a syntax error, the return value is zero.
*/

expression_evaluator::operator long() {
  ex_pcb = &pcb;
  if (pcb.exit_flag == AG_SUCCESS_CODE) return ex_value();
  else return 0;
}

/*
// Check expression_evaluator for error

int error(expression_evaluator &x) {
  return x.pcb.exit_flag != AG_SUCCESS_CODE;
}
*/
#line - "ex.cpp"

#ifndef CONVERT_CASE
#define CONVERT_CASE(c) (c)
#endif
#ifndef TAB_SPACING
#define TAB_SPACING 8
#endif
long ex_value(void) {
  long returnValue;
  returnValue = (*(long *) &(PCB).vs[(PCB).ssx]);
  return returnValue;
}

static long ag_rp_1(long c, long x, long y) {
#line - "ex.syn"
  return c != 0 ? x : y;
#line - "ex.cpp"
}

static long ag_rp_2(long x, long y) {
#line - "ex.syn"
  return x != 0 || y!=0;
#line - "ex.cpp"
}

static long ag_rp_3(long x, long y) {
#line - "ex.syn"
  return x != 0 && y !=0;
#line - "ex.cpp"
}

static long ag_rp_4(long x, long y) {
#line - "ex.syn"
  return x | y;
#line - "ex.cpp"
}

static long ag_rp_5(long x, long y) {
#line - "ex.syn"
  return x ^ y;
#line - "ex.cpp"
}

static long ag_rp_6(long x, long y) {
#line - "ex.syn"
  return x & y;
#line - "ex.cpp"
}

static long ag_rp_7(long x, long y) {
#line - "ex.syn"
  return x == y;
#line - "ex.cpp"
}

static long ag_rp_8(long x, long y) {
#line - "ex.syn"
  return x != y;
#line - "ex.cpp"
}

static long ag_rp_9(long x, long y) {
#line - "ex.syn"
  return x < y;
#line - "ex.cpp"
}

static long ag_rp_10(long x, long y) {
#line - "ex.syn"
  return x > y;
#line - "ex.cpp"
}

static long ag_rp_11(long x, long y) {
#line - "ex.syn"
  return x <= y;
#line - "ex.cpp"
}

static long ag_rp_12(long x, long y) {
#line - "ex.syn"
  return x >= y;
#line - "ex.cpp"
}

static long ag_rp_13(long x, long y) {
#line - "ex.syn"
  return x << y;
#line - "ex.cpp"
}

static long ag_rp_14(long x, long y) {
#line - "ex.syn"
  return x >> y;
#line - "ex.cpp"
}

static long ag_rp_15(long x, long y) {
#line - "ex.syn"
  return x + y;
#line - "ex.cpp"
}

static long ag_rp_16(long x, long y) {
#line - "ex.syn"
  return x - y;
#line - "ex.cpp"
}

static long ag_rp_17(long x, long y) {
#line - "ex.syn"
  return x * y;
#line - "ex.cpp"
}

static long ag_rp_18(long x, long y) {
#line - "ex.syn"
  return x / y;
#line - "ex.cpp"
}

static long ag_rp_19(long x, long y) {
#line - "ex.syn"
  return x % y;
#line - "ex.cpp"
}

static long ag_rp_20(long x) {
#line - "ex.syn"
      if (x != 0) return x;
      syntax_error("Divide by Zero");
      PCB.exit_flag = 5;
      return x;
    
#line - "ex.cpp"
}

static long ag_rp_21(long x) {
#line - "ex.syn"
  return x;
#line - "ex.cpp"
}

static long ag_rp_22(long x) {
#line - "ex.syn"
  return -x;
#line - "ex.cpp"
}

static long ag_rp_23(long x) {
#line - "ex.syn"
  return ~x;
#line - "ex.cpp"
}

static long ag_rp_24(long x) {
#line - "ex.syn"
  return !x;
#line - "ex.cpp"
}

static long ag_rp_25(token x) {
#line - "ex.syn"
  return decode("%lx",x.handle);
#line - "ex.cpp"
}

static long ag_rp_26(token x) {
#line - "ex.syn"
  return decode("%lo",x.handle);
#line - "ex.cpp"
}

static long ag_rp_27(token x) {
#line - "ex.syn"
  return decode("%ld",x.handle);
#line - "ex.cpp"
}

static long ag_rp_28(token x) {
#line - "ex.syn"
  return decode("'%lc'",x.handle);
#line - "ex.cpp"
}

static long ag_rp_29(void) {
#line - "ex.syn"
  return 0;
#line - "ex.cpp"
}

static long ag_rp_30(long x) {
#line - "ex.syn"
  return x;
#line - "ex.cpp"
}


#ifndef AG_TRACE_FILE_NAME
#define AG_TRACE_FILE_NAME "ex.etr"
#endif

static void ag_trace_error(void) {
  FILE *ag_file = fopen(AG_TRACE_FILE_NAME, "w");
  int i;
  if (ag_file == NULL) return;
  fprintf(ag_file, "%d\n", (PCB).ssx);
  for (i = 0; i < (PCB).ssx; i++) fprintf(ag_file, "%d\n", (PCB).ss[i]);
  fprintf(ag_file, "%d\n", (PCB).sn);
  fprintf(ag_file, "%d\n", (PCB).token_number);
  fclose(ag_file);
}


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

static const unsigned char ag_rpx[] = {
    0,  0,  0,  0,  1,  0,  2,  0,  3,  0,  4,  0,  5,  0,  6,  0,  7,  8,
    0,  9, 10, 11, 12,  0, 13, 14,  0, 15, 16,  0, 17, 18, 19, 20,  0, 21,
   22, 23, 24, 25, 26, 27, 28, 29, 30
};

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

static const unsigned char ag_tcv[] = {
    3,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 39,  0,  0,
    0, 36, 17,  0, 45, 46, 33, 30,  0, 31,  0, 34,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  7,  0, 22,  0, 23,  6,  0, 11,  0,  0,  0,  0,  0,  0,
   19,  0, 25,  0, 24, 27,  0,  0,  0,  0, 20,  0,  9,  0, 28,  0, 43,  0,
    0,  0,  0,  0, 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,  0,  0,  0,  0,  0, 13,  0,
   38,  0,  0, 40, 41, 42,  0, 44,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0
};

#ifndef SYNTAX_ERROR
#define SYNTAX_ERROR fprintf(stderr,"%s\n", (PCB).error_message)
#endif

#ifndef PARSER_STACK_OVERFLOW
#define PARSER_STACK_OVERFLOW {fprintf(stderr, \
  "\nParser stack overflow\n");}
#endif

#ifndef REDUCTION_TOKEN_ERROR
#define REDUCTION_TOKEN_ERROR {fprintf(stderr, \
  "\nReduction token error\n");}
#endif


static void ag_prot(void) {
  int ag_k;
  ag_k = 128 - ++(PCB).btsx;
  if (ag_k <= (PCB).ssx) {
    ag_trace_error();
    (PCB).exit_flag = AG_STACK_ERROR_CODE;
    PARSER_STACK_OVERFLOW;
    return;
  }
  (PCB).bts[(PCB).btsx] = (PCB).sn;
  (PCB).bts[ag_k] = (PCB).ssx;
  (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx];
  (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx];
}

static void ag_undo(void) {
  if ((PCB).drt == -1) return;
  while ((PCB).btsx) {
    int ag_k = 128 - (PCB).btsx;
    (PCB).sn = (PCB).bts[(PCB).btsx--];
    (PCB).ssx = (PCB).bts[ag_k];
    (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k];
    (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k];
  }
  (PCB).token_number = (ex_token_type) (PCB).drt;
  (PCB).ssx = (PCB).dssx;
  (PCB).sn = (PCB).dsn;
  (PCB).drt = -1;
}


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


static unsigned const char ag_astt[530] = {
  1,2,2,2,2,2,1,1,1,1,7,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,2,2,1,2,2,2,2,2,1,1,1,1,7,
  2,2,1,2,2,2,2,2,1,1,1,1,7,2,2,1,2,2,2,2,2,1,1,1,1,7,2,2,1,1,1,5,1,1,5,1,1,
  5,1,1,1,1,5,1,1,5,1,5,1,5,1,5,1,5,1,1,5,3,7,2,7,1,2,2,2,2,2,1,1,1,1,7,2,2,
  2,1,2,2,2,2,2,1,1,1,1,7,2,2,2,1,2,2,2,2,2,1,1,1,1,7,2,2,1,2,2,2,2,2,1,1,1,
  1,7,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,2,2,
  2,2,2,1,1,1,1,7,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,2,2,2,2,2,1,1,1,
  1,7,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,
  1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,
  2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,1,1,
  2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,
  1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,7,1,
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,1,1,4,1,1,4,1,1,4,1,1,4,1,1,4,1,1,4,1,1,
  4,1,1,1,1,4,1,1,1,1,4,1,1,4,1,4,1,4,1,4,1,4,1,7,1,2,2,2,2,2,1,1,1,1,7,2,1,
  1,1,1,1,1,1,1,1,1,1,1,11
};


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


static const unsigned short ag_sbt[] = {
     0,  26,  50,  63,  76,  89, 102, 106, 109, 112, 117, 120, 122, 124,
   126, 128, 131, 133, 135, 149, 163, 176, 190, 204, 219, 234, 250, 266,
   282, 298, 315, 332, 350, 369, 389, 410, 432, 456, 460, 464, 467, 470,
   473, 476, 479, 482, 487, 492, 495, 497, 499, 501, 503, 505, 529
};


static const unsigned short ag_sbe[] = {
    10,  36,  60,  73,  86,  99, 105, 108, 111, 116, 119, 121, 123, 125,
   127, 130, 132, 134, 145, 159, 173, 186, 200, 214, 229, 244, 260, 276,
   292, 308, 325, 342, 360, 379, 399, 420, 442, 459, 463, 466, 469, 472,
   475, 478, 481, 486, 491, 494, 496, 498, 500, 502, 504, 515, 529
};


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

static const unsigned char ag_ptt[] = {
    0,  1,  2,  4,  4,  5,  5,  8,  8, 10, 10, 12, 12, 14, 14, 16, 16, 16,
   18, 18, 18, 18, 18, 21, 21, 21, 26, 26, 26, 29, 29, 29, 29, 35, 32, 32,
   32, 32, 32, 37, 37, 37, 37, 37, 37
};


static void ag_ra(void)
{
  switch(ag_rpx[(PCB).ag_ap]) {
    case 1: V(0,(long *)) = ag_rp_1(V(0,(long *)), V(2,(long *)), V(4,(long *))); break;
    case 2: V(0,(long *)) = ag_rp_2(V(0,(long *)), V(2,(long *))); break;
    case 3: V(0,(long *)) = ag_rp_3(V(0,(long *)), V(2,(long *))); break;
    case 4: V(0,(long *)) = ag_rp_4(V(0,(long *)), V(2,(long *))); break;
    case 5: V(0,(long *)) = ag_rp_5(V(0,(long *)), V(2,(long *))); break;
    case 6: V(0,(long *)) = ag_rp_6(V(0,(long *)), V(2,(long *))); break;
    case 7: V(0,(long *)) = ag_rp_7(V(0,(long *)), V(2,(long *))); break;
    case 8: V(0,(long *)) = ag_rp_8(V(0,(long *)), V(2,(long *))); break;
    case 9: V(0,(long *)) = ag_rp_9(V(0,(long *)), V(2,(long *))); break;
    case 10: V(0,(long *)) = ag_rp_10(V(0,(long *)), V(2,(long *))); break;
    case 11: V(0,(long *)) = ag_rp_11(V(0,(long *)), V(2,(long *))); break;
    case 12: V(0,(long *)) = ag_rp_12(V(0,(long *)), V(2,(long *))); break;
    case 13: V(0,(long *)) = ag_rp_13(V(0,(long *)), V(2,(long *))); break;
    case 14: V(0,(long *)) = ag_rp_14(V(0,(long *)), V(2,(long *))); break;
    case 15: V(0,(long *)) = ag_rp_15(V(0,(long *)), V(2,(long *))); break;
    case 16: V(0,(long *)) = ag_rp_16(V(0,(long *)), V(2,(long *))); break;
    case 17: V(0,(long *)) = ag_rp_17(V(0,(long *)), V(2,(long *))); break;
    case 18: V(0,(long *)) = ag_rp_18(V(0,(long *)), V(2,(long *))); break;
    case 19: V(0,(long *)) = ag_rp_19(V(0,(long *)), V(2,(long *))); break;
    case 20: V(0,(long *)) = ag_rp_20(V(0,(long *))); break;
    case 21: V(0,(long *)) = ag_rp_21(V(1,(long *))); break;
    case 22: V(0,(long *)) = ag_rp_22(V(1,(long *))); break;
    case 23: V(0,(long *)) = ag_rp_23(V(1,(long *))); break;
    case 24: V(0,(long *)) = ag_rp_24(V(1,(long *))); break;
    case 25: V(0,(long *)) = ag_rp_25(V(0,(token *))); break;
    case 26: V(0,(long *)) = ag_rp_26(V(0,(token *))); break;
    case 27: V(0,(long *)) = ag_rp_27(V(0,(token *))); break;
    case 28: V(0,(long *)) = ag_rp_28(V(0,(token *))); break;
    case 29: V(0,(long *)) = ag_rp_29(); break;
    case 30: V(0,(long *)) = ag_rp_30(V(1,(long *))); break;
  }
}

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) {
  (PCB).btsx = 0, (PCB).drt = -1;
  return 0;
}

static int ag_action_11_proc(void) {
  (PCB).btsx = 0, (PCB).drt = -1;
  (*(token *) &(PCB).vs[(PCB).ssx]) = (PCB).input_value;
  (PCB).ssx--;
  ag_ra();
  (PCB).ssx++;
  return 0;
}

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 = (ex_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 = (ex_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 = (ex_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) {
    ag_trace_error();
    (PCB).exit_flag = AG_STACK_ERROR_CODE;
    PARSER_STACK_OVERFLOW;
  }
  (*(token *) &(PCB).vs[(PCB).ssx]) = (PCB).input_value;
  (PCB).ss[(PCB).ssx] = (PCB).sn;
  (PCB).ssx++;
  (PCB).sn = (PCB).ag_ap;
  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).ss[(PCB).ssx] = (PCB).sn;
  (PCB).ssx++;
  (PCB).sn = (PCB).ag_ap;
  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).exit_flag = AG_SUCCESS_CODE;
  return 0;
}

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

static int ag_action_3_proc(void) {
  int ag_sd = ag_fl[(PCB).ag_ap] - 1;
  (PCB).btsx = 0, (PCB).drt = -1;
  (*(token *) &(PCB).vs[(PCB).ssx]) = (PCB).input_value;
  if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  else (PCB).ss[(PCB).ssx] = (PCB).sn;
  (PCB).reduction_token = (ex_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();
  ag_trace_error();
  (PCB).exit_flag = AG_SYNTAX_ERROR_CODE;
  SYNTAX_ERROR;
  
  return (PCB).exit_flag == AG_RUNNING_CODE;
}

static int ag_action_5_proc(void) {
  int ag_sd = ag_fl[(PCB).ag_ap];
  (PCB).btsx = 0, (PCB).drt = -1;
  if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  else {
    (PCB).ss[(PCB).ssx] = (PCB).sn;
  }
  (PCB).reduction_token = (ex_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 = (ex_token_type) ag_ptt[(PCB).ag_ap];
  if ((PCB).drt == -1) {
    (PCB).drt=(PCB).token_number;
    (PCB).dssx=(PCB).ssx;
    (PCB).dsn=(PCB).sn;
  }
  if (ag_sd) {
    (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd];
  }
  else {
    ag_prot();
    (PCB).vs[(PCB).ssx] = ag_null_value;
    (PCB).ss[(PCB).ssx] = (PCB).sn;
  }
  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_ex(void) {
  unsigned ag_t1;
  ag_t1 = 0;
  (PCB).error_message = "Syntax Error";
  (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0;
  (PCB).exit_flag = AG_RUNNING_CODE;
  (PCB).btsx = 0, (PCB).drt = -1;
  while (ag_tstt[ag_t1] == 0) {
    (PCB).ag_ap = ag_pstt[ag_t1];
    (ag_gt_procs_scan[ag_astt[ag_t1]])();
    ag_t1 = ag_sbt[(PCB).sn];
  }
}

void ex(void) {
  (PCB).token_number = (ex_token_type) AG_TCV((PCB).input_code);
  while (1) {
    unsigned ag_t1 = ag_sbt[(PCB).sn];
    unsigned ag_t2 = ag_sbe[(PCB).sn] - 1;
    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];
    if ((ag_gt_procs_scan[ag_astt[ag_t1]])() == 0) break;
  }
}