詞法分析程式

2022-06-02 06:12:14 字數 677 閱讀 5985

詞法分析程式的功能:通過使用者輸入的關鍵字及其他保留字元,輸出它本身及它的種別碼

符號與種別碼對照表如下

單詞符號

種別碼單詞符號

種別碼begin

ifthen

while

doend

l(l|d)*

dd*

用文法描述詞法規則:

《字母》->a/b/c.../z

《數字》->1/2/3/4/5/6/7/8/9

《識別符號》->sum.....

《關鍵字》->begin/if/then/while/do/end

《運算子》->+,-,*,/,:,:=,,>,>=,=

《界符》->;|(|)|[|]|

已完成的**如下:

#include#include#includechar word[6][5]=;

char word2[18][3]=;

int words(char ch[5]);

int signs(char ch[3]);

main()

int words(char ch[5])

if(ch>='a'&&ch<='z')

}}int signs(char ch[3])

if(ch>='0'&&ch<='9')}}

詞法分析程式

上課沒聽啥,一邊看書,一邊做的。基本上,老師的要求是實現了,能把乙個句子 也可以是一整個程式,但還不完善,由於時間急,很多情況來不及考慮了 中的單詞項分析出它是保留字,還是識別符號,運算子等等。開始是在控制台下做得,也比較純正 lex.h ifndef lex h define lex h incl...

詞法分析程式

include include char scanin 300 scanout 300 extern int testscan char scanin 300 scanout 300 file fin,fout 指向輸入輸出檔案的指標 int main include include include...

詞法分析程式

include include void fenxi char c,char b void word char a void number char a int i 定義全域性變數i int s 1 用來記錄是否存在非法字元 main printf n void number char a 對數字字...