91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.09MB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2024-01-23
  • 語言: C/C++
  • 標(biāo)簽: LEX??YACC??南開??王剛??

資源簡介

只能實(shí)現(xiàn)斐波那契數(shù)列,沒有實(shí)現(xiàn)pi.c,得分五分 上機(jī)大作業(yè)——簡化C編譯器實(shí)現(xiàn) 總體要求 一、要求實(shí)現(xiàn)的語言特性 1. 基本要求 1數(shù)據(jù)類型:int,char 2語句:賦值(=),if,while,for;賦值 循環(huán) 條件判斷 3算術(shù)運(yùn)算:+,-,*,/,%,++,--,&,|,^,~,<> 4關(guān)系運(yùn)算:==,>,=,<=,!= 5邏輯運(yùn)算:&&(與),||(或),!(非);構(gòu)造與算數(shù)相同 6復(fù)合語句:{、}括起來的語句;要求識(shí)別 if、while中使用 7注釋語句;識(shí)別注釋 然后丟棄 8簡單的輸入輸出 2. 選作功能 1數(shù)組,指針;數(shù)組怎么實(shí)現(xiàn) 第八章介紹數(shù)組的翻譯 2函數(shù) 3其他特性(浮點(diǎn)運(yùn)算、結(jié)構(gòu)/類、連接C標(biāo)準(zhǔn)庫等等) 生成的目標(biāo)代碼 生成x86匯編語言程序。;不要求二進(jìn)制 由編譯器編譯成二進(jìn)制 要求提交的內(nèi)容 1C語言子集的描述:詞法結(jié)構(gòu)的正則表達(dá)式定義、語法結(jié)構(gòu)的CFG定義。 ;簡化子集的描述 2編譯器源程序文本,包括Lex、Yacc等程序和C/C++程序。;兩種語言工具 構(gòu)造詞法分和語法分析部分 passive generate 3編譯器演示程序,可將C語言子集測試程序編譯為目標(biāo)代碼——匯編程序,用匯編器轉(zhuǎn)換為二進(jìn)制程序后運(yùn)行無誤,如斐波那契數(shù)列程序,應(yīng)能翻譯為正確的匯編程序。

資源截圖

代碼片段和文件信息


#include?“globals.h“
#include?“util.h“
#include?“parse.h“
#include?“symtab.h“
#include?“analyze.h“

/*?counter?for?variable?memory?locations?*/
static?int?location?=?0;

/*?current?symble?table?*/
static?Symtab?*?pTable;
static?FunEntry?*?pFun;

/*?procedure?traverse?is?a?generic?recursive
?*?syntax?tree?traversal?routine:
?*?it?applies?preProc?in?preorder?and?postProc
?*?in?postorder?to?tree?pointed?to?by?t
?*/
static?void?traverse(TreeNode?*?t
?void?(*?preProc)?(TreeNode?*)
?void?(*?postProc)?(TreeNode?*))
{
if?(t?!=?NULL)
{
int?i;
preProc(t);
for?(i=0;?i? traverse(t->child[i]?preProc?postProc);
postProc(t);
traverse(t->sibling?preProc?postProc);
}
}

/*?nullProc?is?a?do-nothing?procedure?to
?*?generate?preorder-only?or?postorder-only
?*?traversals?from?traverse
?*/
static?void?nullpreProc(TreeNode?*?t)
{
if?(t?==?NULL)?return;
else?if?(t->nodekind?==?Dec)?{
switch?(t->kind.dec)
{
case?FunDefK:
pFun?=?Lookup_Fun(t->attr.name);
break;
case?CompK:
pTable?=?t->attr.table;
break;
}
}
}

static?void?nullpostProc(TreeNode?*?t)
{
if?(t?==?NULL?||?pTable?==?NULL)?return;
else?if?(t->nodekind?==?Dec?&&?t->kind.dec?==?CompK)
pTable?=?pTable->parent;
}

/*?procedure?insertNode?inserts
?*?identifiers?stored?in?t?into
?*?the?symbol?table
?*/
static?void?insertNode(TreeNode?*?t)
{
switch?(t->nodekind)
{
????case?Dec:
switch?(t->kind.dec)
{
case?FunDecK:
if?(Lookup_Fun(t->attr.name)?==?NULL)
Insert_Fun(t->attr.name?t->type?t->child[0]);
break;
case?FunDefK:
if?(Lookup_Fun(t->attr.name)?==?NULL)
pFun?=?Insert_Fun(t->attr.name?t->type?t->child[0]);
break;
case?VarK:
{
ValEntry?Entry;
TreeNode?*?child;
for?(child?=?t->child[0];?child?!=?NULL;?child?=?child->sibling)?{
if?(child->nodekind?==?Exp?&&?child->kind.exp?==?IdK)?{
if?(Lookup_Var(pTable?pFun?child->attr.name?&Entry)?!=?pTable->nestlevel)
if?(child->child[0]?==?NULL)
Insert_Var(pTable?child->attr.name?t->type?1);
else
Insert_Var(pTable?child->attr.name?t->type?child->child[0]->attr.val.i);
}
else?if?(child->nodekind?==?Stmt?&&?child->kind.stmt?==?AssignK)?{
if?(Lookup_Var(pTable?pFun?child->child[0]->attr.name?&Entry)?!=?pTable->nestlevel)
if?(child->child[0]->child[0]?==?NULL)
Insert_Var(pTable?child->child[0]->attr.name?t->type?1);
else
Insert_Var(pTable?child->child[0]->attr.name?t->type?child->child[0]->child[0]->attr.val.i);
}
}
}
break;
case?CompK:
pTable?=?Createtab(pTable?pFun);
if?(pTable==NULL)
fprintf(listing?“Out?of?memory?error?at?line?%d\n“?t->lineno);
t->attr.table?=?pTable;
break;
????????default:
break;
??????}
??????break;
default:
break;
}
}

/*?function?buildSymtab?constructs?the?symbol
?*?table?by?preorder?travers

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-12-12?15:34??complier_第五次作業(yè)_小型C編譯器\
?????文件????????8133??2012-12-27?12:28??complier_第五次作業(yè)_小型C編譯器\analyze.c
?????文件?????????314??2012-12-27?12:29??complier_第五次作業(yè)_小型C編譯器\analyze.h
?????目錄???????????0??2016-12-08?19:00??complier_第五次作業(yè)_小型C編譯器\Backup\
?????目錄???????????0??2016-12-12?15:30??complier_第五次作業(yè)_小型C編譯器\Backup1\
?????文件?????????953??2016-12-08?19:00??complier_第五次作業(yè)_小型C編譯器\Backup1\main.sln
?????文件???????25104??2012-12-27?12:29??complier_第五次作業(yè)_小型C編譯器\CodeGen.c
?????文件????????1807??2012-12-27?12:29??complier_第五次作業(yè)_小型C編譯器\CodeGen.h
?????目錄???????????0??2016-12-08?19:00??complier_第五次作業(yè)_小型C編譯器\Debug\
?????文件???????15522??2012-12-27?12:48??complier_第五次作業(yè)_小型C編譯器\Debug\analyze.obj
?????文件???????75491??2012-12-27?12:48??complier_第五次作業(yè)_小型C編譯器\Debug\CodeGen.obj
?????文件??????254058??2008-12-25?19:59??complier_第五次作業(yè)_小型C編譯器\Debug\main.exe
?????文件?????1092656??2008-12-25?19:59??complier_第五次作業(yè)_小型C編譯器\Debug\main.ilk
?????文件????????9350??2012-12-27?12:48??complier_第五次作業(yè)_小型C編譯器\Debug\main.obj
?????文件???????76577??2008-12-23?21:42??complier_第五次作業(yè)_小型C編譯器\Debug\parse.obj
?????文件???????13821??2008-12-23?21:42??complier_第五次作業(yè)_小型C編譯器\Debug\scan.obj
?????文件???????13379??2008-12-23?14:31??complier_第五次作業(yè)_小型C編譯器\Debug\symtab.obj
?????文件???????27178??2008-12-23?21:42??complier_第五次作業(yè)_小型C編譯器\Debug\util.obj
?????文件???????74752??2012-12-27?13:43??complier_第五次作業(yè)_小型C編譯器\Debug\vc60.idb
?????文件???????53248??2012-12-27?13:43??complier_第五次作業(yè)_小型C編譯器\Debug\vc60.pdb
?????文件????????3138??2012-12-27?12:29??complier_第五次作業(yè)_小型C編譯器\globals.h
?????文件????????2503??2016-12-08?18:46??complier_第五次作業(yè)_小型C編譯器\main.c
?????文件????????4212??2008-12-22?10:11??complier_第五次作業(yè)_小型C編譯器\main.dsp
?????文件?????????533??2008-12-22?10:11??complier_第五次作業(yè)_小型C編譯器\main.dsw
?????文件??????295936??2012-12-27?13:43??complier_第五次作業(yè)_小型C編譯器\main.ncb
?????文件???????52736??2012-12-27?13:43??complier_第五次作業(yè)_小型C編譯器\main.opt
?????文件????????1501??2012-12-27?13:43??complier_第五次作業(yè)_小型C編譯器\main.plg
?????文件?????2555904??2016-12-12?15:34??complier_第五次作業(yè)_小型C編譯器\main.sdf
?????文件?????????953??2016-12-12?15:30??complier_第五次作業(yè)_小型C編譯器\main.sln
?????文件???????23040??2016-12-12?15:34??complier_第五次作業(yè)_小型C編譯器\main.v12.suo
?????文件????????6778??2016-12-12?15:30??complier_第五次作業(yè)_小型C編譯器\main.vcxproj
............此處省略19個(gè)文件信息

評論

共有 條評論