• 大小: 417KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-27
  • 语言: 其他
  • 标签: IF-ELSE  LL(1)法  

资源简介

IF-ELSE条件语句的翻译程序设计(LL(1)法、输出四元式)

资源截图

代码片段和文件信息

#include“LinearList.h“
#include
#include
#include
#include
using namespace std;
//grammar analysis
LinearList list;
//store input string which is dividing by word
LinearList signStringsourceStringsecondList;
//keyWordseparatoroperatorvariable list to store each kind of word
LinearList keyWordListseparatorListoperatorListvariableList;
//store the grammar
LinearList grammarList;
//grammar
/********************************************************/
/*
E->if A then S else W
A->iB|(A)|notA
B->+TB|-TB|*TB|/TB
B->TB|==TB|>=TB|<=TB
B->orTB|andTB
B->e     //empty
T->i
S->i:=i+i;
W->i:=i*i;
*/
/*
forecast table
    i      +     -     *     /     (     )    >     <     <=     >=    ==   not   or    and    if    #
E                                                                                             ->ifAthenSelseW
A ->iB                           ->(A)                                    ->notA
B       ->+TB  ->TB  ->*TB  ->/TB      ->e  ->>TB -><=TB ->>=TB ->==TB    ->orTB ->andTB     ->e
T ->i
S ->i:=i+i;
W ->i:=i*i;

*/
/*******************************************************/
char * stringToCharP(string s)
{
const char *c=s.c_str();
char *copy=new char[strlen(c)+1];
strcpy(copyc);
return copy;
}
void method()
{
string s1=signString.getFirst()->data;//the head of the remaining input string
string s2=grammarList.getFirst()->data;//the head of the analysis list
char *charPoint1=stringToCharP(s1);
char *charPoint2=stringToCharP(s2);
if(strcmp(charPoint2“#“)==0) {
cout<<“right“< return;
}
else if(strcmp(charPoint1charPoint2)==0)
{
grammarList.removeFirst();
signString.removeFirst();
}
else if(strcmp(charPoint2“E“)==0)
{
if(strcmp(charPoint1“if“)==0)
{
//remove the first element and replace it with its deduction
//E->if A then S else W
grammarList.removeFirst();
grammarList.addFirst(“W“);
grammarList.addFirst(“else“);
grammarList.addFirst(“S“);
grammarList.addFirst(“then“);
grammarList.addFirst(“A“);
grammarList.addFirst(“if“);
}
}
else if(strcmp(charPoint2“A“)==0)
{
//remove the first element and replace it with its deduction
//A->iB|(A)|notA
if(strcmp(charPoint1“i“)==0)
{
grammarList.removeFirst();
grammarList.addFirst(“B“);
grammarList.addFirst(“i“);
}
else if(strcmp(charPoint1“(“)==0)
{
grammarList.removeFirst();
grammarList.addFirst(“)“);
grammarList.addFirst(“A“);
grammarList.addFirst(“(“);
}
else if(strcmp(charPoint1“not“)==0)
{
grammarList.removeFirst();
grammarList.addFirst(“A“);
grammarList.addFirst(“not“);
}
}
else if(strcmp(charPoint2“B“)==0)
{
//remove the first element and replace it with its deduction
//B->+TB|-TB|*TB|/TB|e
//B->TB|==TB
//B->orTB|andTB
if(strcmp(charPoint1“+“)==0)
{
grammarList.rem

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    2288640  2010-01-09 00:00  Compare\Compare.ncb

     文件        887  2010-01-06 09:02  Compare\Compare.sln

    ..A..H.     17408  2010-01-09 00:00  Compare\Compare.suo

     文件      17740  2010-01-06 09:03  Compare\Compare\Compare.aps

     文件      14552  2010-01-08 23:33  Compare\Compare\Compare.cpp

     文件       1282  2010-01-06 09:03  Compare\Compare\Compare.rc

     文件         60  2010-01-07 21:09  Compare\Compare\compare.txt

     文件       3769  2010-01-06 20:54  Compare\Compare\Compare.vcproj

     文件       1427  2010-01-09 00:00  Compare\Compare\Compare.vcproj.XSIT-53C3F15323.xsit.user

     文件       4060  2010-01-07 15:46  Compare\Compare\LinearList.h

     文件       8404  2010-01-08 23:33  Compare\Compare\Debug\BuildLog.htm

     文件        621  2010-01-08 23:33  Compare\Compare\Debug\Compare.exe.intermediate.manifest

     文件     154283  2010-01-08 23:33  Compare\Compare\Debug\Compare.obj

     文件         32  2010-01-06 09:03  Compare\Compare\Debug\Compare.res

     文件         67  2010-01-08 23:33  Compare\Compare\Debug\mt.dep

     文件     191488  2010-01-08 23:33  Compare\Compare\Debug\vc90.idb

     文件     241664  2010-01-08 23:33  Compare\Compare\Debug\vc90.pdb

     目录          0  2010-01-10 17:29  Compare\Compare\Debug

     目录          0  2010-01-10 17:29  Compare\Compare

     目录          0  2010-01-10 17:29  Compare

----------- ---------  ---------- -----  ----

              2946384                    20


评论

共有 条评论