#include <string.h>
#include "cdefs.h"
extern cptr identifier_methods[meth_max];
extern cptr idstring_methods[meth_max];
extern cptr integer_methods[meth_max];
extern cptr sstring_methods[meth_max];
extern int Start_col;
extern int Curr_line_num;

cptr Saved_start_col;
cptr Saved_curr_line_num;

cptr CTokstring;
cptr Cadd_to_list;
cptr Ccurclause;
cptr Cstart_list;
cptr Cadd_instruction;
cptr Cidclause;
cptr CTokname;
cptr CCurr_line_num;
cptr Crouclause;
cptr Cnopars;
cptr Cstrclause;
cptr Crulee;
cptr Ctoken;
cptr Csqclause;
cptr Cgoal;
cptr CStart_col;
cptr Cangclause;

void import_cbuilder(){}

int Init_cbuilder(){
  CTokname = mem_malloc(identifier_methods[0]);
  CTokname[0] = identifier_methods;
  identifier_alloc(CTokname, "Tokname");
  CTokstring = mem_malloc(identifier_methods[0]);
  CTokstring[0] = identifier_methods;
  identifier_alloc(CTokstring, "Tokstring");
  CStart_col = mem_malloc(identifier_methods[0]);
  CStart_col[0] = identifier_methods;
  identifier_alloc(CStart_col, "Start_col");
  CCurr_line_num = mem_malloc(identifier_methods[0]);
  CCurr_line_num[0] = identifier_methods;
  identifier_alloc(CCurr_line_num, "Curr_line_num");
  Ctoken = mem_malloc(identifier_methods[0]);
  Ctoken[0] = identifier_methods;
  identifier_alloc(Ctoken, "Build_token");
  Csqclause = mem_malloc(identifier_methods[0]);
  Csqclause[0] = identifier_methods;
  identifier_alloc(Csqclause, "Build_sqclause");
  Cgoal = mem_malloc(identifier_methods[0]);
  Cgoal[0] = identifier_methods;
  identifier_alloc(Cgoal, "Build_goal");
  Cadd_to_list = mem_malloc(identifier_methods[0]);
  Cadd_to_list[0] = identifier_methods;
  identifier_alloc(Cadd_to_list, "Build_add_to_list");
  Ccurclause = mem_malloc(identifier_methods[0]);
  Ccurclause[0] = identifier_methods;
  identifier_alloc(Ccurclause, "Build_curclause");
  Cstart_list = mem_malloc(identifier_methods[0]);
  Cstart_list[0] = identifier_methods;
  identifier_alloc(Cstart_list, "Build_start_list");
  Cadd_instruction = mem_malloc(identifier_methods[0]);
  Cadd_instruction[0] = identifier_methods;
  identifier_alloc(Cadd_instruction, "Build_add_instruction");
  Cidclause = mem_malloc(identifier_methods[0]);
  Cidclause[0] = identifier_methods;
  identifier_alloc(Cidclause, "Build_idclause");
  Crouclause = mem_malloc(identifier_methods[0]);
  Crouclause[0] = identifier_methods;
  identifier_alloc(Crouclause, "Build_rouclause");
  Cnopars = mem_malloc(identifier_methods[0]);
  Cnopars[0] = identifier_methods;
  identifier_alloc(Cnopars, "Build_nopars");
  Cangclause = mem_malloc(identifier_methods[0]);
  Cangclause[0] = identifier_methods;
  identifier_alloc(Cangclause, "Build_angclause");
  Cstrclause = mem_malloc(identifier_methods[0]);
  Cstrclause[0] = identifier_methods;
  identifier_alloc(Cstrclause, "Build_strclause");
  Crulee = mem_malloc(identifier_methods[0]);
  Crulee[0] = identifier_methods;
  identifier_alloc(Crulee, "Build_rulee");
  Saved_start_col = mem_malloc(integer_methods[0]);
  Saved_start_col[0] = integer_methods;
  Saved_start_col = integer_ialloc(Saved_start_col, 1);
  Saved_curr_line_num = mem_malloc(integer_methods[0]);
  Saved_curr_line_num[0] = integer_methods;
  Saved_curr_line_num = integer_ialloc(Saved_curr_line_num, 1);
  CStart_col[1] += 1; Saved_start_col[1] += 1;
  identifier_OpAssign(CStart_col, Saved_start_col, 0);
  CCurr_line_num[1] += 1; Saved_curr_line_num[1] += 1;
  identifier_OpAssign(CCurr_line_num, Saved_curr_line_num, 0);
};

int Build_token(char* tokname, char* inpline, int i, int j){
  cptr tkn, tkstr; char* tok;
  tkn = mem_malloc(idstring_methods[0]);
  tkn[0] = idstring_methods;
  tkn = idstring_alloc(tkn, tokname);
  CTokname[1] += 1; identifier_OpAssign(CTokname, tkn, 0);
  tok = mem_malloc(j-i+1);
  strncpy(tok, inpline+i, j-i); tok[j-i] = 0;
  tkstr = mem_malloc(sstring_methods[0]);
  tkstr[0] = sstring_methods;
  tkstr = sstring_alloc(tkstr, tok);
  CTokstring[1] += 1; identifier_OpAssign(CTokstring, tkstr, 0);
  Ctoken[1] += 1; identifier_Call(Ctoken);
};

int Build_add_instruction(){
  CStart_col[1] += 1; Saved_start_col[1] += 1;
  Saved_start_col = integer_update_hashval(Saved_start_col, Start_col+1);
  identifier_OpAssign(CStart_col, Saved_start_col, 0);
  CCurr_line_num[1] += 1; Saved_curr_line_num[1] += 1;
  Saved_curr_line_num = integer_update_hashval(Saved_curr_line_num, Curr_line_num);
  identifier_OpAssign(CCurr_line_num, Saved_curr_line_num, 0);
  Cadd_instruction[1] += 1;
  identifier_Call(Cadd_instruction);
};


int Build_sqclause(){
  Csqclause[1] += 1;
  identifier_Call(Csqclause);
};

int Build_goal(){
  Cgoal[1] += 1;
  identifier_Call(Cgoal);
};

int Build_add_to_list(){
  Cadd_to_list[1] += 1;
  identifier_Call(Cadd_to_list);
};

int Build_curclause(){
  Ccurclause[1] += 1;
  identifier_Call(Ccurclause);
};

int Build_start_list(){
  Cstart_list[1] += 1;
  identifier_Call(Cstart_list);
};

int Build_idclause(){
  Cidclause[1] += 1;
  identifier_Call(Cidclause);
};

int Build_rouclause(){
  Crouclause[1] += 1;
  identifier_Call(Crouclause);
};

int Build_nopars(){
  Cnopars[1] += 1;
  identifier_Call(Cnopars);
};

int Build_angclause(){
  Cangclause[1] += 1;
  identifier_Call(Cangclause);
};

int Build_strclause(){
  Cstrclause[1] += 1;
  identifier_Call(Cstrclause);
};

int Build_rulee(){
  Crulee[1] += 1;
  identifier_Call(Crulee);
};
