遞迴下降剖析器

來源:互聯網
上載者:User

標籤:上下文無關文法   style   表達   div   stdio.h   new   void   截取   理解   

實驗一、遞迴下降分析實驗

專業   姓名  學號

一、 實驗目的

 

     練習構造遞迴下降文法剖析器的方法,熟悉上下文無關文法的使用,加深對課堂教學的理解;提高文法分析方法的實踐能力。

 

二、 實驗內容和要求

     利用c語言構造文法剖析器。

 

三、 實驗方法、步驟及結果測試

 

  1. 原理分析及流程圖

對於給定的文法

E—>aE | bE | T

T—>=T | +T | -T | *T | F

F—>( E ) F | ;

 

  1. 主要程式段及其解釋:
#include<stdio.h>#include<string>char str[50];   //要分析的字串int ch=0;       void scaner();void E();                     void T();           void F();void error(); main(){    int len;    printf("請輸入算數運算式:");    scanf("%s",str);    len=strlen(str);    str[len]=‘#‘;    if(str[ch]==‘a‘)    scaner();else error();    E();    printf("\n正確!\n");    strcpy(str,"");     } void scaner(){ch++;} void E(){    E();    T();} void X(){    } void T(){if(str[ch]==‘+‘||str[ch]==‘-‘||(str[ch]==‘*‘||str[ch]==‘/‘)    {        ch++;        T();        F();    }   else error();}   void F(){   if (str[x]==‘(‘)    {             ch++;        E();        if(str[x]==‘)‘)        {           F();        }        else    }    else if((str[x]!=‘;‘)error(); } } void error(){printf("\n錯誤!\n");}

  

 

  1. 運行結果及分析

一般必須配運行結果,結果是否符合預期及其分析。

   (需根據實際,截取有代表性的測試例子)

 

 

 

 

 

 

 

四、 實驗總結

 

心得體會,實驗過程的痛點問題及其解決的方法。

 

 

 

 

 

 

遞迴下降剖析器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.