📄 midcode.h
字号:
// File Name: MidCode.h
#include "CharStack.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
struct MIDCODE
{
char Op;
WORDNODE *pArg1;
WORDNODE *pArg2;
WORDNODE *pResult;
} m_MidCode[MAX_DATA_LEN];
int m_nMidCodeLen;
void InitMidCode()
{
m_nMidCodeLen = -1;
}
void Gen(char Op, WORDNODE *pArg1, WORDNODE *pArg2, WORDNODE *pResult)
{
++m_nMidCodeLen;
m_MidCode[m_nMidCodeLen].Op = Op;
m_MidCode[m_nMidCodeLen].pArg1 = pArg1;
m_MidCode[m_nMidCodeLen].pArg2 = pArg2;
m_MidCode[m_nMidCodeLen].pResult = pResult;
}
void GetCodeString(WORDNODE *pWord, char cResult[])
{
if (pWord == NULL)
{
cResult[0] = '\0';
return;
}
if (pWord->byType != WT_TEMP)
{
memcpy(cResult, pWord->Value, MAX_DATA_LEN);
return;
}
cResult[0] = 'T';
_itoa(pWord->Value[0], &cResult[1], 10);
}
void PrintMidCode()
{
char c[3][MAX_DATA_LEN];
printf("生成四元式为:\n");
for (int i = 0; i <= m_nMidCodeLen; i++)
{
GetCodeString(m_MidCode[i].pArg1, c[0]);
GetCodeString(m_MidCode[i].pArg2, c[1]);
GetCodeString(m_MidCode[i].pResult, c[2]);
printf("%2d (%c,%s,%s,%s)\n", i, m_MidCode[i].Op, c[0], c[1], c[2]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -