private void buildtable int flag = 0; table = new Dictionaryint Liststring; forint i=0;istatesCount; i++ 对每个状态经过终结符的情况进行判断 Liststring strings = new Liststring; foreac
This function builds the parsing table for a given LR(0) automaton.
First, it initializes an empty dictionary called "table" to store the table entries.
Then, for each state in the automaton, it examines each terminal symbol in the grammar. If there is a transition from the current state on that symbol, it adds the action to shift to the state specified by the transition to the corresponding entry in the table. If there is no transition on that symbol, it adds an empty string to the table entry.
Next, for each nonterminal symbol in the grammar, it examines whether there is a transition from the current state on that symbol. If there is, it adds the state to transition to the corresponding entry in the table. If there is no transition on that symbol, it adds an empty string to the table entry.
Finally, it adds the completed table entry for the current state to the "table" dictionary using the state index as the key.
The resulting table can be used to parse input strings according to the LR(0) grammar
原文地址: http://www.cveoy.top/t/topic/g8IM 著作权归作者所有。请勿转载和采集!