#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
#include "nwcc.h"
#include "nwcclex.h"





#include "config.h"

#include <sys/time.h>

#ifndef __MINGW32__
#include <sys/times.h>
#endif

#include <setjmp.h>

#include <complex>

#include "syserr.h"
#include "pllex.h"

#include "bin_node.h"
#include "gc.h"
#include "var.h"
#include "pred.h"
#include "module.h"
#include "context.h"
#include "unify.h"
#include "func.h"
#include "sysmodule.h"
#include "builtin.h"

jmp_buf	program_jb;

Node*	r_head= Nil;
Node*	r_literal= Nil;
Node*	r_body= Nil;
Node*	r_clause= Nil;
Node*	r_defobj= Nil;
Node*	r_inherit= Nil;
Node*	r_pred= Nil;
Node*	r_proc= Nil;
Node*	r_node= Nil;
Node*	r_term_node= Nil;
Node*	r_list= Nil;
Node*	r_loop= Nil;
Node*	r_alt= Nil;
Node*	r_var= Nil;
Node*	r_obj= Nil;
Node*	r_class= Nil;
Node*	r_term= Nil;
Node*	r_name= Nil;
Node*	r_expression= Nil;
Node*	r_exp_plsmns= Nil;
Node*	r_exp_muldiv= Nil;
Node*	r_proc_letf= Nil;
Node*	r_proc_leti= Nil;
Node*	r_proc_letc= Nil;
Node*	r_proc_rpnf= Nil;
Node*	r_proc_rpni= Nil;
Node*	r_proc_comparef= Nil;
Node*	r_proc_comparei= Nil;
Node*	r_comparing= Nil;
Node*	r_comp_and= Nil;
Node*	r_comp_not= Nil;
Node*	r_comp_gl= Nil;
Node*	r_proc_format= Nil;

extern int ErrorStopFlag;
extern int BreakFlag;
extern int ThrowFlag;

Node*	varlist = Nil;

#ifdef __MINGW32__
void bcopy(void *IN, void *OUT, size_t N)
{
	char* in = (char*)IN;
	char* out = (char*)OUT;

	for ( ; N >0; N--) {
		*(out++) = *(in++);
	}
}

#endif

void RegisterVar(Var* v)
{
	varlist = Cons(v, varlist);
}

Var* SearchVar(const char* s)
{
	Node* p;
	for (p = varlist; p != Nil; p=p->Cdr()) {
		if (((Var*)(p->Car()))->Name() == s) {
			return ((Var*)p->Car());
		}
	}
	return NULL;
}

Var* GetVar(const char* s)
{
	if (strncmp(s, "_", 1) != 0) {
		Var* v = SearchVar(s);
		if (v != NULL) {
			return v;
		}
	}
	Var* r = new Var(s);
	RegisterVar(r);
	return r;
}

void ClearVar()
{
	varlist = Nil;
}


int CheckSJIS2nd()
{
	extern FILE* RdFp;
	extern int CharSJISLen(unsigned char c);
	int c;
	long tp, i;
	int flg = 0;

	tp = FilePointSave();
	for (i = tp-2; i >= 0; i--) {
		fseek(RdFp, i, 0);
		c = fgetc(RdFp);
		if (c < ' ') {
			break;
		}
	}
	i++;

	flg = 0;
	fseek(RdFp, i, 0);
	for ( ; ; i++) {
		c = fgetc(RdFp);
		if (i > tp-2) {
			break;
		}

		if (flg) {
			flg = 0;
		} else if (CharSJISLen(c) > 1) {
			flg = 1;
		}
	}

	FilePointResume(tp);

	return flg;
}

int NOTSPACE()
{
	extern int Char;
	extern int pllexCkSpace(int c);
	extern std::string code;
	extern int CharSJISLen(unsigned char c);

	C();

	switch (Char) {
	case '\"':
	case '\'':
	case '!':
	case '#':
	case '&':
	case '\%':
	case '(':
	case ')':
	case '*':
	case '+':
	case '-':
	case '/':
	case ':':
	case ';':
	case '<':
	case '=':
	case '>':
	case '?':
	case '[':
	case ']':
	case '{':
	case '}':
	case '|':
		if (code == "SJIS") {
			if (CheckSJIS2nd()) {
				return 0;
			}
		}
		UnGetChar(Char);
		return -1;
	}		


	if (Char <= ' ') {
		UnGetChar(Char);
		return -1;
	}

	if (pllexCkSpace(Char)) {
		UnGetChar(Char);
		return -1;
	}


	return 0;
}

int HEXNUM()
{
	extern int Char;
	extern int C();

	SkipSpace();

	tokenPt = 0;

	C();
	if (Char != '0') {
		UnGetChar(Char);
		return -1;
	}
	SetToken(Char);

	C();
	if (Char != 'x') {
		UnGetChar(Char);
		UnGetChar('0');
		return -1;
	}
	SetToken(Char);

	for (;;) {
		C();
		if (isdigit(Char) 
		    || ((Char >= 'a') && (Char <= 'f'))
		    || ((Char >= 'A') && (Char <= 'F'))){
			SetToken(Char);
		} else {
			UnGetChar(Char);
			SetToken('\0');
			break;
		}
	}
	unsigned long long n = strtoll(TOKEN, (char **)NULL, 16);
	snprintf(TOKEN, TOKEN_LEN, "%lld\0", n);
	return 0;	
}


const char* InputSuffix="pl";
const char* OutputSuffix="c";
int NwccMain()
{
int program();
ErrorFlg=program();
if(ErrorFlg) ErrorStop(MESG);
return 0;
}

int program()
{


				   ErrorStopFlag = 0;
				   ErrGoal = Nil;
				   BreakFlag = 0;
				   ThrowFlag = 0;

				   if (setjmp(program_jb) != 0) {
					ErrorStopFlag = 0;

					ErrGoal = Nil;

					return 0;
				   }

				
ErrorFlg = 0;
MESG=NULL;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
if(ErrorFlg){
int goal();
ErrorFlg = goal();
MESG="goal is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
}
if(ErrorFlg){
int declare();
ErrorFlg = declare();
MESG="declare is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
}
return ErrorFlg;
}

int goal()
{
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("?");
MESG="\"?\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   Node* l_goalnodes = Nil;
				   int orflag = 0;
				   Node* l_goal = Nil; 
				   int r ;
				   ClearVar(); 
				
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_goal = MkList(r_node); 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("|");
MESG="\"|\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   orflag++;
				   if (orflag == 1) {
					l_goal = MkPred(MkList(mka("or"), 
								l_goal));

				   }
				   l_goalnodes = Nil;
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   if (orflag == 0) {
					l_goal = Append(l_goal, MkList(r_node));
				   } else {
					if (l_goalnodes == Nil) {
						l_goalnodes = MkList(r_node);
						l_goal = Append(l_goal, 
								MkList(l_goalnodes));
					} else {
						l_goalnodes 
							= Append(l_goalnodes,
								MkList(r_node));
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);

				   extern int TraceFlag;
				   extern int incflag;
				   if (TraceFlag) {
					   PrintNode("? ", l_goal);
				   }
				   incflag = 0;

				   Context* cx = new Context(Module, 
							new Atom("WORLD"));

				   l_goal = l_goal->Val();

			 	   struct timeval tv;
				   gettimeofday (&tv, NULL);
				   progtime.start_time = tv.tv_sec*1000000
								+tv.tv_usec;
#ifndef __MINGW32__
				   struct tms tmsbuf;
				   times(&tmsbuf);
				   progtime.start_utime = tmsbuf.tms_utime;
				   progtime.start_stime = tmsbuf.tms_stime;
				   progtime.start_cutime = tmsbuf.tms_cutime;
				   progtime.start_cstime = tmsbuf.tms_cstime;
#endif

				   jmp_buf	save_jb;
				   bcopy(program_jb, save_jb, sizeof save_jb);

				   cxpush(cx, l_goal);

				   if ((r = setjmp(program_jb)) == 0) {
					   r = Unify(cx, l_goal);

				   } else {
					r = r - 2;
				   }

				   cxpop(cx);

				   bcopy(save_jb, program_jb, sizeof save_jb);

				   extern int resultflg;
				   if (!incflag && resultflg) {
					printf("result -- \n");
					PPmoduleBody(1, l_goal);
				   	if (r == 1) {
						printf("-- true\n");
				   	} else if (r == 0) {
						printf("-- false\n");
				   	} else { 						printf("-- unknown\n");
					}
				   }
				   ClearVar(); 

				   BreakFlag = 0;
				   ThrowFlag = 0;


				   delete cx;

				   ErrGoal = Nil;

				   GC();
				
}
return ErrorFlg;
}

int literal()
{
 r_literal = Nil; 
ErrorFlg = 0;
MESG=NULL;
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_literal = r_pred; 
}
return ErrorFlg;
}

int declare()
{

				   r_defobj = Nil;
				   r_clause = Nil;
				   r_list = Nil;
				
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int defobj();
ErrorFlg = defobj();
MESG="defobj is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Assert(Module, r_defobj); 
}
if(ErrorFlg){
int clause();
ErrorFlg = clause();
MESG="clause is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Assert(Module, r_clause); 
}
}
if(ErrorFlg){
int list();
ErrorFlg = list();
MESG="list is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Module->SetCar(Append(Module->Car(), 
							r_list->Car())); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int clause()
{

				   r_clause = Nil; Node* l_clause = Nil; 
				   ClearVar(); 
				
ErrorFlg = 0;
MESG=NULL;
int head();
ErrorFlg = head();
MESG="head is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int body();
ErrorFlg = body();
MESG="body is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   if (r_body == Nil) {
					l_clause = MkList(r_head);
				   } else {
					if (r_body->kind() != LIST) {
						r_body = MkList(r_body);
					}
					l_clause = Cons(r_head, r_body); 
				   }
				   ClearVar(); 
				   r_clause = l_clause;
				
}
return ErrorFlg;
}

int head()
{
 r_head = Nil; 
ErrorFlg = 0;
MESG=NULL;
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_head = r_pred; 
}
return ErrorFlg;
}

int body()
{

				   Node* r_bodynodes = Nil;
				   int orflag = 0;
				   r_body = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("|");
MESG="\"|\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   orflag++;
				   if (orflag == 1) {
					r_body = MkPred(MkList(mka("or"),
								r_body));
				   }
				   r_bodynodes = Nil;
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 
				   if (orflag == 0) {
					r_body = Append(r_body, MkList(r_node));
				   } else {
					if (r_bodynodes == Nil) {
						r_bodynodes = MkList(r_node);
						r_body = Append(r_body, 
								MkList(r_bodynodes));
					} else {
						r_bodynodes 
							= Append(r_bodynodes,
								MkList(r_node));
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
}
return ErrorFlg;
}

int defobj()
{

				   r_defobj = Nil;
				   Node* l_defobj = Nil;
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("::");
MESG="\"::\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
ErrorFlg = COMP("<");
MESG="\"<\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
int obj_name();
ErrorFlg = obj_name();
MESG="obj_name is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_defobj = MkList(MkPred(r_class)); 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int clause();
ErrorFlg = clause();
MESG="clause is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_defobj = Append(l_defobj, MkList(r_clause)); 
}
if(ErrorFlg){
int inherit();
ErrorFlg = inherit();
MESG="inherit is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_defobj = Append(l_defobj, MkList(r_inherit)); 
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(">");
MESG="\">\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_defobj = MkList(MkPred(l_defobj)); 
}
return ErrorFlg;
}

int inherit()
{
 r_inherit = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("inherit");
MESG="\"inherit\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int term();
ErrorFlg = term();
MESG="term is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_inherit = MkList(mka("inherit"), r_term); 
}
return ErrorFlg;
}

int pred()
{
 
				   Node* l_pred = Nil;
				   int   dotflg = 0; 
				   Node* lastnode = Nil;
				   r_pred = Nil;
				
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("<");
MESG="\"<\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = Nil; 
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("!");
MESG="\"!\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = MkList(mka("!")); 
}
if(ErrorFlg){
int proc_rpnf();
ErrorFlg = proc_rpnf();
MESG="proc_rpnf is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_rpnf; 
}
}
if(ErrorFlg){
int proc_rpni();
ErrorFlg = proc_rpni();
MESG="proc_rpni is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_rpni; 
}
}
if(ErrorFlg){
int proc_comparef();
ErrorFlg = proc_comparef();
MESG="proc_comparef is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_comparef; 
}
}
if(ErrorFlg){
int proc_comparei();
ErrorFlg = proc_comparei();
MESG="proc_comparei is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_comparei; 
}
}
if(ErrorFlg){
int proc_letf();
ErrorFlg = proc_letf();
MESG="proc_letf is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_letf; 
}
}
if(ErrorFlg){
int proc_leti();
ErrorFlg = proc_leti();
MESG="proc_leti is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_leti; 
}
}
if(ErrorFlg){
int proc_leti2();
ErrorFlg = proc_leti2();
MESG="proc_leti2 is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_leti; 
}
}
if(ErrorFlg){
int proc_letc();
ErrorFlg = proc_letc();
MESG="proc_letc is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_letc; 
}
}
if(ErrorFlg){
int proc_format();
ErrorFlg = proc_format();
MESG="proc_format is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_pred = r_proc_format; 
}
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   l_pred = lastnode = MkList(r_node); 
				
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   l_pred = Append(l_pred, 
						lastnode = MkList(r_node)); 
				
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(":");
MESG="\":\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);

				   ((List*)lastnode)->SetCdr(r_node); 
				
ErrorFlg = COMP(";");
MESG="\";\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(">");
MESG="\">\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
 r_pred = MkPred(l_pred); 
}
return ErrorFlg;
}

int list()
{

				   Node* l_listnodes = Nil;
				   int orflag = 0;
				   r_list = Nil;
				   Node* l_list = Nil;
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("(");
MESG="\"(\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("|");
MESG="\"|\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   orflag++;
				   if (orflag == 1) {
					l_list = MkPred(MkList(mka("or"),
								l_list));
				   }
				   l_listnodes = Nil;
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   if (orflag == 0) {
					l_list = Append(l_list, MkList(r_node));
				   } else {
					if (l_listnodes == Nil) {
						l_listnodes = MkList(r_node);
						l_list = Append(l_list, 
								MkList(l_listnodes));
					} else {
						l_listnodes 
							= Append(l_listnodes,
								MkList(r_node));
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP(":");
MESG="\":\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   if (orflag == 0) {
					l_list = Append(l_list, r_node);
				   } else {
					if (l_listnodes == Nil) {
						l_listnodes = MkList(r_node);
						l_list = Append(l_list, 
								l_listnodes);
					} else {
						l_listnodes 
							= Append(l_listnodes,
								r_node);
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(")");
MESG="\")\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_list = l_list; 
}
return ErrorFlg;
}

int obj()
{
 
				   r_obj = Nil;
				   Node* l_obj = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("::");
MESG="\"::\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int obj_name();
ErrorFlg = obj_name();
MESG="obj_name is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_obj = MkList(mka("obj"), r_class); 
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_obj = MkPred(Append(l_obj, MkList(r_pred))); 
}
return ErrorFlg;
}

int node()
{
 r_node = Nil; 
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int obj();
ErrorFlg = obj();
MESG="obj is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_obj; 
}
if(ErrorFlg){
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_pred; 
}
}
if(ErrorFlg){
int list();
ErrorFlg = list();
MESG="list is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_list; 
}
}
if(ErrorFlg){
int loop();
ErrorFlg = loop();
MESG="loop is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_loop; 
}
}
if(ErrorFlg){
int alt();
ErrorFlg = alt();
MESG="alt is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_alt; 
}
}
if(ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_var; 
}
}
if(ErrorFlg){
ErrorFlg = COMP("\\");
MESG="\"\\\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka("\\"); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("*");
MESG="\"*\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka("*"); 
}
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int HEXNUM();
ErrorFlg = HEXNUM();
MESG="HEXNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka(TOKEN); 
}
if(ErrorFlg){
int FNUM();
ErrorFlg = FNUM();
MESG="FNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka(TOKEN); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("i");
MESG="\"i\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka("i"); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int HEXNUM();
ErrorFlg = HEXNUM();
MESG="HEXNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 std::string s = "-";
				   s = s + TOKEN;
				   r_node = mka((char*)s.c_str()); 
}
if(ErrorFlg){
int FNUM();
ErrorFlg = FNUM();
MESG="FNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 std::string s = "-";
				   s = s + TOKEN;
				   r_node = mka((char*)s.c_str()); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("i");
MESG="\"i\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka("-i"); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if(ErrorFlg){
ErrorFlg = COMP("i");
MESG="\"i\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka("i"); 
}
}
if(ErrorFlg){
int HEXNUM();
ErrorFlg = HEXNUM();
MESG="HEXNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka(TOKEN); 
}
}
if(ErrorFlg){
int FNUM();
ErrorFlg = FNUM();
MESG="FNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = mka(TOKEN); 
}
}
if(ErrorFlg){
int term();
ErrorFlg = term();
MESG="term is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_node = r_term; 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int loop()
{

				   Node* l_loopnodes = Nil;
				   int orflag = 0;
				   r_loop = Nil;
				   Node* l_loop = Nil;
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("{");
MESG="\"{\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_loop = MkList(r_var); 
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("|");
MESG="\"|\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   orflag++;
				   if (orflag == 1) {
					l_loop = MkPred(MkList(mka("or"),
								l_loop));
				   }
				   l_loopnodes = Nil;
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   if (orflag == 0) {
					l_loop = Append(l_loop, MkList(r_node));
				   } else {
					if (l_loopnodes == Nil) {
						l_loopnodes = MkList(r_node);
						l_loop = Append(l_loop, 
								MkList(l_loopnodes));
					} else {
						l_loopnodes 
							= Append(l_loopnodes,
								MkList(r_node));
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP("}");
MESG="\"}\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_loop = MkPred(Cons(mka("loop"), 
							l_loop)); 
}
return ErrorFlg;
}

int alt()
{

				   Node* l_altnodes = Nil;
				   int orflag = 0;
				   r_alt = Nil;
				   Node* l_alt = Nil;
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("[");
MESG="\"[\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("|");
MESG="\"|\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   orflag++;
				   if (orflag == 1) {
					l_alt = MkPred(MkList(mka("or"),
								l_alt));
				   }
				   l_altnodes = Nil;
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){

				   if (orflag == 0) {
					l_alt = Append(l_alt, MkList(r_node));
				   } else {
					if (l_altnodes == Nil) {
						l_altnodes = MkList(r_node);
						l_alt = Append(l_alt, 
								MkList(l_altnodes));
					} else {
						l_altnodes 
							= Append(l_altnodes,
								MkList(r_node));
					}
				   }
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP("]");
MESG="\"]\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   r_alt = MkPred(Cons(mka("alt"), MkList(l_alt))); 
				
}
return ErrorFlg;
}

int var()
{
 r_var = Nil; 
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("_");
MESG="\"_\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
 r_var = GetVar("_"); 
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("#");
MESG="\"#\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int Word();
ErrorFlg = Word();
MESG="Word is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);

					std::string buf = "#";
					buf = buf + TOKEN;
					r_var = GetVar((char*)buf.c_str());
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int obj_name()
{
 r_class = Nil; 
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int Word();
ErrorFlg = Word();
MESG="Word is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_class = mka(TOKEN); 
}
if(ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_class = r_var; 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int term()
{
 r_term = Nil; 
ErrorFlg = 0;
MESG=NULL;
int Word();
ErrorFlg = Word();
MESG="Word is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_term = mka(TOKEN); 
}
return ErrorFlg;
}

int name()
{
 r_name = Nil; 
ErrorFlg = 0;
MESG=NULL;
int Word();
ErrorFlg = Word();
MESG="Word is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_name = mka(TOKEN); 
}
return ErrorFlg;
}

int expression()
{

				    r_expression = Nil;
				    Node* l_expression = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
int exp_plsmns();
ErrorFlg = exp_plsmns();
MESG="exp_plsmns is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_expression = r_exp_plsmns;	
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_expression = Append(l_expression,
							MkList(mka("+"))); 
}
if(ErrorFlg){
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_expression = Append(l_expression, 
							MkList(mka("-"))); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
int exp_plsmns();
ErrorFlg = exp_plsmns();
MESG="exp_plsmns is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_expression = Append(l_expression, 
							r_exp_plsmns); 
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_expression = l_expression; 
}
return ErrorFlg;
}

int exp_plsmns()
{

				   r_exp_plsmns = Nil;
				   Node* l_exp_plsmns = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
int exp_muldiv();
ErrorFlg = exp_muldiv();
MESG="exp_muldiv is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_exp_plsmns = r_exp_muldiv; 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("*");
MESG="\"*\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_exp_plsmns = Append(l_exp_plsmns, MkList(mka("*"))); 
}
if(ErrorFlg){
ErrorFlg = COMP("/");
MESG="\"/\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_exp_plsmns = Append(l_exp_plsmns, MkList(mka("/"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("%");
MESG="\"%\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_exp_plsmns = Append(l_exp_plsmns, MkList(mka("%"))); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
int exp_muldiv();
ErrorFlg = exp_muldiv();
MESG="exp_muldiv is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_exp_plsmns = Append(l_exp_plsmns, r_exp_muldiv); 
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_exp_plsmns = l_exp_plsmns; 
}
return ErrorFlg;
}

int term_node()
{

				   std::string s; 
				   r_term_node = Nil;
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 s = "+"; 
}
if(ErrorFlg){
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 s = "-"; 
}
}
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int obj();
ErrorFlg = obj();
MESG="obj is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 if (s == "-") {
					r_term_node = MkList(mka("-1"), 
							     mka("*"),
								r_obj);
							     
				   } else {
					r_term_node = MkList(r_obj);
				   }
				
}
if(ErrorFlg){
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 if (s == "-") {
					r_term_node = MkList(mka("-1"), 
							     mka("*"),
								r_pred);
							     
				   } else {
					r_term_node = MkList(r_pred);
				   }
				
}
}
if(ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 if (s == "-") {
					r_term_node = MkList(mka("-1"), 
							     mka("*"),
								r_var);
							     
				   } else {
					r_term_node = MkList(r_var);
				   }
				
}
}
if(ErrorFlg){
ErrorFlg = COMP("i");
MESG="\"i\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 
				   s += "i";
				   r_term_node = MkList(mka((char*)s.c_str()));
				
}
}
if(ErrorFlg){
int HEXNUM();
ErrorFlg = HEXNUM();
MESG="HEXNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 
				   s += TOKEN;
				   r_term_node = MkList(mka((char*)s.c_str()));
				
}
}
if(ErrorFlg){
int FNUM();
ErrorFlg = FNUM();
MESG="FNUM is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 
				   s += TOKEN;
				   r_term_node = MkList(mka((char*)s.c_str()));
				
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
}
return ErrorFlg;
}

int exp_muldiv()
{
 r_exp_muldiv = Nil; 
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("(");
MESG="\"(\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(")");
MESG="\")\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_exp_muldiv = MkList(r_expression); 
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
int term_node();
ErrorFlg = term_node();
MESG="term_node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_exp_muldiv = r_term_node; 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int comparing()
{

				    r_comparing = Nil; 
				    Node* l_comp_or = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
int comp_and();
ErrorFlg = comp_and();
MESG="comp_and is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_or = r_comp_and; 
ErrorFlg = COMP("or");
MESG="\"or\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int comp_and();
ErrorFlg = comp_and();
MESG="comp_and is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_comp_or = MkList(l_comp_or, mka("or"),
								r_comp_and); 
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_comparing = l_comp_or; 
}
return ErrorFlg;
}

int comp_and()
{

				   r_comp_and = Nil;
				   Node* l_comp_and = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
int comp_not();
ErrorFlg = comp_not();
MESG="comp_not is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_and = r_comp_not; 
ErrorFlg = COMP("and");
MESG="\"and\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int comp_not();
ErrorFlg = comp_not();
MESG="comp_not is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_comp_and = MkList(l_comp_and, mka("and"),
								r_comp_not); 
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_comp_and = l_comp_and; 
}
return ErrorFlg;
}

int comp_not()
{

				   r_comp_not = Nil;
				   Node* l_comp_not = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("not");
MESG="\"not\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_not = (MkList(mka("not"))); 
}
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
int comp_gl();
ErrorFlg = comp_gl();
MESG="comp_gl is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 if (l_comp_not == Nil) {
					l_comp_not = r_comp_gl;
				   } else {
					l_comp_not = Append(l_comp_not, 
							MkList(r_comp_gl));
				   }
				
 r_comp_not = l_comp_not; 
}
return ErrorFlg;
}

int comp_gl()
{

				   r_comp_gl = Nil;
				   Node* l_comp_gl = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("(");
MESG="\"(\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int comparing();
ErrorFlg = comparing();
MESG="comparing is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP(")");
MESG="\")\" is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_comp_gl = r_comparing; 
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = r_expression; 
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("==");
MESG="\"==\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("=="))); 
}
if(ErrorFlg){
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("="))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("<>");
MESG="\"<>\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("<>"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("!=");
MESG="\"!=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("!="))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("="))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP(">=");
MESG="\">=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka(">="))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP(">");
MESG="\">\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka(">"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("<=");
MESG="\"<=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("<="))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("<");
MESG="\"<\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_comp_gl = Append(l_comp_gl, MkList(mka("<"))); 
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   l_comp_gl = Append(l_comp_gl, r_expression);
				   r_comp_gl = l_comp_gl; 
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
return ErrorFlg;
}

int proc_letf()
{

				   r_proc_letf = Nil;
				   Node* l_proc_letf = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("letf");
MESG="\"letf\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 l_proc_letf = MkList(mka("letf"),
							r_var,
							mka("=")); 
				
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   				   r_proc_letf = l_proc_letf;
				   r_proc_letf = Append(r_proc_letf, r_expression); 

				
}
return ErrorFlg;
}

int proc_leti()
{

				   r_proc_leti = Nil;
				   Node* l_proc_leti = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("let");
MESG="\"let\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 l_proc_leti = MkList(mka("let"),
							r_var,
							mka("=")); 
				
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   				   r_proc_leti = l_proc_leti;
				   r_proc_leti = Append(r_proc_leti, 
							r_expression); 

				
}
return ErrorFlg;
}

int proc_leti2()
{

				   r_proc_leti = Nil;
				   Node* l_proc_leti = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_leti = MkList(mka("let"),
							r_var,
							mka("=")); 
				
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   				   r_proc_leti = l_proc_leti;
				   r_proc_leti = Append(r_proc_leti, r_expression); 
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
 r_proc_leti = MkList(r_var); 
ErrorFlg = 0;MESG=NULL;

if(!ErrorFlg){
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 r_proc_leti = Append(r_proc_leti, 
							MkList(r_node)); 
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(ErrorFlg) ErrorStop(MESG);
}
return ErrorFlg;
}

int proc_letc()
{

				   r_proc_letc = Nil;
				   Node* l_proc_letc = Nil; 
				
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("letc");
MESG="\"letc\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
ErrorFlg = COMP("=");
MESG="\"=\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 l_proc_letc = MkList(mka("letc"),
							r_var,
							mka("=")); 
				
int expression();
ErrorFlg = expression();
MESG="expression is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 
				   				   r_proc_letc = l_proc_letc;
				   r_proc_letc = Append(r_proc_letc, r_expression); 

				
}
return ErrorFlg;
}

int proc_comparef()
{
 r_proc_comparef = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("comparef");
MESG="\"comparef\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int comparing();
ErrorFlg = comparing();
MESG="comparing is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_proc_comparef = MkList(mka("comparef"));
				   r_proc_comparef = Append(r_proc_comparef,
							r_comparing); 
				
}
return ErrorFlg;
}

int proc_comparei()
{
 r_proc_comparei = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("compare");
MESG="\"compare\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int comparing();
ErrorFlg = comparing();
MESG="comparing is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_proc_comparei = MkList(mka("compare"));
				   r_proc_comparei = Append(r_proc_comparei, 
							r_comparing); 
				
}
return ErrorFlg;
}

int proc_rpnf()
{
 r_proc_rpnf = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("rpnf");
MESG="\"rpnf\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Node* l_proc_rpnf = MkList(mka("rpnf")); 
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_proc_rpnf = Append(l_proc_rpnf, MkList(r_var)); 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(mka("+"))); 
}
if(ErrorFlg){
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(mka("-"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("*");
MESG="\"*\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(mka("*"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("/");
MESG="\"/\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(mka("/"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("%");
MESG="\"%\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(mka("%"))); 
}
}
if(ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(r_var)); 
}
}
if(ErrorFlg){
int obj();
ErrorFlg = obj();
MESG="obj is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(r_obj)); 
}
}
if(ErrorFlg){
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(r_pred)); 
}
}
if(ErrorFlg){
int term();
ErrorFlg = term();
MESG="term is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpnf = Append(l_proc_rpnf, MkList(r_term)); 
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_proc_rpnf = l_proc_rpnf; 
}
return ErrorFlg;
}

int proc_rpni()
{
 r_proc_rpni = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("rpn");
MESG="\"rpn\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Node* l_proc_rpni = MkList(mka("rpn")); 
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_proc_rpni = Append(l_proc_rpni, MkList(r_var)); 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(mka("+"))); 
}
if(ErrorFlg){
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(mka("-"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("*");
MESG="\"*\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(mka("*"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("/");
MESG="\"/\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(mka("/"))); 
}
}
if(ErrorFlg){
ErrorFlg = COMP("%");
MESG="\"%\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(mka("%"))); 
}
}
if(ErrorFlg){
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(r_var)); 
}
}
if(ErrorFlg){
int obj();
ErrorFlg = obj();
MESG="obj is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(r_obj)); 
}
}
if(ErrorFlg){
int pred();
ErrorFlg = pred();
MESG="pred is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(r_pred)); 
}
}
if(ErrorFlg){
int term();
ErrorFlg = term();
MESG="term is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 l_proc_rpni = Append(l_proc_rpni, MkList(r_term)); 
}
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);
 r_proc_rpni = l_proc_rpni; 
}
return ErrorFlg;
}

int Word()
{

				   std::string s; 
				
ErrorFlg = 0;
MESG=NULL;
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("-");
MESG="\"-\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int NUM();
ErrorFlg = NUM();
MESG="NUM is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 s = TOKEN; 
				   snprintf(TOKEN, TOKEN_LEN, "-%s", s.c_str());
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
if(ErrorFlg){
{
int nloop = 0;
do {
long chktell1,chktell2;
chktell1=FilePointSave();
ErrorFlg = COMP("+");
MESG="\"+\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
int NUM();
ErrorFlg = NUM();
MESG="NUM is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 s = TOKEN;
				   snprintf(TOKEN, TOKEN_LEN, "+%s", s.c_str());
				
}
if (!ErrorFlg) nloop++;
}while(0);
}
if(!ErrorFlg){
}
}
if(ErrorFlg){
int STRINGS();
ErrorFlg = STRINGS();
MESG="STRINGS is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
}
if(ErrorFlg){
int WordBlock();
ErrorFlg = WordBlock();
MESG="WordBlock is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
}
}
return ErrorFlg;
}

int WordBlock()
{
 { extern int Char; 
				     long tellsave;
				     tokenPt = 0;
				     tellsave=FilePointSave();
				     SkipSpace();
				
ErrorFlg = 0;
MESG=NULL;
int NOTSPACE();
ErrorFlg = NOTSPACE();
MESG="NOTSPACE is missing ";
if (ErrorFlg) {
{
  FilePointResume(tellsave); 
}
}
if(!ErrorFlg){
   SetToken(Char); 
do {
long chktell1,chktell2;
chktell1=FilePointSave();
int NOTSPACE();
ErrorFlg = NOTSPACE();
MESG="NOTSPACE is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
   SetToken(Char); 
}
chktell2=FilePointSave();
if ((chktell1 == chktell2) && !ErrorFlg)
  ErrorStop("endless loop occured");
}while(!ErrorFlg);
ErrorFlg = 0;
MESG=NULL;
if(!ErrorFlg){
}
ErrorFlg = 0;
MESG=NULL;
if(ErrorFlg) ErrorStop(MESG);

				     SetToken('\0');
				   }
				
}
return ErrorFlg;
}

int proc_format()
{
 r_proc_format = Nil; 
ErrorFlg = 0;
MESG=NULL;
ErrorFlg = COMP("%");
MESG="\"%\" is missing ";
if (ErrorFlg) {
}
if(!ErrorFlg){
 Node* l_proc_format = MkList(mka("%")); 
int var();
ErrorFlg = var();
MESG="var is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_proc_format = Append(l_proc_format, 
							MkList(r_var)); 
int Word();
ErrorFlg = Word();
MESG="Word is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 l_proc_format = Append(l_proc_format, 
							MkList(mka(TOKEN))); 
int node();
ErrorFlg = node();
MESG="node is missing ";
if (ErrorFlg) {
}
if(ErrorFlg) ErrorStop(MESG);
 r_proc_format = Append(l_proc_format, 
							MkList(r_node)); 
}
return ErrorFlg;
}

