#error This is not directly used in anything at the moment.
// It is here for incorporating as the basis of a compile() function to do something useful with an AST.
// For example this generated the code that was manually converted into algol60-indent.h

#define X_APP 1
#include <stdio.h>

#define AST_idx_mask 0x7FFFFFFU
#define AST_type_shift 27U
#define AST_type_mask  31U
#define AST_BIP      (16U << AST_type_shift)
#define AST_PHRASE   (17U << AST_type_shift)
#define AST_ATOM_LIT (18U << AST_type_shift)

//int AST(int idx) {
//}

//int wlit(int P) {
//}

//int P(int P_) {
//}
int compile(int Ph, int depth) {

  // AST format not properly designed yet.  These are placeholders:
#define P(x) (x) // TEMP
#define A(x) (x) // TEMP
#define wlit(x) (x)

  int AST_index = Ph&AST_idx_mask;
  int AST_type  = Ph & (AST_type_mask << AST_type_shift);
  int op    = A(AST_index+1);
  int alt   = A(AST_index+2);
  int count = A(AST_index+3);
  int t[LARGEST_ALT];
  int r = 0;

  fprintf(stderr, "Ph=%d AST_type = %d  AST_index = %d  op=%d  alt=%d  count=%d\n", Ph, AST_type>>AST_type_shift, AST_index, op, alt, count);

  switch (op) {
    // It is here for incorporating as the basis of a compile() function to do something useful with an AST.
    // For example this generated the code that was manually converted into algol60-indent.h

//\\ B<EOF> = 0;
//\\#
//\\ P<empty> =
   case P_empty:
#ifdef IN_PARSER

  return -1;

#endif
     {                              //\\    "";
     t[1] = wlit(P(1));
     return t[0] = P_mktuple(P_empty, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<SS> =
   case P_SS:
#ifdef IN_PARSER

  return T[1];

#endif
     {                              //\\    <instruction-list> <EOF>;
     t[1] = compile(P(1), depth+1 /* P_instruction_list */);
     t[2] = wlit(P(2) /*, L"EOF" */);
     return t[0] = P_mktuple(P_SS, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<array> =
   case P_array:
#ifdef IN_PARSER

  return AST_mktuple(AST_list, T[2]);

#endif
     {                              //\\    "[" <value-list> "]";
     t[1] = wlit(P(1));
     t[2] = compile(P(2), depth+1 /* P_value_list */);
     t[3] = wlit(P(3));
     return t[0] = P_mktuple(P_array, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<opt-sign> =
   case P_opt_sign:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  if (alt != 0) return -1;
  return AST_mktuple(AST_source_text, T[1], -1);  

#endif
     if (alt == 0)               {  //\\    "-",
       t[1] = wlit(P(1));
       return t[0] = P_mktuple(P_opt_sign, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_opt_sign, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<number> =
   case P_number:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  if (T[1] == -1) return T[2];
  {
    int sign;
    AST_detuple(T[1], AST_source_text, &sign, NULL);
    return AST_mktuple(AST_number, AST_mktuple(AST_source_text, sign, T[2]));
  }

#endif
     if (alt == 0)               {  //\\    <opt-sign> <float>,
       t[1] = compile(P(1), depth+1 /* P_opt_sign */);
       t[2] = compile(P(2), depth+1 /* P_float */);
       return t[0] = P_mktuple(P_number, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <opt-sign> <integer>;
       t[1] = compile(P(1), depth+1 /* P_opt_sign */);
       t[2] = compile(P(2), depth+1 /* P_integer */);
       return t[0] = P_mktuple(P_number, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<boolean> =
   case P_boolean:
#ifdef IN_PARSER

  return AST_mktuple(AST_boolean, AST_mktuple(AST_source_text, T[1], -1));

#endif
     if (alt == 0)               {  //\\    "true",
       t[1] = wlit(P(1));
       return t[0] = P_mktuple(P_boolean, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else if (alt == 1)        {  //\\    "false",
       t[1] = wlit(P(1));
       return t[0] = P_mktuple(P_boolean, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    "undef";
       t[1] = wlit(P(1));
       return t[0] = P_mktuple(P_boolean, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<value> =
   case P_value:
#ifdef IN_PARSER

  if (alt == 3) {
    fprintf(stdout, "*** AN INSTRUCTION SHOULD NEVER BE FOUND AS A VALUE ***\n");
    fprintf(stderr, "*** AN INSTRUCTION SHOULD NEVER BE FOUND AS A VALUE ***\n");
  }
  return T[1];

#endif
     if (alt == 0)               {  //\\    <boolean>,
       t[1] = compile(P(1), depth+1 /* P_boolean */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else if (alt == 1)        {  //\\    <array>,
       t[1] = compile(P(1), depth+1 /* P_array */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else if (alt == 2)        {  //\\    <number>,
       t[1] = compile(P(1), depth+1 /* P_number */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else if (alt == 3)        {  //\\    <instruction>,
       t[1] = compile(P(1), depth+1 /* P_instruction */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else if (alt == 4)        {  //\\    <name>,
       t[1] = compile(P(1), depth+1 /* P_name */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <string>;
       t[1] = compile(P(1), depth+1 /* P_string */);
       return t[0] = P_mktuple(P_value, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<rest-of-value-list> =
   case P_rest_of_value_list:
#ifdef IN_PARSER

  // returns AST_list_element containing << value, next_value >>
  if (alt != 0) return -1;
  return AST_mktuple(AST_list_element, T[2], T[3]);

#endif
     if (alt == 0)               {  //\\    "," <value> <rest-of-value-list>,
       t[1] = wlit(P(1));
       t[2] = compile(P(2), depth+1 /* P_value */);
       t[3] = compile(P(3), depth+1 /* P_rest_of_value_list */);
       return t[0] = P_mktuple(P_rest_of_value_list, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_rest_of_value_list, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<value-list> =
   case P_value_list:
#ifdef IN_PARSER

  // returns AST_list_element containing << value, next_value >>
  return AST_mktuple(AST_list_element, T[1], T[2]);

#endif
     {                              //\\    <value> <rest-of-value-list>;
     t[1] = compile(P(1), depth+1 /* P_value */);
     t[2] = compile(P(2), depth+1 /* P_rest_of_value_list */);
     return t[0] = P_mktuple(P_value_list, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<quote> =
   case P_quote:
#ifdef IN_PARSER

  return -1;

#endif
     {                              //\\    «"»;
     t[1] = wlit(P(1));
     return t[0] = P_mktuple(P_quote, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<char> =
   case P_char:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  return AST_mktuple(AST_source_text, T[2], -1);

#endif
     {                              //\\    <!quote> «.»;
     t[1] = -1; /* ignore negative guard */;
     t[2] = wlit(P(2));
     return t[0] = P_mktuple(P_char, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<chars> =
   case P_chars:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  if (alt != 0) return -1;
  int text;
  AST_detuple(T[1], AST_source_text, &text, NULL);
  return AST_mktuple(AST_source_text, text, T[2]);

#endif
     if (alt == 0)               {  //\\    <char> <chars>,
       t[1] = compile(P(1), depth+1 /* P_char */);
       t[2] = compile(P(2), depth+1 /* P_chars */);
       return t[0] = P_mktuple(P_chars, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_chars, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<string> =
   case P_string:
#ifdef IN_PARSER

  return AST_mktuple(AST_string, T[2]);

#endif
     {                              //\\    <quote> <chars> <quote>;
     t[1] = compile(P(1), depth+1 /* P_quote */);
     t[2] = compile(P(2), depth+1 /* P_chars */);
     t[3] = compile(P(3), depth+1 /* P_quote */);
     return t[0] = P_mktuple(P_string, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<name> =
   case P_name:
#ifdef IN_PARSER

  return AST_mktuple(AST_name, AST_mktuple(AST_source_text, T[1], -1));

#endif
     {                              //\\    «[A-Za-z\$][A-Za-z0-9_]*»;
     t[1] = wlit(P(1));
     return t[0] = P_mktuple(P_name, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<opt-exponent> =
   case P_opt_exponent:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  if (alt != 0) return -1;
  if (T[2] == -1) {
    return AST_mktuple(AST_source_text, T[1], T[3]);
  } else {
    AST_detuple(T[2], AST_source_text, &text, NULL);
    if (text == -1) {
      return AST_mktuple(AST_source_text, T[1], T[3]);
    } else {
      return AST_mktuple(AST_source_text, T[1], AST_mktuple(AST_source_text, text, T[3]));
    }
  }

#endif
     if (alt == 0)               {  //\\    «[Ee]» <opt-sign> <integer>,
       t[1] = wlit(P(1));
       t[2] = compile(P(2), depth+1 /* P_opt_sign */);
       t[3] = compile(P(3), depth+1 /* P_integer */);
       return t[0] = P_mktuple(P_opt_exponent, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_opt_exponent, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<float> =
   case P_float:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  return AST_mktuple(AST_source_text, T[1], T[2]);

#endif
     {                              //\\    «[0-9]*\.[0-9][0-9]*» <opt-exponent>;
     t[1] = wlit(P(1));
     t[2] = compile(P(2), depth+1 /* P_opt_exponent */);
     return t[0] = P_mktuple(P_float, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<integer> =
   case P_integer:
#ifdef IN_PARSER

  // returns AST_source_text containing  <<text_descriptor, next_concatenated_text>>
  return AST_mktuple(AST_source_text, T[1], -1);

#endif
     {                              //\\    «[0-9][0-9]*»;
     t[1] = wlit(P(1));
     return t[0] = P_mktuple(P_integer, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<argument> =
   case P_argument:
#ifdef IN_PARSER

  // returns AST_argument containing << name, value, next_arg >>
  if (alt == 0) return AST_mktuple(AST_argument, T[1], T[3], -1);
  return AST_mktuple(AST_argument, -1, T[1], -1);

#endif
     if (alt == 0)               {  //\\    <name> "=" <value>,
       t[1] = compile(P(1), depth+1 /* P_name */);
       t[2] = wlit(P(2));
       t[3] = compile(P(3), depth+1 /* P_value */);
       return t[0] = P_mktuple(P_argument, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <value>;
       t[1] = compile(P(1), depth+1 /* P_value */);
       return t[0] = P_mktuple(P_argument, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<rest-of-argument-list> =
   case P_rest_of_argument_list:
#ifdef IN_PARSER

  // returns AST_argument containing << name, value, next_arg >>
  {
    int name, value;
    if (alt != 0) return -1;
    AST_detuple(T[2], AST_argument, &name, &value, NULL);
    return AST_mktuple(AST_argument, name, value, T[3]);
  }

#endif
     if (alt == 0)               {  //\\    "," <argument> <rest-of-argument-list>,
       t[1] = wlit(P(1));
       t[2] = compile(P(2), depth+1 /* P_argument */);
       t[3] = compile(P(3), depth+1 /* P_rest_of_argument_list */);
       return t[0] = P_mktuple(P_rest_of_argument_list, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_rest_of_argument_list, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<opt-argument-list> =
   case P_opt_argument_list:
#ifdef IN_PARSER

  // returns AST_argument containing << name, value, next_arg >>
  {
    int name, value;
    if (alt != 0) return -1;
    AST_detuple(T[1], AST_argument, &name, &value, NULL);
    return AST_mktuple(AST_argument, name, value, T[2]);
  }

#endif
     if (alt == 0)               {  //\\    <argument> <rest-of-argument-list>,
       t[1] = compile(P(1), depth+1 /* P_argument */);
       t[2] = compile(P(2), depth+1 /* P_rest_of_argument_list */);
       return t[0] = P_mktuple(P_opt_argument_list, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_opt_argument_list, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<instruction> =
   case P_instruction:
#ifdef IN_PARSER

  // returns AST_instruction tuple containing <<name, argument list, block, next instruction>>
  // (I'll ignore any modifiers present for now.)
  return AST_mktuple(AST_instruction, T[2], T[4], T[6], -1);

#endif
     {                              //\\    «[%#!*]*» <name> "(" <opt-argument-list> ")" <opt-block>;
     t[1] = wlit(P(1));
     t[2] = compile(P(2), depth+1 /* P_name */);
     t[3] = wlit(P(3));
     t[4] = compile(P(4), depth+1 /* P_opt_argument_list */);
     t[5] = wlit(P(5));
     t[6] = compile(P(6), depth+1 /* P_opt_block */);
     return t[0] = P_mktuple(P_instruction, alt, 6/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<instruction-list> =
   case P_instruction_list:
#ifdef IN_PARSER

  // returns AST_instruction tuple containing <<name, argument list, block, next instruction>>
  {
    int name, args, block;
    if (alt != 0) return -1;
    AST_detuple(T[1], AST_instruction, &name, &args, &block, NULL);
    return AST_mktuple(AST_instruction, name, args, block, T[2]);
  }

#endif
     if (alt == 0)               {  //\\    <instruction> <instruction-list>,
       t[1] = compile(P(1), depth+1 /* P_instruction */);
       t[2] = compile(P(2), depth+1 /* P_instruction_list */);
       return t[0] = P_mktuple(P_instruction_list, alt, 2/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    <empty>;
       t[1] = compile(P(1), depth+1 /* P_empty */);
       return t[0] = P_mktuple(P_instruction_list, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ P<opt-block> =
   case P_opt_block:
#ifdef IN_PARSER

  if (alt != 0) return -1;
  return T[2];

#endif
     if (alt == 0)               {  //\\    "{" <instruction-list> "}",
       t[1] = wlit(P(1));
       t[2] = compile(P(2), depth+1 /* P_instruction_list */);
       t[3] = wlit(P(3));
       return t[0] = P_mktuple(P_opt_block, alt, 3/*phrases*/, t); /* (note t[], not T[]) */

     } else                      {  //\\    ";";
       t[1] = wlit(P(1));
       return t[0] = P_mktuple(P_opt_block, alt, 1/*phrases*/, t); /* (note t[], not T[]) */

     }
//\\ E
   default:
     return r;
  }
}
