Скачиваний:
11
Добавлен:
01.05.2014
Размер:
19.2 Кб
Скачать
#define NDEBUG

#include <stdio.h>
#include "stack.h"
#include "list.h"

#include "symb.h"
#include "voc.h"
#include "types.cpp"

#include "dmp0.cpp"
#include "dmp1.cpp"
#include "dmp2.cpp"
#include "dmp3.cpp"
#include "dmp4.cpp"
#include "dmp5.cpp"
#include "dmp6.cpp"
#include "dmp7.cpp"
#include "dmp8.cpp"


List<ELEM_T_ID> t_id;        // в Ў«Ёж  Ё¤Ґ­вЁдЁЄ в®а®ў (3)
List<int> t_i_const;         // в Ў«Ёж  楫ле Є®­бв ­в (4)
List<float> t_f_const;       // в Ў«Ёж  ўҐйҐб⢥­­ле Є®­бв ­в (5)
List<ELEM_T_VAR> t_var;      // в Ў«Ёж  ЇҐаҐ¬Ґ­­ле (6)
List<unsigned int> t_mark;   // в Ў«Ёж  ¬Ґв®Є (7)

Stack<SYMB> S;               // Њ Ј §Ё­



int cj_fun0(const SYMB& s)
{
	char i = s.get_id(1);
// Ґб«Ё Є« бб id - ЇҐаҐ¬Ґ­­ п в® ЇҐаҐе®¤ ­  Їа®жҐбб®а 4, Ё­ зҐ ЇҐаҐ­®б
	return ((t_id[i].cls == 1 || t_id[i].cls == 2) ? 29 : 0); // 20 + 9(ᬥ饭ЁҐ x ў в Ў«ЁжҐ AF)
}

int cj_fun1(const SYMB& s)
{
	SYMB sd1 = S.pop();
	SYMB sd2 = S.pop();
	S.push(sd2);
	S.push(sd1);
	if (sd2 == _for_)
		return 33;
	else
		return 34;
}

int (*carry_jmp[2])(const SYMB&) = {cj_fun0, cj_fun1};


int qntf_rbo = 0;
int fun_carry0()
{
	qntf_rbo++;
	return 1;
}

int fun_carry1()
{
	if (qntf_rbo) {
		qntf_rbo--;
		return 1;
	}
	else
		return 0;
}

int (*fun_carry[2])() = {fun_carry0, fun_carry1};


#include "sem_oper.cpp"


SYMB bs = SYMB(3, 0, 0);
SYMB eps = SYMB(4, 0, 0);


int init_tables()
{
	FILE* f = fopen("tables.bin", "rb");
	if (f == NULL) {
		printf("Warning! FILE: tables.bin NOT FOUND!!!\n");
		return 1;
	}
	int sz;
	fscanf(f, "%c%c", &sz, ((char*)&sz)+1);
	int i, ti, j;

	ELEM_T_ID dflt = {0, 0, {0, 0}};
	for (i = 0; i < sz; i++)
		t_id.add(dflt);
	fscanf(f, "%c%c", &sz, ((char*)&sz)+1);

	for (i = 0; i < sz; i++) {
		fscanf(f, "%c%c", &ti, ((char*)&ti)+1);
		t_i_const.add(ti);
	}
	fscanf(f, "%c%c", &sz, ((char*)&sz)+1);
	float tf;
	for (i = 0; i < sz; i++) {
		for (j = 0; j < 4; j++)
			fscanf(f, "%c", ((char*)&tf)+j);
		t_f_const.add(tf);
	}
	fclose(f);
	return 0;
}

// —Ёв Ґ¬ Ё§ д ©«  ®зҐаҐ¤­го «ҐЄбҐ¬г
void read_tok(FILE* inp, int& t1, int& t2)
{
	if (fscanf(inp, "%c%c%c%c", (char*)&t1, (char*)&t1+1, (char*)&t2, (char*)&t2+1) == EOF) {
		t1 = -1;
		t2 = -1;
	}
}



