📄 code.cpp
字号:
// Code.cpp : implementation file
//
#include "stdafx.h"
#include "My1.h"
#include "Code.h"
#include "InputDlg.h"
#include <fstream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCode
#include "ResultDlg.h"
CCode::CCode()
{
}
void CCode::Interpret()
{
fstream outfile;
outfile.open("c://Data.txt",ios::out);
char buf[20];
int p,t;
fct f;
int l,a;
t=0;b=1;p=0;
s[1]=0;s[2]=0;s[3]=0;
do{
f=code[p].f;l=code[p].l;a=code[p].a;
p++;
switch (f)
{
case lit:
s[++t]=a;
break;
case opr:
switch (a)
{
case 0:
t=b-1;
p=s[t+3];
b=s[t+2];
break;
case 1:
s[t]=-s[t];
break;
case 2: t--;
s[t]=s[t]+s[t+1];
break;
case 3: t--;
s[t]=s[t]-s[t+1];
break;
case 4: t--;
s[t]=s[t]*s[t+1];
break;
case 5: t--;
s[t]=s[t]/s[t+1];
break;
case 6:
s[t]=s[t]%2;
break;
case 8: t--;
s[t]=(s[t]==s[t+1]);
break;
case 9: t--;
s[t]=(s[t]!=s[t+1]);
break;
case 10: t--;
s[t]=(s[t]<s[t+1]);
break;
case 11: t--;
s[t]=(s[t]>=s[t+1]);
break;
case 12: t--;
s[t]=(s[t]>s[t+1]);
break;
case 13: t--;
s[t]=(s[t]<=s[t+1]);
break;
case 14:
sprintf(buf,"%d",s[t]);
outfile<<buf;
break;
case 15:
sprintf(buf,"\n");
outfile<<buf;
break;
case 16:
t++;
CInputDlg d;
d.DoModal();
s[t]=d.m_input;
break;
}
break;
case lod:
t++;
s[t]=s[Base(l)+a];
break;
case sto:
s[Base(l)+a]=s[t];
t--;
break;
case cal:
s[t+1]=Base(l);
s[t+2]=b;
s[t+3]=p;
b=t+1;
p=a;
break;
case intint:
t+=a;break;
case jmp:
p=a;break;
case jpc:
if (s[t]==0) p=a;
t--;
break;
}
}while (p!=0);
outfile.close();
CResultDlg dlg;
dlg.DoModal();
}
void CCode::Gen(enum fct x,int y,int z)
{
if (cx<CODE_SIZE)
{
code[cx].f=x;
code[cx].l=y;
code[cx].a=z;
cx++;
}
}
int CCode::Base(int l)
{
int b1;
b1=b;
while (l>0)
{
b1=s[b1];
l--;
}
return b1;
}
CCode::CCode(CCompiler *compiler)
{
mCompiler =compiler;
cx =0;
}
CCode::~CCode()
{
}
BEGIN_MESSAGE_MAP(CCode, CWnd)
//{{AFX_MSG_MAP(CCode)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCode message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -