编译原理-LL(1)预测分析实验 c源代码

   编译原理实验--LL(1)预测分析,根据LL(1)文法,写出各文法左部的FIRST集 FOLLOW集 SELECT集.然后根据SELECT集 写出预测分析表.本程序是在SELECT集建立后,程序根据预测分析表进行分析.

 

/**
*@Create:      2006-11-21
*@Description: LL(1) forcast Analyse
*@Author:      oDon
*@Corporation: xxxxxxx CO.
*@Copyright:   yuanonline@hotmail.com  --oDon--

               0       1        2       3        4         5         6        7   
---------------------------------------table---------------------------------------
|        |    I    |    +   |   -    |   *   |    /     |    (    |    )   |    #    |
------------------------------------------------------------------------------------
|  E         ->TG                                          ->TG                                      |
------------------------------------------------------------------------------------
|  G                 ->+TG    ->-TG                                   ->~     ->~  |
------------------------------------------------------------------------------------
|  T       ->FS                                            ->FS                     |
------------------------------------------------------------------------------------
|  S                  ->~        ->~     *FS      /FS                ->~      ->~  |
------------------------------------------------------------------------------------
|  F         ->i                                              ->(E)                |
-----------------------------------------------------------------------------------
*/

#include 
" stdio.h "
#define SIZE 
20
#define EMPTY 
14
#define TABLE_SIZE 
5

typedef struct table
{
        
char head;
        
char  pre[8][4]; 
}
table;

char  ExpressionStr[SIZE];                        // Inputed Analysed Expression
char  AnalysisStack[SIZE];                        // Analysis Stack
unsigned  char  analysis_Index;                    //
unsigned  char  analy_Index;                       // Current TOP_Index of Expression
unsigned  char  exp_Index;                         // Current Bottom_Index of Expression
unsigned  char  step;
table tb[TABLE_SIZE];                                               
// forcast table---------------



/***************************************
 @name:       InitTable
 @Describe:   Initlize the forcast table
 @Param:      void
 @Return:     void
 ****************************************
*/

void  InitTable()
{
     
// table E
     tb[0].head = 'E';
     strcpy(tb[
0].pre[0], "GT");
     strcpy(tb[
0].pre[5], "GT");
     
//table G
     tb[1].head = 'G';
     strcpy(tb[
1].pre[1], "GT+");
     strcpy(tb[
1].pre[2], "GT-");
     strcpy(tb[
1].pre[6], "~");
     strcpy(tb[
1].pre[7], "~");
     
//table T
     tb[2].head = 'T';
     strcpy(tb[
2].pre[0], "SF");
     strcpy(tb[
2].pre[5], "SF");
     
//table S
     tb[3].head = 'S';
     strcpy(tb[
3].pre[1], "~");
     strcpy(tb[
3].pre[2], "~");
     strcpy(tb[
3].pre[3], "SF*");
     strcpy(tb[
3].pre[4], "SF/");
     strcpy(tb[
3].pre[6], "~");
     strcpy(tb[
3].pre[7], "~");
     
//table F
     tb[4].head = 'F';
     strcpy(tb[
4].pre[0], "i");
     strcpy(tb[
4].pre[5], ")E(");
}


/***************************************
 @name:       PrintGenerate
 @Describe:   Printing Generate expression
 @Param:      void
 @Return:     void
 ****************************************
*/

 
void  PrintGenerate( char   * ch)
 
{
      
int i = 0;
      
for(i = strlen(ch) - 1; i >= 0; i--)
      
{
            printf(
"%c",ch[i]);
      }

      printf(
" ");
      
 }


/*******************************************
*@name:        Trace
*@Description: Format output
*@Param:       void
*@Return:      void
*******************************************
*/

void  Trace()
{
     
int i = 0;
     
int j = 0;
     printf(
" ");
     printf(
"%d  ",step++);
     
while(AnalysisStack[i] != '
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值