void init_gram_attr(DMP_PROC& D)
{
	int i, j, k;
	for (i = 0; i < D.n_rul; i++)
		for (j = 0; j < D.max_rul; j++)
			for (k = 0; k < 4; k++)
				D.gram[i][j].set_attr(k, D.gram_attr[i][j][k].val[0], D.gram_attr[i][j][k].val[1]);
}



void determinate_xy_AF(DMP_PROC& D, const SYMB& i_s, const SYMB& u_s, int& x, int& y)
{
	x = 0;
	y = 0;
	int i = 0;
	char find = 0;
	char fnd = 0;
	char n_cur_sub = 0; // Ќ®¬Ґа ўбваҐз. бЁ¬ў®«  Ї®¤Ја ¬¬ вЁЄЁ
	while (i < D.AF_x_sz && (!find)) {
		if (D.AF_x[i].get_type() == 5) { // ‘Ё¬ў®« Ї®¤Ја ¬¬ вЁЄЁ
			fnd = 0;
			int j = 0;
			while (j < (*D.sub_gram).n_symb_subgram[n_cur_sub] && !fnd) {
				fnd = (i_s == (*D.sub_gram).symb_subgram[n_cur_sub][j++]);
			}
			find = fnd;
			i++;
			n_cur_sub++;
		}
		else
			find = (i_s == D.AF_x[i++]);
	}
	x = (find) ? --i : -1;
	i = 0;
	find = 0;
	while (i < D.AF_y_sz && (!find)) {
		find = (u_s == D.AF_y[i++]);
	}
	y = (find) ? --i : -1;
}


int reduction(DMP_PROC& D, FILE* out, FILE* outb) // ᢥавЄ 
{

// Ќ ©¤Ґ¬ Ї® Є Є®¬г Їа ўЁ«г ¤Ґ« вм ᢥавЄг (­ е®¤Ё¬ ®б­®ўг)
	int i = 0;
	int j, k;
	int find = 0;
	int n;
	Stack<SYMB> TS;
	SYMB down_base; // бЁ¬ў®« Ї®¤ ®б­®ў®©

	while ((!find) && i < D.n_rul) {
		SYMB t = S.pop();
		S.push(t);
		if (t == D.gram[i][D.gram_idx[i][0]]) {
			j = D.gram_idx[i][0] - 1;
			if (j == 0) {
				find = 1;
				TS.push(S.pop());
				down_base = S.pop();
				S.push(down_base);
				S.push(TS.pop());
			}
			else {
				TS.push(S.pop());
				int f = 1;
				while (f && j > 0) {
					t = S.pop();
					TS.push(t);
					f = (t == D.gram[i][j--]);
				}
				if (f) {
					find = 1;
					down_base = S.pop();
					S.push(down_base);
				}
				while (!TS.is_empty())
					S.push(TS.pop());
			}
		}
		i++;
	}
	n = --i; // n - ­®¬Ґа Їа ўЁ«  ; down_base - cЁ¬ў®« Ї®¤ ®б­®ў®©
// ®ЇаҐ¤Ґ«пҐ¬ x Ё y FG
	int y;
	i = 0;
	find = 0;
	while (i < D.AF_y_sz && (!find)) {
		find = (down_base == D.AF_y[i++]);
	}
	if (!find)
		return 2;
	y = --i;
	if (!D.AG[y][n]) // ­Ґ в®в бЁ¬ў®« Ї®¤ ®б­®ў®©
		return 2;    // ®иЁЎЄ 
// д®а¬Ёа®ў ­ЁҐ ўаҐ¬Ґ­­®Ј® ¬ ббЁў 
	SYMB temp[15];
	temp[0] = D.gram[n][0];
// ¤®Ў®ў«пҐ¬ ®ЇҐа. бЁ¬ў®«л
	i = D.gram_idx[n][0] + 1;
	for (j = 0; j < D.gram_idx[n][1]; j++) {
		temp[i] = D.gram[n][i];
		i++;
	}

// б­Ё¬ Ґ¬ Ё§ б⥪  ®б­®ўг Ё § ЇЁеЁў Ґ¬ ў® ўаҐ¬Ґ­­л© ¬ ббЁў
	for (i = D.gram_idx[n][0]; i > 0; i--)
		temp[i] = S.pop();

// ®Ўа Ў®вЄ  ®ЇҐа жЁ®­­ле бЁ¬ў®«®ў Ё ўлзЁб«Ґ­ЁҐ  ваЁЎгв®ў
	i = D.gram_idx[n][0] + 1;
	j = 0;
	int err = 0;
	while (j < D.gram_idx[n][1] && !err) {
		for (k = 0; k < 4; k++) {
			unsigned char a1, a2;
			temp[i].get_attr(k, a1, a2);
			if (a1 == 20) {
// ᨭ⥧Ёа®ў ­­л©  ваЁЎгв ®ЇҐа жЁ®­­®Ј® бЁ¬ў®« 
				ATTR na = (*(arr_fun_synth_attr[a2]))();
				temp[i].set_attr(k, na);
			}
			else {
				if (a1) {
					ATTR t_a;
					temp[a1].get_attr(a2, t_a);
					temp[i].set_attr(k, t_a);
				}
			}
		}
// ўл§®ў дг­ЄжЁЁ, ᮮ⢥вбвўго饩 ®ЇҐа ж. бЁ¬ў®«г
		err = (*(arr_fun_ops[temp[i].get_id(0)]))(temp[i], out, outb);
// err > 0 - cҐ¬ ­вЁзҐбЄ п ®иЁЎЄ 
// err = 0 - ok
		j++;
		i++;
	}
	if (err)
		return err;
// ўлзЁб«Ґ­ЁҐ  ваЁЎгв  «Ґў®Ј® ­ҐвҐа¬Ё­ « 
	unsigned char a1, a2;
	for (k = 0; k < 4; k++) {
		temp[0].get_attr(k, a1, a2);
		if (a1) {
			ATTR at;
			temp[a1].get_attr(a2, at);
			temp[0].set_attr(k, at);
		}
	}
// Љ« ¤Ґ¬ ў б⥪ бў®а зЁў Ґ¬л© ­ҐвҐа¬Ё­ «
	S.push(temp[0]);
	return 0; // ­Ґв ®иЁЎ®Є
}



// S- ваЁЎгв­л© „ЊЏ - Їа®жҐбб®а
int s_attr_dmp_proc(char n_dmp_p,  DMP_PROC* da, FILE* inp, FILE* out, FILE* outb, unsigned int& ntok, int& cp)
{
	int current_dmp_proc = 0;
// €­ЁжЁ «Ё§Ёа㥬 ўбҐ Ја ¬¬ вЁЄЁ  ваЁЎгв ¬Ё
	int w;
	for (w = 0; w < n_dmp_p; w++)
		init_gram_attr(da[w]);

	int t, i1, i2;
	int access = 0;    // д« Ј ¤®ЇгбЄ 
	int move_head = 1; // д« Ј ЇҐаҐ¬ҐйҐ­Ёп Ј®«®ўЄЁ
	int error = 0;     // д« Ј ®иЁЎЄЁ
	ntok = 0;

	S.push(bs);        // ­ з бЁ¬ў®« ¬ Ј §Ё­ 
	int x, y;
	int xy_new = 1;

	do {
		if (move_head) {
			read_tok(inp, i1, i2);
			t = (i1 == -1) ? 4 : 0;  // 4- eps 0 - terminal
			i1 = (i1 == -1) ? 0 : i1;
			i2 = (i2 == -1) ? 0 : i2;
			ntok++;
		}
		SYMB in_symb(t, i1, i2);     // ўе.бЁ¬ў®«
		in_symb.set_attr(0, i1, i2); // гбв ­ ў«Ёў Ґ¬  ваЁЎгвл

		SYMB up_symb_stack = S.pop(); // ўҐаиЁ­  б⥪ 
		S.push(up_symb_stack);

		if (xy_new)
			determinate_xy_AF(da[current_dmp_proc], in_symb, up_symb_stack, x, y);

		if (x == -1) { // ­ҐЁ§ўҐбв­л© бЁ¬ў®« Ја ¬¬ вЁЄЁ
			if (current_dmp_proc) {
				x = da[current_dmp_proc].AF_x_sz - 1;
				xy_new = 0;
				move_head = 0;
			}
			else
				error = 1;
		}
		if (!error) {
			if ((y == 0 && in_symb == eps) || (y == 0 && !xy_new)) {  // bs S
				SYMB t1 = S.pop();
				SYMB t2 = S.pop();
				S.push(t2);
				S.push(t1);
				if (t2 == bs)
					y = da[current_dmp_proc].AF_y_sz;
			}
			int operation = da[current_dmp_proc].AF[y][x];
			if (operation) {
				switch(operation) {
					case 1: // ЇҐаҐ­®б
						S.push(in_symb);
						move_head = 1;
						xy_new = 1;
						break;
					case 2: // ᢥавЄ 
						error = reduction(da[current_dmp_proc], out, outb);
						move_head = 0;
						xy_new = 1;
						break;
					case 3: // ¤®ЇгбЄ
						if (current_dmp_proc) { // ЇҐаҐе®¤ ­  бв ал© Їа®ж.
							SYMB t1 = S.pop(); // б­Ё¬ Ґ¬ ­ з. бЁ¬ў. Ја ¬¬ в
							ATTR tattr[4]; // б®е࠭塞  ваЁЎгвл
							int x;
							for (x = 0; x < 4; x++)
								t1.get_attr(x, tattr[x]);
							S.pop(); // б­Ё¬ Ґ¬ ­ з. бЁ¬ў®« ¬ Ј §Ё­ 
							t1 = S.pop();
							for (x = 0; x < 4; x++) // ЇҐаҐ¤ Ґ¬  ваЁЎгвл
								t1.set_attr(x, tattr[x]);
							S.push(t1);
							current_dmp_proc = t1.get_id(1);
							xy_new = 1;
						}
						else
							access = 1;
						break;
					default: // ЇҐаҐе®¤ ­  ¤а. Їа®жҐбб®а
						if (operation > 49) { // дг­ЄжЁ®­. ЇҐаҐ­®б
							operation -=50;
							int f = (*fun_carry[operation])();
							if (f) {
								S.push(in_symb);
								move_head = 1;
								xy_new = 1;
							}
							else {
								x = da[current_dmp_proc].AF_x_sz - 1;
								xy_new = 0;
								move_head = 0;
							}
							break;
						}
						if (operation > 39) {
							operation -= 40;
							int f = (*carry_jmp[operation])(in_symb);
							// f = 0 (ЇҐаҐ­®б)
							if (!f) {
								S.push(in_symb);
								move_head = 1;
								break;
							}
							else
								operation = f;
						}
						if (operation > 19) {
							x = operation - 20; // 20 + x(AF)
							operation = da[current_dmp_proc].AF[y][x];
						}
						operation-= 4;
						move_head = 0; // ­Ґ б¤ўЁЈ Ґ¬ Ј®«®ўЄг
						SYMB tt = da[current_dmp_proc].AF_x[x];
						S.push(tt);
						S.push(bs); // ­ з. бЁ¬ў®« ¬ Ј §Ё­  ў б⥪
						current_dmp_proc = operation;
				}
			}
			else {
				if (!xy_new)
					error = 1;
				else {
					if (current_dmp_proc) { // ­Ґ 0 Їа®жҐбc®а
						x = da[current_dmp_proc].AF_x_sz - 1; // д-п ®в eps
						xy_new = 0;
						move_head = 0;
					}
					else
						error = 1;
				}
			}
		}

	} while ((!error) && (!access));

// ®Їгбв®и Ґ¬ б⥪
	while (!S.is_empty())
		S.pop();

	cp = current_dmp_proc;
	return error;
}

char* text_errors[] = {
"ЋиЁЎЄ  ЇҐаҐ­®б ",
"ЋиЁЎЄ  ᢥавЄЁ",
"ЌҐб®ўЇ ¤Ґ­ЁҐ вЁЇ®ў",
"€¤Ґ­вЁдЁЄ в®а ­Ґ ®Ўкпў«Ґ­",
"Џ®ўв®а­®Ґ ®Ўкпў«Ґ­ЁҐ Ё¤Ґ­вЁдЁЄ в®а ",
"ЌҐ¤®ЇгбвЁ¬л© Є« бб Ё¤Ґ­вЁдЁЄ в®а ",
"Њ®¤ЁдЁЄ жЁп Є®­бв ­в­®Ј® ®ЎкҐЄв ",
"ЌҐ¤®ЇгбвЁ¬ п ®ЇҐа жЁп",
"ЌҐб®®вўҐвбвўЁҐ а §¬Ґа®ў ¬ ваЁж",
"ЌҐб®®вўҐвбвўЁҐ а §¬Ґа­®б⥩ ¬ ббЁў ",
"ЏҐаҐЇ®«­Ґ­ЁҐ ў ®Ў« бвЁ ¤ ­­ле",
"ЌҐ¤®ЇгбвЁ¬л© а §¬Ґа ¬ ббЁў ",
"ЌҐЄ®а४в­л© вЁЇ Ё­¤ҐЄб  ¬ ббЁў /¬ ваЁжл",
"ЋиЁЎЄ  ЇаЁбў Ёў ­Ёп"
};

// ‚лў®¤ в Ў«Ёж Ї®б«Ґ бЁ­в ЄбЁзҐбЄ®Ј®  ­ «Ё§ 
void out_tables()
{
	int i;
	FILE* out = fopen("t_mark.syn", "w");
	fprintf(out, "*** Marks table(7):\n\n");
	fprintf(out, "N:    POS:\n");
	for (i = 0; i < t_mark.get_qntf(); i++) {
		fprintf(out, "%-7u%u\n", i, t_mark[i]);
	}
	fclose(out);

	out = fopen("t_id.syn", "w");
	fprintf(out, "*** Identifiers table(3):\n\n");
	fprintf(out, "N:   CLASS:  TYPE:      PTR:\n");
	for (i = 0; i < t_id.get_qntf(); i++) {
		fprintf(out, "%-7u%-7i%-7i[%-3i,%-3i]\n", i, t_id[i].cls, t_id[i].type, t_id[i].ptr.val[0], t_id[i].ptr.val[1]);
	}
	fprintf(out, "\nClass:\n1 - variable\n2 - constant variable\n3 - mark\n");
	fprintf(out, "\nTypes:\n");
	fprintf(out, "1 - int\n2 - float\n3 - fmatr\n4 - array of int\n5 - array of float\n");
	fclose(out);

	out = fopen("t_var.syn", "w");
	fprintf(out, "*** Variables table(6):\n\n");
	fprintf(out, "N:   TYPE:   SIZE:   ADDR:   OFFSET:  X_Matr:  Y_Matr:\n");
	for (i = 0; i < t_var.get_qntf(); i++) {
		fprintf(out, "%-7u%-7u%-7u$%-7u[%u %u]     %-7u%-7u\n", i, t_var[i].type, t_var[i].size, t_var[i].addr, t_var[i].offs.val[0], t_var[i].offs.val[1], t_var[i].attr.val[0], t_var[i].attr.val[1]);
	}
	fprintf(out, "\n\nSize variables area: %u\n", max_addr);
	fprintf(out, "Defined variables area: [0 - %u]\n", temp_addr - 1);
	fprintf(out, "Tempory area: [%u - %u]\n", temp_addr, max_addr - 1);
	fclose(out);

	out = fopen("t_i_cons.syn", "w");
	fprintf(out, "*** Numeric integer constant table(4):\n\n");
	fprintf(out, "N_CONST:  VALUE:\n");
	for (i = 0; i < t_i_const.get_qntf(); i++) {
		fprintf(out, "%-9u %i\n", i, t_i_const[i]);
	}
	fclose(out);

	out = fopen("t_f_cons.syn", "w");
	fprintf(out, "*** Numeric floating constant table(5):\n\n");
	fprintf(out, "N_CONST:  VALUE:\n");
	for (i = 0; i < t_f_const.get_qntf(); i++) {
		fprintf(out, "%-9u %f\n", i, t_f_const[i]);
	}
	fclose(out);
}


void link_asm()
{
	FILE* inp = fopen("atoms.bin", "rb");
	FILE* out = fopen("out.asm", "w");
	unsigned int n_atom = 0;
	unsigned char code, p1[3], p2[3];
	int i;
	unsigned int t;
	unsigned int offs[3];
	char need_sz_m = 0;

	fprintf(out, "\tinclude macro.inc\n\n");

	fprintf(out, "\t.model SMALL\n");
	fprintf(out, "\t.stack 100h\n\n");

	// generate data segment
	fprintf(out, "data\tsegment\n\n");

	// generate integer constant table
	fprintf(out, "ticonst\tlabel word\n");
	for (i = 0; i < t_i_const.get_qntf(); i++) {
		fprintf(out, "\tdw %i\n", t_i_const[i]);
	}

	// generate floating constant table
	fprintf(out, "\ntfconst\tlabel dword\n");
	for (i = 0; i < t_f_const.get_qntf(); i++) {
		fprintf(out, "\tdd %f\n", i, t_f_const[i]);
	}

	// generate variable data area
	fprintf(out, "\ntvar\tdb %u dup(?)\n", max_addr);

	fprintf(out, "\ndata\tends\n");


	// generate code segment
	fprintf(out, "\n\ntext\tsegment 'code'\n");
	fprintf(out, "\tassume cs:text, ds:data, es:data\n");
	fprintf(out, "p386\n");
	fprintf(out, "p387\n");

	fprintf(out, "main\tproc far\n");
	fprintf(out, "\tpush ds\n\txor ax, ax\n\tpush ax\n\tmov ax, data\n");
	fprintf(out, "\tmov ds, ax\n\tmov es, ax\n\n");
	fprintf(out, "\tcall openIO\n\n");
	// now generate code

	while (fscanf(inp, "%c%c%c%c%c%c%c", &code, p1, p2, p1 + 1, p2 + 1, p1 + 2, p2 + 2) != EOF) {
		// search mark in marks table
		char f_find = 0;
		i = 0;
		while (i < t_mark.get_qntf() && !f_find) {
			if (t_mark[i] == n_atom)
				f_find = 1;
			else
				i++;
		}

		if (f_find)
			fprintf(out, "@m%u:\t", n_atom);
		else
			fprintf(out, "\t");

		fprintf(out, "%s ", str_atom[code]);

		if (code == 8 || code == 19 || code == 20)
			// mulm , det, transp (need size of matrix!)
			need_sz_m = 1;
		else
			need_sz_m = 0;


		for (i = 0; i < 3; i++) {
			offs[i] = 0;

			if (p1[i] == 4) {
				t = p2[i] * 2;
				if (i != 0)
					fprintf(out, ", ");
				fprintf(out, "ticonst+%u", t);
			}
			else {
				if (p1[i] == 5) {
					if (i != 0)
						fprintf(out, ", ");
					fprintf(out, "tfconst+%u", p2[i]*4);
				}
				else {
					if (p1[i] == 6) {
						if (i != 0)
							fprintf(out, ", ");

						fprintf(out, "tvar+%u", t_var[p2[i]].addr);

						if (t_var[p2[i]].offs.ptr) {
							offs[i] = t_var[t_var[p2[i]].offs.val[1]].addr;
						}

						if (need_sz_m) {
							fprintf(out, ", %u, %u", t_var[p2[i]].attr.val[0], t_var[p2[i]].attr.val[1]);
						}
					}
					else {
						if (p1[i] == 7) {
							if (i != 0)
								fprintf(out, ", ");
							fprintf(out, "@m%u", t_mark[p2[i]]);
						}
					}
				}
			}
		}

		if ((code == 30) || (code == 2) || (code == 5)) // setm, addm, subm
			fprintf(out, ", %u", t_var[p2[1]].size);

		// add offsets for addr
		int count_out = 0;
		for (i = 0; i < 3; i++) {
			if (offs[i])
				count_out = i + 1;
		}
		for (i = 0; i < count_out; i++) {
			fprintf(out, ", %u", offs[i]);
		}

		fprintf(out, "\n");
		n_atom++;
	}

	fprintf(out, "@m%u:\n", n_atom);

	fprintf(out, "\n\tcall closeIO\n");
	fprintf(out, "\n\tret\nmain\tendp\ntext\tends\n\tend main\n");


	fclose(inp);
	fclose(out);

}




void link()
{
	FILE* inp = fopen("atoms.bin", "rb");
	FILE* out = fopen("link.txt", "w");
	unsigned int n_atom = 0;
	unsigned char code, p1[3], p2[3];
	int i;
	unsigned int t;

	while (fscanf(inp, "%c%c%c%c%c%c%c", &code, p1, p2, p1 + 1, p2 + 1, p1 + 2, p2 + 2) != EOF) {
		fprintf(out, "%-3u: %s  ", n_atom++, str_atom[code]);
		for (i = 0; i < 3; i++) {
			if (p1[i] == 4) {
				t = p2[i] * 2;
				fprintf(out, "ticonst + %u;  ", t);
			}
			else {
				if (p1[i] == 5) {
					t = p2[i] * 4;
					fprintf(out, "tfconst + %u;  ", t);
				}
				else {
					if (p1[i] == 6) {
						if (t_var[p2[i]].offs.ptr == 0) {
							fprintf(out, "tvar + %u;  ", t_var[p2[i]].addr);
						}
						else
							fprintf(out, "tvar + %u + [$%u];  ", t_var[p2[i]].addr, t_var[t_var[p2[i]].offs.val[1]].addr);
					}
					else {
						if (p1[i] == 7)
							fprintf(out, "%u;  ", t_mark[p2[i]]);
						else
							fprintf(out, ";  ");
					}
				}
			}
		}
		fprintf(out, "\n");
	}
	fprintf(out, "%-3u: end\n", cur_atom);
	fclose(inp);
	fclose(out);
}





