Пример #1
0
        /// <summary>
        /// Creates a new symbol or gives a reference to a symbol that is
        /// determined by the type of the symbol record in the file content.
        /// </summary>
        /// <param name="symbolRecord"></param>
        /// <returns></returns>
        public static Symbol CreateSymbol(SymbolRecord symbolRecord)
        {
            Symbol symbol;

            switch (symbolRecord.Kind)
            {
            case 0:
                symbol = new SymbolNonterminal(symbolRecord.Index, symbolRecord.Name);
                break;

            case 1:
                symbol = new SymbolTerminal(symbolRecord.Index, symbolRecord.Name);
                break;

            case 2:
                symbol = new SymbolWhiteSpace(symbolRecord.Index);
                break;

            case 3:
                symbol = SymbolCollection.EOF;
                break;

            case 4:
                symbol = new SymbolCommentStart(symbolRecord.Index);
                break;

            case 5:
                symbol = new SymbolCommentEnd(symbolRecord.Index);
                break;

            case 6:
                symbol = new SymbolCommentLine(symbolRecord.Index);
                break;

            case 7:
                symbol = SymbolCollection.ERROR;
                break;

            default:
                // this sort of symbol should never be here
                symbol = new SymbolError(-1);
                break;
            }
            return(symbol);
        }
Пример #2
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);
        }
Пример #3
0
		/// <summary>
		/// Creates a new symbol or gives a reference to a symbol that is
		/// determined by the type of the symbol record in the file content.
		/// </summary>
		/// <param name="symbolRecord"></param>
		/// <returns></returns>
		static public Symbol CreateSymbol(SymbolRecord symbolRecord)
		{
			Symbol symbol;
			switch (symbolRecord.Kind)
			{
				case 0:
					symbol = new SymbolNonterminal(symbolRecord.Index,symbolRecord.Name);
					break;
				case 1:
					symbol = new SymbolTerminal(symbolRecord.Index,symbolRecord.Name);
					break;
				case 2:
					symbol = new SymbolWhiteSpace(symbolRecord.Index);
					break;
				case 3:
					symbol = SymbolCollection.EOF;
					break;
				case 4:
					symbol = new SymbolCommentStart(symbolRecord.Index);
					break;
				case 5:
					symbol = new SymbolCommentEnd(symbolRecord.Index);
					break;
				case 6:
					symbol = new SymbolCommentLine(symbolRecord.Index);
					break;
				case 7:
					symbol = SymbolCollection.ERROR;
					break;
				default:
					// this sort of symbol should never be here
					symbol = new SymbolError(-1);
					break;
			}
			return symbol;
		}
Пример #4
0
 /// <summary>
 /// Creates a new rule.
 /// </summary>
 /// <param name="id">Id of this rule.</param>
 /// <param name="lhs">Left hand side. The other symbols can be reduced to
 /// this symbol.</param>
 /// <param name="rhs">The right hand side. The symbols that can be reduced.</param>
 public Rule(int id, SymbolNonterminal lhs, Symbol[] rhs)
 {
     this.id = id;
     this.lhs = lhs;
     this.rhs = rhs;
 }
 public GotoEventArgs(SymbolNonterminal symbol, State newState)
 {
     this.symbol   = symbol;
     this.newState = newState;
 }
Пример #6
0
 public GotoEventArgs(SymbolNonterminal symbol, State newState)
 {
     this.symbol = symbol;
     this.newState = newState;
 }
Пример #7
0
 /// <summary>
 /// Creates a new rule.
 /// </summary>
 /// <param name="id">Id of this rule.</param>
 /// <param name="lhs">Left hand side. The other symbols can be reduced to
 /// this symbol.</param>
 /// <param name="rhs">The right hand side. The symbols that can be reduced.</param>
 public Rule(int id, SymbolNonterminal lhs, Symbol[] rhs)
 {
     this.id  = id;
     this.lhs = lhs;
     this.rhs = rhs;
 }