Синтаксический анализатор. Написание синтаксического анализатора для языка ADA на любом доступном языке программирования., страница 3

МР автомат


Текстпрограммы

//--------------------------------------------------------------------------#include <vcl.h>

#include <math.h>

#include <fstream.h>

#include <stdio.h>

#include <string.h>

#include <StrUtils.hpp> // Библиотека работы со строками

#include <ShellApi.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit2.h"

#define bukva 1

#define cifra 2

#define znak 3

#define probel 4

#define tck 5

#define pod 6

//--------------------------------------------------------------------------#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

void printlist(void);

int exist;

//int skolko=0; //сколько всего объявлено подпрограмм

int dop=0; //допустить или нет

//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

Memo1->Clear();ListBox2->Clear(); ListBox3->Clear();

printlist();

Memo1->Focused();

}

//--------------------------------------------------------------------------char letter[52] =

{

'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',

'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z',

'x', 'c', 'v', 'b', 'n', 'm','Q' , 'W', 'E', 'R',

'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F',

'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B',

'N', 'M'

};

char number[10] =

{

'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'

};

char zna[16] =

{

'+', '-', '*', '(', ')', '<', '>', '&', '|', '=', ':', ';', ',', '/', '_', '.' //  =>,**,/=,

};

struct oper

{

int nmb;

char name[10];

};

struct queue

{

int i,j;

}que[512];

int ique=0;

char ident[50][20];

int id=0;

char con[50][20];

int co=0;

oper opername[33]= {

{0, "begin"},

{1, "end"},

{2, "not"},

{3, "if"},

{4, "then"},

{5, "else"},

{6, "goto"},

{7, "case"},

{8, "elsif"},

{9, "for"},

{10,"loop"},

{11,"or"},

{12,"and"},

{13,"xor"},

{14,"return"},

{15,"while"},

{16,"integer"},

{17,"float"},

{18,"boolean"},

{19,"mod"},

{20,"function"},

{21,"procedure"},

{22,"constant"},

{23,"exit"},

{24,"delay"},

{25,"of"},

{26,"when"},

{27,"reverse"},

{28,"is"},

//{29,"in"},

{29,"true"},

{30,"false"},

{31,"print"},

{32,"input"}

};

int st[5000];                    // стек из 5000 целых чисел

int deep = 0;                    // указатель на вершину // число записанных в стек элементов

void push(int x)

{

st[deep++] = x;            // запись в стек

}

int pop()                    //извлечение из стека

{

return st[--deep];

}

int peek()                    //чтение из стека

{

return st[deep-1];

}

void clear(void);

void printlist(void)  //функция печати в ListBoxы

{                                  //ключевых слов и разделителей

int i;

char  buf[20];

for(i=0;i<33;i++)

{

sprintf(buf,"%i %s",i,opername[i].name);

Form1->ListBox2->Items->Add(buf);

}

for(i=0;i<16;i++)

{

sprintf(buf,"%i %c",i,zna[i]);

Form1->ListBox3->Items->Add(buf);

}

Form1->ListBox3->Items->Add("16 ..");

Form1->ListBox3->Items->Add("17 **");

Form1->ListBox3->Items->Add("18 /=");

Form1->ListBox3->Items->Add("19 <=");

Form1->ListBox3->Items->Add("20 >=");

Form1->ListBox3->Items->Add("21 :=");

Form1->ListBox3->Items->Add("22 =>");

}

void fileprint(char temp[],char filename[],char b[])

{

int consti=0;