?? parser.h
字號:
// ----------------------------- parser.h ---------------------------------
#include "..\\lextest\\scanner.h"
//--------------------------------- 語法分析器類中的類型定義
typedef double (* func_ptr)(double);
typedef struct tree_node // 語法樹節點類型
{ enum token_type op_code; // PLUS, FUNC, CONST_ID, ...
union
{ struct { tree_node *left, *right; } tag_op;
struct { tree_node *child; func_ptr math_func_ptr; } tag_func;
double tag_const;
double * tag_parameter;
} content;
} * tree_node_ptr;
//--------------------------------- 語法分析器類聲明
class parser_class {
protected:
double parameter; // 參數T的存儲空間
int line_color; // 線條顏色
token_rec token; // 記號
tree_node_ptr start_ptr, // 繪圖起點表達式的語法樹
end_ptr, // 繪圖終點表達式的語法樹
step_ptr, // 步長表達式的語法樹
x_ptr, // 點的橫坐標表達式的語法樹
y_ptr, // 點的橫坐標表達式的語法樹
angle_ptr; // 旋轉角度表達式的語法樹
scanner_class Scanner; // 詞法分析器對象
// --------------- 輔助函數
void fetch_token (); // 獲取記號
void match_token (enum token_type the_token); // 匹配記號
void syntax_error (int case_of); // 指出語法錯誤(調用error_msg)
void print_syntax_tree(tree_node *root, int indent); // 打印語法樹
tree_node_ptr make_tree_node(enum token_type opcode,...); // 構造語法樹
virtual void error_msg(int line, char *descrip, char *string); // 在Semantics中重置為窗口打印形式
// ---------------非終結符的遞歸子程序
void program();
void statement();
void color_statement();
void colors();
// 下述四個函數在Semantics_class中需重置,以實現語法制導翻譯
virtual void for_statement();
virtual void origin_statement();
virtual void rot_statement();
virtual void scale_statement();
tree_node_ptr expression();
tree_node_ptr term();
tree_node_ptr factor();
tree_node_ptr component();
tree_node_ptr atom();
public:
parser_class() // 對象聲明時需置初值
{
parameter = 0;
line_color= red_color;
start_ptr = NULL;
end_ptr = NULL;
step_ptr = NULL;
x_ptr = NULL;
y_ptr = NULL;
}
~parser_class() {}
void parser(char * file_name); // 語法分析器接口
private:
// 下述函數用于語法分析器的跟蹤調試, 在Semantics_class中需重置為不起作用
virtual void enter(char * x);
virtual void back(char * x);
virtual void call_match(char * x);
virtual void tree_trace(tree_node_ptr x);
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -