#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern char** clib_ArgV;
extern int Start_col, Curr_col, Curr_line_num;
extern char Inp_line[512];

char *Ignorables();
char *Ignorable_toks;
char **Token_sets();
char **Tok_set;
char Ignored_tokens[1024], *Ignored_toks;
int Tok;

void import_parser(){}

int clib_Parse(long *fn, long *mode){
  Tok_set = Token_sets();
  Ignorable_toks = Ignorables();
  Ignored_toks = Ignored_tokens; *Ignored_toks = 0;
  Init_scanner(fn, mode);
  Init_cbuilder();
  Tok = Next_token();
  Parse_goal();
  Skip(1);
};

int Match(char *Toks){
  do{
    if (Tok == 0) Note_error();
    if (strchr(Toks,Tok)) return 1;
    if (strpbrk(Toks,Ignored_tokens)) return 1;
    if (!strchr(Ignorable_toks,Tok)) return 0;
    *Ignored_toks = Tok; Ignored_toks += 1; *Ignored_toks = 0;
    Tok = Next_token();
  }while (1);
};

int Match1(int Tk){
  do{
    if (Tok == 0) Note_error();
    if (Tk == Tok || strchr(Ignored_tokens, Tk)) return 1;
    if (!strchr(Ignorable_toks,Tok)) return 0;
    *Ignored_toks = Tok; Ignored_toks += 1; *Ignored_toks = 0;
    Tok = Next_token();
  }while (1);
};

int Note_error(){
  int i;
  if (Tok == 1)
    fprintf(stderr, "%s(%i) ERROR: Source file ended too soon\n", clib_ArgV[1], Curr_line_num);
  else{
    fprintf(stderr, "%s(%i, %i) ERROR: Did not expect ", clib_ArgV[1], Curr_line_num, Start_col+1);
    for (i = Start_col; i < Curr_col; i++) fputc(Inp_line[i], stderr);
    fprintf(stderr, "\n");
  };
  exit(1);
};

int Skip(int Tk){
  char *p = strchr(Ignored_tokens,Tk);
  if (p != NULL){
    do {*p = 127; p = strchr(Ignored_tokens,Tk);} while (p != NULL);
    return;
  };
  while (Tk != Tok){
    if (!strchr(Ignorable_toks,Tok)) Note_error();
    Tok = Next_token();
  };
  Tok = Next_token();
  Ignored_toks = Ignored_tokens;  *Ignored_toks = 0; 
};

int Parse_identifier(){
  if (!Match1(3)) Note_error();
  Build_token("identifier", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

int Parse_float(){
  if (!Match1(4)) Note_error();
  Build_token("float", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

int Parse_integer(){
  if (!Match1(5)) Note_error();
  Build_token("integer", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

int Parse_string(){
  if (!Match1(6)) Note_error();
  Build_token("string", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

int Parse_bcomment(){
  if (!Match1(7)) Note_error();
  Build_token("bcomment", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

int Parse_ecomment(){
  if (!Match1(8)) Note_error();
  Build_token("ecomment", Inp_line, Start_col, Curr_col);
  Tok = Next_token();
  Ignored_toks = &Ignored_tokens[0]; *Ignored_toks = 0;
};

char *Ignorables(){
  char *igs = malloc(6);
  igs[0] = 2;
  igs[1] = 7;
  igs[2] = 8;
  igs[3] = 12;
  igs[4] = 30;
  igs[5] = 0;
  return igs;
};

int Parse_export(){
  Skip(80);
  Parse_identifiers();
  Build_export();
};

int Parse_uexpr(){
  if (Match(Tok_set[0])){
    if (Match1(21)){
      Skip(21);
    }else if (Match1(46)){
      Skip(46);
    }else{
      Note_error();
    };
    Parse_expr();
    Build_negate();
  }else if (Match(Tok_set[1])){
    if (Match1(14)){
      Skip(14);
    }else if (Match1(38)){
      Skip(38);
    }else{
      Note_error();
    };
    Parse_expr();
    Build_length();
  }else if (Match(Tok_set[2])){
    Parse_expr();
  }else{
    Note_error();
  };
};

int Parse_module(){
  Build_start_list();
  while (Match(Tok_set[3])){
    if (Match(Tok_set[4])){
      Parse_statement();
      Build_add_statement();
    }else if (Match1(91)){
      Parse_procedure();
      Build_add_statement();
    }else if (Match1(86)){
      Parse_function();
      Build_add_statement();
    }else if (Match1(45)){
      Parse_inv();
      Build_add_statement();
    }else{
      Skip(61);
    };
  };
  Build_module();
};

int Parse_function(){
  Skip(86);
  Parse_identifier();
  Parse_parameter_declarations();
  if (Match1(58)){
    Skip(58);
  }else if (Match1(71)){
    Skip(71);
  }else{
    Note_error();
  };
  Parse_type_expression();
  Build_result_type();
  Build_indent();
  Parse_statements();
  if (Match1(76)){
    Skip(76);
  };
  Build_function();
};

int Parse_name(){
  Parse_qual_ident();
  if (Match1(16)){
    Parse_selector_values();
  };
};

int Parse_selector_values(){
  Skip(16);
  Parse_expression();
  Build_make_selector();
  while (Match(Tok_set[5])){
    if (Match1(20)){
      Skip(20);
    };
    Parse_expression();
    Build_make_selector();
  };
  while (Match1(48)){
    Skip(48);
    Parse_expression();
    Build_make_selector();
    while (Match(Tok_set[5])){
      if (Match1(20)){
        Skip(20);
      };
      Parse_expression();
      Build_make_selector();
    };
  };
  Skip(17);
};

int Parse_arith_expr(){
  Parse_term();
  while (Match(Tok_set[6])){
    if (Match1(19)){
      Skip(19);
      Parse_term();
      Build_plus();
    }else{
      if (Match1(21)){
        Skip(21);
      }else if (Match1(60)){
        Skip(60);
      }else{
        Note_error();
      };
      Parse_term();
      Build_minus();
    };
  };
};

int Parse_put(){
  Build_start_list();
  if (Match1(74)){
    Skip(74);
    while (Match(Tok_set[7])){
      if (Match1(2)){
        /*Eol already skipped*/ break;
      }else{
        Parse_expression();
        Build_putcol_expression();
        Build_add_statement();
      };
    };
    if (Match1(15)){
      Skip(15);
    }else{
      Build_put_eol();
      Build_add_statement();
    };
  }else if (Match1(50)){
    Skip(50);
    Build_start_of_put();
    Build_add_statement();
    while (Match(Tok_set[8])){
      if (Match1(2)){
        /*Eol already skipped*/ break;
      }else if (Match1(20)){
        Skip(20);
        Build_put_comma();
        Build_add_statement();
      }else if (Match1(12)){
        Skip(12);
        Build_put_space();
        Build_add_statement();
      }else{
        Parse_expression();
        Build_put_expression();
        Build_add_statement();
        if (Match1(46)){
          Skip(46);
          Build_put_space();
          Build_add_statement();
          Parse_expr();
          Build_negate();
          Build_put_expression();
          Build_add_statement();
        }else if (Match1(38)){
          Skip(38);
          Build_put_space();
          Build_add_statement();
          Parse_expr();
          Build_length();
          Build_put_expression();
          Build_add_statement();
        };
      };
    };
    if (Match1(15)){
      Skip(15);
    }else{
      Build_put_eol();
      Build_add_statement();
    };
  }else{
    Note_error();
  };
  if (Match1(89)){
    Skip(89);
    Parse_expression();
    Build_when();
  };
};

int Parse_variable_definition(){
  Skip(29);
  Parse_type_expression();
  Build_declare_as_var();
  if (Match1(62)){
    Skip(62);
    Parse_expression();
    Build_assign();
  }else{
    Build_dec_ref();
  };
};

int Parse_get(){
  Skip(37);
  Parse_typed_names();
  Build_get();
};

int Parse_assert(){
  Skip(72);
  Parse_expression();
  Build_assert();
};

int Parse_generator(){
  Parse_expression();
  Build_generator();
};

int Parse_qual_ident(){
  Parse_identifier();
  if (Match1(22)){
    Skip(22);
    Parse_identifier();
    Build_qualify();
  };
};

int Parse_names(){
  Parse_name();
  if (Match1(30)){
    Skip(30);
  }else if (Match(Tok_set[9])){
    while (Match(Tok_set[9])){
      if (Match1(2)){
        /*Eol already skipped*/ break;
      }else{
        if (Match1(20)){
          Skip(20);
        };
        Parse_name();
        Build_make_name_list();
      };
    };
  };
};

int Parse_negation(){
  if (Match1(47)){
    Skip(47);
    Parse_relation();
    Build_not();
  }else if (Match(Tok_set[10])){
    Parse_relation();
  }else{
    Note_error();
  };
};

int Parse_while_loop(){
  Skip(10);
  Parse_expression();
  if (Match1(101)){
    Skip(101);
  };
  Build_indent();
  Parse_statements();
  if (Match1(93)){
    Skip(93);
    Build_while_loop();
  }else if (Match1(24)){
    Skip(24);
    Parse_expression();
    Build_while_until();
  }else{
    Note_error();
  };
};

int Parse_ids(){
  Parse_qual_ident();
  while (Match(Tok_set[11])){
    if (Match1(20)){
      Skip(20);
    };
    Parse_qual_ident();
    Build_make_name_list();
  };
};

int Parse_assignment(){
  if (Match1(62)){
    Skip(62);
    Parse_expression();
    Build_assign();
  }else if (Match1(79)){
    Skip(79);
    Parse_expression();
    Build_plus_assign();
  }else if (Match(Tok_set[12])){
    if (Match1(81)){
      Skip(81);
    }else if (Match1(96)){
      Skip(96);
    }else{
      Note_error();
    };
    Parse_expression();
    Build_minus_assign();
  }else if (Match1(83)){
    Skip(83);
    Parse_expression();
    Build_divide_assign();
  }else if (Match1(78)){
    Skip(78);
    Parse_expression();
    Build_multiply_assign();
  }else{
    Note_error();
  };
};

int Parse_parameter_declarations(){
  Build_start_list();
  if (Match1(16)){
    Skip(16);
    while (Match1(3)){
      Parse_parameter_declaration();
      if (Match1(20)){
        Skip(20);
      };
      Build_add_statement();
    };
    Skip(17);
  };
};

int Parse_set(){
  Skip(67);
  if (Match1(28)){
    Skip(28);
    Parse_expression();
    if (Match1(41)){
      Skip(41);
      Build_lazy();
      Parse_iterator();
      Build_make_eset();
    }else if (Match(Tok_set[13])){
      if (Match1(66)){
        Skip(66);
      }else if (Match1(11)){
        Skip(11);
      }else{
        Note_error();
      };
      Build_iterator();
      Parse_expression();
      Build_lazy();
      Build_make_filter();
      Build_make_set();
    }else{
      Build_iterator();
      Build_make_set();
    };
  }else if (Match(Tok_set[14])){
    Build_set_constructor();
    while (Match(Tok_set[14])){
      Parse_set_range();
      if (Match1(20)){
        Skip(20);
      };
    };
    Build_set_literal();
  }else{
    Build_set_constructor();
    Build_set_literal();
  };
  Skip(68);
};

int Parse_identifiers(){
  Build_start_list();
  Parse_identifier();
  Build_add_to_list();
  while (Match(Tok_set[9])){
    if (Match1(2)){
      /*Eol already skipped*/ break;
    }else{
      if (Match1(20)){
        Skip(20);
      };
      Parse_identifier();
      Build_add_to_list();
    };
  };
};

int Parse_goal(){
  Parse_module();
};

int Parse_import(){
  Skip(75);
  Parse_identifiers();
  Build_import();
};

int Parse_expr(){
  if (Match(Tok_set[15])){
    Parse_call();
  }else if (Match1(4)){
    Parse_float();
  }else if (Match1(5)){
    Parse_integer();
  }else if (Match1(6)){
    Parse_string();
    Build_string();
  }else if (Match1(52)){
    Parse_list();
  }else if (Match1(67)){
    Parse_set();
  }else if (Match1(16)){
    Skip(16);
    Parse_expression();
    Skip(17);
  }else if (Match1(43)){
    Skip(43);
    Skip(16);
    Parse_qual_ident();
    Build_new();
    while (Match(Tok_set[11])){
      if (Match1(20)){
        Skip(20);
      };
      Parse_identifier();
      if (Match1(20)){
        Skip(20);
      };
      Parse_expression();
      Build_set_attribute();
    };
    Skip(17);
  }else if (Match1(99)){
    Skip(99);
    Parse_expression();
    Skip(87);
    Parse_expression();
    Skip(85);
    Parse_expression();
    Build_cond_expr();
  }else if (Match(Tok_set[16])){
    if (Match1(44)){
      Skip(44);
    }else if (Match1(95)){
      Skip(95);
    }else{
      Note_error();
    };
    Skip(102);
    Parse_type_expression();
    Build_powerset();
  }else if (Match(Tok_set[17])){
    if (Match1(94)){
      Skip(94);
    }else if (Match1(23)){
      Skip(23);
    }else{
      Note_error();
    };
    Skip(102);
    Parse_type_expression();
    Build_list_of();
  }else if (Match(Tok_set[18])){
    if (Match1(33)){
      Skip(33);
    }else if (Match1(88)){
      Skip(88);
    }else{
      Note_error();
    };
    if (Match1(90)){
      Skip(90);
    };
    Parse_type_expressions();
    Skip(106);
    Parse_type_expression();
    Build_codomain();
  }else{
    Note_error();
  };
};

int Parse_parameter_declaration(){
  Build_start_list();
  Parse_identifier();
  Build_add_to_list();
  while (Match1(20)){
    Skip(20);
    Parse_identifier();
    Build_add_to_list();
  };
  if (Match1(29)){
    Skip(29);
    Parse_type_expression();
    Build_declare_typed_params();
  }else if (Match1(30)){
    Skip(30);
    Build_declare_params();
  }else{
    Build_declare_params();
  };
};

int Parse_express(){
  Parse_conjunction();
  while (Match1(105)){
    Skip(105);
    Parse_conjunction();
    Build_sc_or();
  };
};

int Parse_inv(){
  Skip(45);
  Parse_expression();
  Build_invariant();
};

int Parse_call(){
  if (Match1(3)){
    Parse_qual_ident();
    if (Match1(16)){
      Parse_parameter_values();
    }else if (Match1(35)){
      Skip(35);
      Parse_uexpr();
      Build_make_parameter();
      while (Match1(35)){
        Skip(35);
        Build_end_parlist();
        Parse_uexpr();
        Build_make_parameter();
      };
    };
    Build_evaluate();
  }else if (Match(Tok_set[19])){
    Parse_call_c();
  }else{
    Note_error();
  };
};

int Parse_set_range(){
  Parse_expression();
  if (Match(Tok_set[20])){
    if (Match1(53)){
      Skip(53);
    }else if (Match1(106)){
      Skip(106);
    }else{
      Note_error();
    };
    Parse_expression();
    if (Match1(104)){
      Skip(104);
      Parse_expression();
      Build_set_srange();
      Build_plus();
    }else{
      Build_set_range();
      Build_plus();
    };
  }else{
    Build_append();
  };
};

int Parse_iteration(){
  if (Match1(70)){
    Parse_repeat_loop();
  }else if (Match1(10)){
    Parse_while_loop();
  }else if (Match1(41)){
    Parse_for_loop();
  }else{
    Note_error();
  };
};

int Parse_expressions(){
  Build_start_list();
  if (Match(Tok_set[14])){
    Parse_expression();
    Build_add_to_list();
    while (Match(Tok_set[5])){
      if (Match1(20)){
        Skip(20);
      };
      Parse_expression();
      Build_add_to_list();
    };
  };
};

int Parse_call_c(){
  if (Match1(34)){
    Skip(34);
    Skip(22);
    Parse_identifier();
    Skip(16);
    Parse_expressions();
    Skip(17);
    Build_call_c_func();
  }else if (Match1(98)){
    Skip(98);
    Skip(22);
    Parse_identifier();
    Build_c_const();
  }else{
    Note_error();
  };
};

int Parse_statement(){
  if (Match1(80)){
    Build_check_indent();
    Parse_export();
  }else if (Match1(75)){
    Parse_import();
  }else if (Match(Tok_set[21])){
    Parse_put();
  }else if (Match(Tok_set[22])){
    Parse_conditional_statement();
  }else if (Match1(99)){
    Parse_selection();
  }else if (Match(Tok_set[23])){
    Parse_iteration();
  }else if (Match(Tok_set[19])){
    Parse_call_c();
  }else if (Match1(72)){
    Parse_assert();
  }else if (Match1(42)){
    Parse_pre();
  }else if (Match1(97)){
    Parse_post();
  }else{
    Note_error();
  };
};

int Parse_parameter_values(){
  Skip(16);
  if (Match(Tok_set[14])){
    Parse_expression();
    Build_make_parameter();
    while (Match(Tok_set[5])){
      if (Match1(20)){
        Skip(20);
      };
      Parse_expression();
      Build_make_parameter();
    };
  }else{
    Build_fcall();
  };
  while (Match1(48)){
    Skip(48);
    Build_end_parlist();
    if (Match(Tok_set[14])){
      Parse_expression();
      Build_make_parameter();
      while (Match(Tok_set[5])){
        if (Match1(20)){
          Skip(20);
        };
        Parse_expression();
        Build_make_parameter();
      };
    }else{
      Build_fcall();
    };
  };
  Skip(17);
};

int Parse_statements(){
  Build_start_list();
  while (Match(Tok_set[4])){
    Parse_statement();
    Build_add_statement();
  };
  Build_outdent();
  Build_end_statements();
};

int Parse_iterator(){
  Parse_ids();
  Skip(103);
  Parse_generator();
  Build_make_iterator();
  while (Match1(20)){
    Skip(20);
    Parse_ids();
    Skip(103);
    Parse_generator();
    Build_lazy();
    Build_make_nested_iterator();
  };
  if (Match(Tok_set[13])){
    if (Match1(66)){
      Skip(66);
    }else if (Match1(11)){
      Skip(11);
    }else{
      Note_error();
    };
    Parse_expression();
    Build_lazy();
    Build_make_filter();
  };
};

int Parse_expression(){
  Parse_express();
  if (Match1(107)){
    Skip(107);
    Build_lazy();
    Parse_iterator();
    Build_forsome();
  }else if (Match1(69)){
    Skip(69);
    Build_lazy();
    Parse_iterator();
    Build_forany();
  }else if (Match1(29)){
    Skip(29);
    Parse_express();
    Build_pair();
  };
};

int Parse_post(){
  Skip(97);
  Parse_expression();
  Build_postcondition();
};

int Parse_pre(){
  Skip(42);
  Parse_expression();
  Build_precondition();
};

int Parse_factor(){
  Parse_def_expr();
  if (Match1(49)){
    Skip(49);
    Parse_factor();
    Build_exponentiate();
  };
};

int Parse_relation(){
  Parse_arith_expr();
  if (Match1(47)){
    Skip(47);
    if (Match1(103)){
      Skip(103);
      Parse_arith_expr();
      Build_in();
      Build_not();
    }else if (Match1(73)){
      Skip(73);
      Parse_arith_expr();
      Build_subset();
      Build_not();
    }else{
      Note_error();
    };
  }else if (Match(Tok_set[24])){
    if (Match1(14)){
      Skip(14);
    }else if (Match1(56)){
      Skip(56);
    }else if (Match1(59)){
      Skip(59);
    }else{
      Note_error();
    };
    Parse_arith_expr();
    Build_eq();
    Build_not();
  }else if (Match1(103)){
    Skip(103);
    Parse_arith_expr();
    Build_in();
  }else if (Match(Tok_set[25])){
    if (Match1(32)){
      Skip(32);
      Parse_arith_expr();
      Build_eq();
    }else if (Match1(31)){
      Skip(31);
      Parse_arith_expr();
      Build_lt();
    }else if (Match1(63)){
      Skip(63);
      Parse_arith_expr();
      Build_le();
    }else if (Match1(39)){
      Skip(39);
      Parse_arith_expr();
      Build_gt();
    }else if (Match1(65)){
      Skip(65);
      Parse_arith_expr();
      Build_ge();
    }else if (Match1(73)){
      Skip(73);
      Parse_arith_expr();
      Build_subset();
    }else{
      Note_error();
    };
    while (Match(Tok_set[25])){
      if (Match1(32)){
        Skip(32);
        Parse_arith_expr();
        Build_eq();
        Build_transitive();
      }else if (Match1(31)){
        Skip(31);
        Parse_arith_expr();
        Build_lt();
        Build_transitive();
      }else if (Match1(63)){
        Skip(63);
        Parse_arith_expr();
        Build_le();
        Build_transitive();
      }else if (Match1(39)){
        Skip(39);
        Parse_arith_expr();
        Build_gt();
        Build_transitive();
      }else if (Match1(65)){
        Skip(65);
        Parse_arith_expr();
        Build_ge();
        Build_transitive();
      }else{
        Skip(73);
        Parse_arith_expr();
        Build_subset();
        Build_transitive();
      };
    };
  };
};

int Parse_procedure(){
  Skip(91);
  Parse_identifier();
  Parse_parameter_declarations();
  Build_indent();
  Parse_statements();
  if (Match1(84)){
    Skip(84);
  };
  Build_procedure();
};

int Parse_term(){
  Parse_factor();
  while (Match(Tok_set[26])){
    if (Match1(100)){
      Skip(100);
      Parse_factor();
      Build_intersect();
    }else if (Match1(18)){
      Skip(18);
      Parse_factor();
      Build_multiply();
    }else{
      Skip(25);
      Parse_factor();
      Build_divide();
    };
  };
};

int Parse_repeat_loop(){
  Skip(70);
  Build_indent();
  Parse_statements();
  if (Match1(93)){
    Skip(93);
    Build_repeat_loop();
  }else if (Match1(24)){
    Skip(24);
    Parse_expression();
    Build_repeat_until();
  }else{
    Note_error();
  };
};

int Parse_conditional_statement(){
  Build_start_list();
  if (Match1(77)){
    Skip(77);
    if (Match1(2)){
      /*Eol already skipped*/
    }else if (Match(Tok_set[14])){
      Parse_expression();
      Build_result();
      Build_add_statement();
    };
    Build_return();
  }else if (Match1(92)){
    Skip(92);
    if (Match1(2)){
      /*Eol already skipped*/
      Build_exit();
    }else if (Match1(5)){
      Parse_integer();
      Build_multi_exit();
    }else{
      Build_exit();
    };
  }else if (Match1(37)){
    Parse_get();
  }else if (Match1(3)){
    Parse_names();
    if (Match(Tok_set[27])){
      Parse_assignment();
    }else if (Match1(32)){
      Parse_constant_definition();
    }else if (Match1(29)){
      Parse_variable_definition();
    }else{
      Build_call();
    };
  }else{
    Note_error();
  };
  Build_add_statement();
  if (Match1(89)){
    Skip(89);
    Parse_expression();
    Build_when();
  };
};

int Parse_type_expression(){
  Parse_expression();
  Build_make_type();
};

int Parse_conjunction(){
  Parse_negation();
  while (Match1(26)){
    Skip(26);
    Parse_negation();
    Build_sc_and();
  };
};

int Parse_list(){
  Skip(52);
  if (Match1(28)){
    Skip(28);
    Parse_expression();
    if (Match1(41)){
      Skip(41);
      Build_lazy();
      Parse_iterator();
      Build_make_elist();
    }else if (Match(Tok_set[13])){
      if (Match1(66)){
        Skip(66);
      }else if (Match1(11)){
        Skip(11);
      }else{
        Note_error();
      };
      Build_iterator();
      Parse_expression();
      Build_lazy();
      Build_make_filter();
      Build_make_list();
    }else{
      Build_iterator();
      Build_make_list();
    };
  }else if (Match(Tok_set[14])){
    Build_list_constructor();
    while (Match(Tok_set[14])){
      Parse_list_range();
      if (Match1(20)){
        Skip(20);
      };
    };
    Build_list_literal();
  }else{
    Build_list_constructor();
    Build_list_literal();
  };
  Skip(54);
};

int Parse_constant_definition(){
  Skip(32);
  Parse_expression();
  Build_constant();
};

int Parse_type_expressions(){
  Build_map_constructor();
  Parse_type_expression();
  Build_domain();
  while (Match(Tok_set[5])){
    if (Match1(20)){
      Skip(20);
    };
    Parse_type_expression();
    Build_domain();
  };
};

int Parse_def_expr(){
  Parse_uexpr();
  if (Match1(36)){
    Skip(36);
    Parse_uexpr();
    Build_sc_if_def();
  };
};

int Parse_typed_name(){
  Parse_identifier();
  if (Match1(16)){
    Parse_selector_values();
  }else if (Match1(29)){
    Skip(29);
    Parse_type_expression();
    Build_declare_as_var();
  };
};

int Parse_typed_names(){
  Parse_typed_name();
  while (Match(Tok_set[9])){
    if (Match1(2)){
      /*Eol already skipped*/ break;
    }else{
      if (Match1(20)){
        Skip(20);
      };
      Parse_typed_name();
      Build_make_name_list();
    };
  };
};

int Parse_list_range(){
  Parse_expression();
  if (Match(Tok_set[20])){
    if (Match1(53)){
      Skip(53);
    }else if (Match1(106)){
      Skip(106);
    }else{
      Note_error();
    };
    Parse_expression();
    if (Match1(104)){
      Skip(104);
      Parse_expression();
      Build_list_srange();
      Build_plus();
    }else{
      Build_list_range();
      Build_plus();
    };
  }else{
    Build_append();
  };
};

int Parse_selection(){
  Skip(99);
  Parse_expression();
  if (Match1(87)){
    Skip(87);
  };
  Build_indent();
  Parse_statements();
  Build_if();
  while (Match1(9)){
    Skip(9);
    Parse_expression();
    if (Match1(87)){
      Skip(87);
    };
    Build_indent();
    Parse_statements();
    Build_elsif();
  };
  if (Match1(85)){
    Skip(85);
    Build_indent();
    Parse_statements();
    Build_else();
  };
  if (Match1(27)){
    Skip(27);
  }else if (Match1(82)){
    Skip(82);
  }else{
    Note_error();
  };
  Build_endif();
};

int Parse_for_loop(){
  Skip(41);
  Parse_iterator();
  if (Match1(101)){
    Skip(101);
  };
  Build_indent();
  Parse_statements();
  if (Match1(93)){
    Skip(93);
    Build_for_loop();
  }else if (Match1(24)){
    Skip(24);
    Parse_expression();
    Build_for_until();
  }else{
    Note_error();
  };
};

char **Token_sets(){
  char** ts = malloc(112);
  ts[24] = malloc(4);
  ts[24][0] = 56;
  ts[24][1] = 59;
  ts[24][2] = 14;
  ts[24][3] = 0;
  ts[0] = malloc(3);
  ts[0][0] = 21;
  ts[0][1] = 46;
  ts[0][2] = 0;
  ts[19] = malloc(3);
  ts[19][0] = 34;
  ts[19][1] = 98;
  ts[19][2] = 0;
  ts[15] = malloc(4);
  ts[15][0] = 34;
  ts[15][1] = 3;
  ts[15][2] = 98;
  ts[15][3] = 0;
  ts[14] = malloc(23);
  ts[14][0] = 33;
  ts[14][1] = 34;
  ts[14][2] = 3;
  ts[14][3] = 98;
  ts[14][4] = 4;
  ts[14][5] = 38;
  ts[14][6] = 5;
  ts[14][7] = 6;
  ts[14][8] = 67;
  ts[14][9] = 99;
  ts[14][10] = 43;
  ts[14][11] = 44;
  ts[14][12] = 46;
  ts[14][13] = 47;
  ts[14][14] = 14;
  ts[14][15] = 16;
  ts[14][16] = 52;
  ts[14][17] = 21;
  ts[14][18] = 23;
  ts[14][19] = 88;
  ts[14][20] = 94;
  ts[14][21] = 95;
  ts[14][22] = 0;
  ts[16] = malloc(3);
  ts[16][0] = 44;
  ts[16][1] = 95;
  ts[16][2] = 0;
  ts[7] = malloc(24);
  ts[7][0] = 33;
  ts[7][1] = 2;
  ts[7][2] = 34;
  ts[7][3] = 3;
  ts[7][4] = 98;
  ts[7][5] = 4;
  ts[7][6] = 38;
  ts[7][7] = 5;
  ts[7][8] = 6;
  ts[7][9] = 67;
  ts[7][10] = 99;
  ts[7][11] = 43;
  ts[7][12] = 44;
  ts[7][13] = 46;
  ts[7][14] = 47;
  ts[7][15] = 14;
  ts[7][16] = 16;
  ts[7][17] = 52;
  ts[7][18] = 21;
  ts[7][19] = 23;
  ts[7][20] = 88;
  ts[7][21] = 94;
  ts[7][22] = 95;
  ts[7][23] = 0;
  ts[13] = malloc(3);
  ts[13][0] = 66;
  ts[13][1] = 11;
  ts[13][2] = 0;
  ts[26] = malloc(4);
  ts[26][0] = 18;
  ts[26][1] = 100;
  ts[26][2] = 25;
  ts[26][3] = 0;
  ts[22] = malloc(5);
  ts[22][0] = 3;
  ts[22][1] = 37;
  ts[22][2] = 92;
  ts[22][3] = 77;
  ts[22][4] = 0;
  ts[11] = malloc(3);
  ts[11][0] = 3;
  ts[11][1] = 20;
  ts[11][2] = 0;
  ts[9] = malloc(4);
  ts[9][0] = 2;
  ts[9][1] = 3;
  ts[9][2] = 20;
  ts[9][3] = 0;
  ts[4] = malloc(18);
  ts[4][0] = 97;
  ts[4][1] = 34;
  ts[4][2] = 3;
  ts[4][3] = 99;
  ts[4][4] = 37;
  ts[4][5] = 70;
  ts[4][6] = 98;
  ts[4][7] = 72;
  ts[4][8] = 41;
  ts[4][9] = 74;
  ts[4][10] = 75;
  ts[4][11] = 10;
  ts[4][12] = 77;
  ts[4][13] = 42;
  ts[4][14] = 80;
  ts[4][15] = 50;
  ts[4][16] = 92;
  ts[4][17] = 0;
  ts[10] = malloc(22);
  ts[10][0] = 33;
  ts[10][1] = 34;
  ts[10][2] = 3;
  ts[10][3] = 98;
  ts[10][4] = 4;
  ts[10][5] = 38;
  ts[10][6] = 5;
  ts[10][7] = 6;
  ts[10][8] = 67;
  ts[10][9] = 99;
  ts[10][10] = 43;
  ts[10][11] = 44;
  ts[10][12] = 46;
  ts[10][13] = 14;
  ts[10][14] = 16;
  ts[10][15] = 52;
  ts[10][16] = 21;
  ts[10][17] = 23;
  ts[10][18] = 88;
  ts[10][19] = 94;
  ts[10][20] = 95;
  ts[10][21] = 0;
  ts[5] = malloc(24);
  ts[5][0] = 33;
  ts[5][1] = 34;
  ts[5][2] = 3;
  ts[5][3] = 98;
  ts[5][4] = 4;
  ts[5][5] = 38;
  ts[5][6] = 5;
  ts[5][7] = 6;
  ts[5][8] = 67;
  ts[5][9] = 99;
  ts[5][10] = 43;
  ts[5][11] = 44;
  ts[5][12] = 46;
  ts[5][13] = 47;
  ts[5][14] = 14;
  ts[5][15] = 16;
  ts[5][16] = 20;
  ts[5][17] = 52;
  ts[5][18] = 21;
  ts[5][19] = 23;
  ts[5][20] = 88;
  ts[5][21] = 94;
  ts[5][22] = 95;
  ts[5][23] = 0;
  ts[20] = malloc(3);
  ts[20][0] = 53;
  ts[20][1] = 106;
  ts[20][2] = 0;
  ts[27] = malloc(7);
  ts[27][0] = 96;
  ts[27][1] = 81;
  ts[27][2] = 79;
  ts[27][3] = 83;
  ts[27][4] = 78;
  ts[27][5] = 62;
  ts[27][6] = 0;
  ts[2] = malloc(18);
  ts[2][0] = 33;
  ts[2][1] = 34;
  ts[2][2] = 3;
  ts[2][3] = 98;
  ts[2][4] = 4;
  ts[2][5] = 5;
  ts[2][6] = 6;
  ts[2][7] = 67;
  ts[2][8] = 99;
  ts[2][9] = 43;
  ts[2][10] = 44;
  ts[2][11] = 16;
  ts[2][12] = 52;
  ts[2][13] = 23;
  ts[2][14] = 88;
  ts[2][15] = 94;
  ts[2][16] = 95;
  ts[2][17] = 0;
  ts[6] = malloc(4);
  ts[6][0] = 19;
  ts[6][1] = 21;
  ts[6][2] = 60;
  ts[6][3] = 0;
  ts[8] = malloc(26);
  ts[8][0] = 2;
  ts[8][1] = 3;
  ts[8][2] = 4;
  ts[8][3] = 5;
  ts[8][4] = 6;
  ts[8][5] = 67;
  ts[8][6] = 12;
  ts[8][7] = 14;
  ts[8][8] = 16;
  ts[8][9] = 20;
  ts[8][10] = 21;
  ts[8][11] = 23;
  ts[8][12] = 88;
  ts[8][13] = 94;
  ts[8][14] = 95;
  ts[8][15] = 33;
  ts[8][16] = 34;
  ts[8][17] = 98;
  ts[8][18] = 99;
  ts[8][19] = 38;
  ts[8][20] = 43;
  ts[8][21] = 44;
  ts[8][22] = 46;
  ts[8][23] = 47;
  ts[8][24] = 52;
  ts[8][25] = 0;
  ts[25] = malloc(7);
  ts[25][0] = 32;
  ts[25][1] = 63;
  ts[25][2] = 65;
  ts[25][3] = 39;
  ts[25][4] = 73;
  ts[25][5] = 31;
  ts[25][6] = 0;
  ts[12] = malloc(3);
  ts[12][0] = 96;
  ts[12][1] = 81;
  ts[12][2] = 0;
  ts[1] = malloc(3);
  ts[1][0] = 38;
  ts[1][1] = 14;
  ts[1][2] = 0;
  ts[17] = malloc(3);
  ts[17][0] = 23;
  ts[17][1] = 94;
  ts[17][2] = 0;
  ts[3] = malloc(22);
  ts[3][0] = 97;
  ts[3][1] = 34;
  ts[3][2] = 3;
  ts[3][3] = 99;
  ts[3][4] = 37;
  ts[3][5] = 70;
  ts[3][6] = 98;
  ts[3][7] = 72;
  ts[3][8] = 41;
  ts[3][9] = 74;
  ts[3][10] = 75;
  ts[3][11] = 10;
  ts[3][12] = 77;
  ts[3][13] = 42;
  ts[3][14] = 45;
  ts[3][15] = 80;
  ts[3][16] = 50;
  ts[3][17] = 86;
  ts[3][18] = 91;
  ts[3][19] = 92;
  ts[3][20] = 61;
  ts[3][21] = 0;
  ts[23] = malloc(4);
  ts[23][0] = 70;
  ts[23][1] = 41;
  ts[23][2] = 10;
  ts[23][3] = 0;
  ts[18] = malloc(3);
  ts[18][0] = 33;
  ts[18][1] = 88;
  ts[18][2] = 0;
  ts[21] = malloc(3);
  ts[21][0] = 50;
  ts[21][1] = 74;
  ts[21][2] = 0;
  return ts;
};
