Esempio n. 1
0
        private StateCollection CreateParserStates(CGTContent content)
        {
            rules = CreateRules(content);

            StateCollection states = new StateCollection();
            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = new State(record.Index);
                states.Add(state);
            }

            foreach (LALRStateRecord record in content.LALRStateTable)
            {
                State state = states[record.Index];
                foreach (ActionSubRecord subRecord in record.ActionSubRecords)
                {
                    Action action =
                        ActionFactory.CreateAction(subRecord,
                                                   states,
                                                   symbols,
                                                   rules);
                    state.Actions.Add(action);
                }

            }
            return states;
        }
Esempio n. 2
0
 private void Reset()
 {
     stream = null;
     structure = null;
     content = null;
     dfaStates = null;
     parserStates = null;
     symbols = null;
     rules = null;
 }
Esempio n. 3
0
        private RuleCollection CreateRules(CGTContent content)
        {
            RuleCollection rules = new RuleCollection();
            foreach (RuleRecord ruleRecord in content.RuleTable)
            {
                SymbolNonterminal lhs = symbols[ruleRecord.Nonterminal] as SymbolNonterminal;
                //todo: exception handling?
                Symbol[] rhs = new Symbol[ruleRecord.Symbols.Count];
                for (int i = 0; i< rhs.Length; i++)
                {
                    rhs[i] = symbols[ruleRecord.Symbols[i]];
                }

                Rule rule = new Rule(ruleRecord.Index,lhs,rhs);
                rules.Add(rule);
            }
            return rules;
        }