int main()
{
	if (init_tables())
		return 1;

	printf(":::‘Ё­в ЄбЁзҐбЄЁ©  ­ «Ё§ в®а:::\n");

	FILE* inp = fopen("token.bin", "rb");
	if (inp == NULL) {
		printf("Warning! FILE: token.bin NOT FOUND!!!\n");
		return 1;
	}

	FILE* out = fopen("atoms.txt", "w");
	FILE* outb = fopen("atoms.bin", "wb");

	char n_dmp_proc = 9;

	DMP_PROC dmp_arr[9] = {
{n_rul0, max_rul0, gram0, gram0_idx, gram0_attr, AF0_x_sz, AF0_x, AF0_y_sz, AF0_y, AF0, AG0, &sub_gram0},
{n_rul1, max_rul1, gram1, gram1_idx, gram1_attr, AF1_x_sz, AF1_x, AF1_y_sz, AF1_y, AF1, AG1, &sub_gram1},
{n_rul2, max_rul2, gram2, gram2_idx, gram2_attr, AF2_x_sz, AF2_x, AF2_y_sz, AF2_y, AF2, AG2, &sub_gram2},
{n_rul3, max_rul3, gram3, gram3_idx, gram3_attr, AF3_x_sz, AF3_x, AF3_y_sz, AF3_y, AF3, AG3, &sub_gram3},
{n_rul4, max_rul4, gram4, gram4_idx, gram4_attr, AF4_x_sz, AF4_x, AF4_y_sz, AF4_y, AF4, AG4, &sub_gram4},
{n_rul5, max_rul5, gram5, gram5_idx, gram5_attr, AF5_x_sz, AF5_x, AF5_y_sz, AF5_y, AF5, AG5, &sub_gram5},
{n_rul6, max_rul6, gram6, gram6_idx, gram6_attr, AF6_x_sz, AF6_x, AF6_y_sz, AF6_y, AF6, AG6, NULL},
{n_rul7, max_rul7, gram7, gram7_idx, gram7_attr, AF7_x_sz, AF7_x, AF7_y_sz, AF7_y, AF7, AG7, &sub_gram7},
{n_rul8, max_rul8, gram8, gram8_idx, gram8_attr, AF8_x_sz, AF8_x, AF8_y_sz, AF8_y, AF8, AG8, &sub_gram8},
	};

	int np = 0;
	unsigned int ntok;
	int e = s_attr_dmp_proc(n_dmp_proc, dmp_arr, inp, out, outb, ntok, np);

	if (e) {
		printf("!!! ЋиЁЎЄ  [%i][Џа®жҐбб®а: %i][‹ҐЄбҐ¬ : %u]!!!\n", e, np, ntok);
		e = (e < 10) ? e - 1: e - 8;
		printf("  - %s\n\n", text_errors[e]);
		fclose(inp);
		fclose(out);
		fclose(outb);
		return 1;
	}
	else {
		printf("OK!!!\n");
		printf("ѓҐ­ҐаЁагҐ¬лҐ д ©«л:\n");
		printf("> atoms.bin - Ї®б«Ґ¤®ў вҐ«м­®бвм вҐва ¤ ў ЎЁ­ а­®¬ д®а¬ вҐ\n");
		printf("> atoms.txt - Ї®б«Ґ¤®ў вҐ«м­®бвм вҐва ¤ ў ⥪бв®ў®¬ д®а¬ вҐ\n");
		printf("> link.txt - Ї®б«Ґ¤®ў вҐ«м­®бвм вҐва ¤ Ї®б«Ґ «Ё­Є®ўЄЁ\n");
		printf("> t_i_const.syn - в Ў«Ёж  楫ле Є®­бв ­в\n");
		printf("> t_f_const.syn - в Ў«Ёж  ўҐйҐб⢥­­ле Є®­бв ­в\n");
		printf("> t_id.syn - в Ў«Ёж  Ё¤Ґ­вЁдЁЄ в®а®ў\n");
		printf("> t_var.syn - в Ў«Ёж  ЇҐаҐ¬Ґ­­ле\n");
		printf("> t_mark.syn - в Ў«Ёж  ¬Ґв®Є\n");
		fprintf(out, "%-3i: end.\n", cur_atom);
	}
	fclose(inp);
	fclose(out);
	fclose(outb);

	out_tables();
	link();
	link_asm();
	return 0;
}

/*
ЋиЁЎЄЁ dmp-Їа®жҐбб®а :

‘Ё­в ЄбЁзҐбЄЁҐ ®иЁЎЄЁ:
1 - ЋиЁЎЄ  ЇҐаҐ­®б 
2 - ЋиЁЎЄ  ᢥавЄЁ

‘Ґ¬ ­вЁзҐбЄЁҐ ®иЁЎЄЁ:

10 - ­Ґб®ўЇ ¤Ґ­ЁҐ вЁЇ®ў
11 - Ё¤Ґ­вЁдЁЄ в®а ­Ґ ®Ўкпў«Ґ­
12 - Ї®ўв®а­®Ґ ®Ўкпў«Ґ­ЁҐ Ё¤Ґ­вЁдЁЄ в®а 
13 - ­Ґ в®в Є« бб Ё¤Ґ­вЁдЁЄ в®а 
14 - ¬®¤ЁдЁЄ жЁп Є®­бв ­в­®Ј® ®ЎкҐЄв 
15 - ­Ґ ¤®ЇгбвЁ¬ п ®ЇҐа жЁп
16 - ­Ґ ᮮ⢥вбвўЁҐ а §¬Ґа®ў ¬ ваЁж
17 - ­Ґ ᮮ⢥вбвўЁҐ а §¬Ґа­®б⥩ ¬ ббЁў 
18 - ЇҐаҐЇ®«­Ґ­ЁҐ ®Ў« бвЁ ¤ ­­ле
19 - ­Ґ ¤®ЇгбвЁ¬л© а §¬Ґа ¬ ббЁў 
20 - ­ҐЄ®а४в­л© вЁЇ Ё­¤ҐЄб 
21 - ­Ґў®§¬®¦­®бвм ЇаЁбў®Ґ­Ёп
*/
Соседние файлы в папке kurs