多檔案組織詞法分析

2021-07-24 15:25:25 字數 2633 閱讀 7948

如果你還在為多檔案組織的重複定義煩惱時,就來這裡看看吧。

main.cpp

#include"analyse.h"

#include#includeusing namespace std;

string sentence;

int main()

analyse.h

#ifndef analyse_h_included

#define analyse_h_included

/*author: jzf

date:2016-11-02

description:provide functions to lexical analysis;

*/#include#include#include#include#includeusing namespace std;

extern string sentence;

extern char c;

extern char word[10];

extern char word2[10];

extern int i, k;

static int j;

bool judge_keyword(char word[10]);

bool judge_constant(char word[10]);

bool judge_identifiers(char word[10]);

bool judge_operator(char word[10]);

bool judge_delimiter(char c);

void getsym(string sentence);

#endif // analyse_h_included

lexical.cpp

#include "analyse.h"

#include#includeusing namespace std;

char c;

char word[10];

char word2[10];

int i, k;

bool judge_keyword(char word[10])//判斷是否為關鍵字

else if (strcmp(word, "if") == 0)

else if (strcmp(word, "then") == 0)

else if (strcmp(word, "while") == 0)

else if (strcmp(word, "do") == 0)

else if (strcmp(word, "end") == 0)

else

return true;

}bool judge_constant(char word[10])//判斷是否為常量

if (word[j] == '.')//判斷是否為小數

}word2[k] = '\0';

cout << "(11," << word2 << ")";

return true;

}else

return false;

}bool judge_identifiers(char word[10])//判斷是否為識別符號

word2[k] = '\0';

cout << "(10," << word2 << ")";

return true;

}else

return false;

}bool judge_operator(char word[10])//判斷是否為運算子

else if (c == '-')

else if (c == '*')

else if (c == '/')

else if (c == ':')

else

cout << "(17,:)";

}else if (c == '<')

else if (word[j] == '=')

else

cout << "(20,<)";

j++;

}else if (c == '>')

else

cout << "(23,>)";

}else if (c == '=')

else

return true;

}bool judge_delimiter(char c)//判斷是否為界符

else if (c == '(')

else if (c == ')')

else

return true;

}void getsym(string sentence)//得到語句

//判斷是否為關鍵字

else

//判斷是否為常量

else if (judge_identifiers(word)){}//判斷是否為識別符號

else if (judge_operator(word)){}//判斷是否為運算子

else if (judge_delimiter(c)){}//判斷是否為界符}}

j = 0;//單詞初始化

} }}

程式的多檔案組織

ifndef j h included define j h included class void setb double y void setc double z double geta void 置三邊的值,注意要能成三角形 double getb void double getc void ...

程式的多檔案組織

專案3 程式的多檔案組織 利用多檔案組織,重新實現專案2。其中,整個專案包括3個檔案 注意,將3個set函式和3個get函式設計成內建成員函式,其他函式不作為內建函式 main函式 include include include include h using namespace std int m...

4 2 利用多檔案組織專案

報告 2 實驗目的 利用多檔案組織專案 實驗內容 對任務及求解方法的描述部分 輸入描述 問題描述 程式輸出 問題分析 演算法設計 主檔案 main.cpp,用於定義main 函式 include include mytime.h using namespace std int main void t...