public void dumpLR_DFA(State startState, string grammarFile, string inputFile, int compilerType) { if (startState != null && compilerType == 1 && inputFile != null && grammarFile != null) { LRdot dfaOut = new LRdot(startState, grammarFile); } else { throw new Exception("User Error, did not specify the use of an LR Compiler.\nattempted to output a LR_DFA without a LR(0) Start State!!"); } }
public void dumpLR_DFA() { if (startState != null) { LRdot dfaOut = new LRdot(startState, this.grammarFile); } else { throw new Exception("User Error, did not specify the use of an LR Compiler.\nattempted to output a LR_DFA without a LR(0) Start State!!"); } }
public GLR(Dictionary <string, Production> prodDict, string firstProduction, Dictionary <string, HashSet <string> > follow, List <Token> t, ref List <Dictionary <string, List <Tuple <string, int, string> > > > parseTable, ref TreeNode productionTreeRoot, ref State startState, bool computeTree) { productionDict = prodDict; Follows = follow; tokens = t; //create Start State states = new List <State>(); startState = new State(0); LR0Item start = new LR0Item("S'", new List <string> { firstProduction }, 0); parseTable = new List <Dictionary <string, List <Tuple <string, int, string> > > >(); seen = new Dictionary <HashSet <LR0Item>, State>(new EQ()); Stack <State> todo = new Stack <State>(); startState.Items.Add(start); computeClosure(startState.Items); states.Add(startState); seen.Add(startState.Items, startState); todo.Push(startState); while (todo.Count > 0) { State Q = todo.Pop(); Dictionary <string, HashSet <LR0Item> > transitions = computeTransitions(Q); addStates(Q, transitions, seen, todo); } printSeenMap(seen); computeGLRTable(ref parseTable); printGLRTable(parseTable); printTokens(t); LRdot dot = new LRdot(startState, "gFile.dot"); if (computeTree) { GLR_Parse(parseTable, ref productionTreeRoot); } }
//LR(0) stuff private void LR_Grammar_Proc() { //create Start State states = new List <State>(); startState = new State(); LR0Item start = new LR0Item("S'", new List <string> { "S" }, 0); Dictionary <HashSet <LR0Item>, State> seen = new Dictionary <HashSet <LR0Item>, State>(new EQ()); Stack <State> todo = new Stack <State>(); startState.Items.Add(start); computeClosure(startState.Items); states.Add(startState); seen.Add(startState.Items, startState); todo.Push(startState); while (todo.Count > 0) { State Q = todo.Pop(); Dictionary <string, HashSet <LR0Item> > transitions = computeTransitions(Q); addStates(Q, transitions, seen, todo); } computeSLRTable(); printSeenMap(seen); printLRTable(); LRdot dot = new LRdot(startState, grammarFile); if (this.inputFile != null) { SLR_Parse(); } }