把这个代码中的goto语句换一种方式表达#include stdioh#include stdlibh#include stringh#define MAX_STACK 100#define MAX_INPUT 100 SLR分析表int action_table126 = 1 0 0 4 0 0 0 6 0 0 0 -1 0 -2 7 0 -2 -2 0 -4 -4 0
将goto语句换成if语句:
// 分析表查找函数 int get_action(int state, char symbol) { int col = 0; switch (symbol) { case 'i': col = 0; break; case '+': col = 1; break; case '*': col = 2; break; case '(': col = 3; break; case ')': col = 4; break; case '#': col = 5; break; default: break; } int action = action_table[state][col]; if (action >= 0) { return action; } else { return -action; } }
int get_goto(int state, char symbol) { int col = 0; switch (symbol) { case 'E': col = 0; break; case 'T': col = 1; break; case 'F': col = 2; break; default: break; } int new_state = goto_table[state][col]; return new_state;
原文地址: https://www.cveoy.top/t/topic/fJ7n 著作权归作者所有。请勿转载和采集!