⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 利用flex和bison做的简易C语言编译器核心 支持C语言的大部分运算操作和语法,但是没有 变量声明和函数声明 适合制作虚拟机之类的 输出结果是伪汇编代码 我会继续更新
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

#ifndef DEBUG_PRINT_TOKEN
#define DEBUG_PRINT_TOKEN
#endif/*DEBUG_PRINT_TOKEN*/

#include "calc_flex.c"
#include "calc_yacc.c"
//---------------------------------------------------------------------------
long g_LabCount = 0;

void zzlabel(char *s)
{
    sprintf(s, "%04d", g_LabCount ++);
}
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
FILE *asout = NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        this->Memo1->Lines->SaveToFile("temp_i.txt");

        yyin  = fopen("temp_i.txt", "r+");
        yyout = fopen("temp_o.txt", "w+");
        asout = fopen("uasm_o.txt", "w+");

        //while(yylex());

        yyparse();

        fclose(yyin);
        fclose(yyout);
        fclose(asout);

        this->Memo2->Clear();
        this->Memo2->Lines->LoadFromFile("temp_o.txt");

        this->Memo3->Clear();
        this->Memo3->Lines->LoadFromFile("uasm_o.txt");
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -