コード例 #1
0
ファイル: Parser.cs プロジェクト: dw4dev/Phalanger
		private void ParseRhs(NonTerminal lhs)
		{
			Production production = new Production(lhs);
			int num = 0;
			while (this.token == GrammarToken.Symbol || this.token == GrammarToken.Literal || this.token == GrammarToken.Action || this.token == GrammarToken.Prec)
			{
				GrammarToken grammarToken = this.token;
				switch (grammarToken)
				{
				case GrammarToken.Symbol:
					if (this.grammar.terminals.ContainsKey(this.scanner.yylval))
					{
						production.rhs.Add(this.grammar.terminals[this.scanner.yylval]);
					}
					else
					{
						production.rhs.Add(this.grammar.LookupNonTerminal(this.scanner.yylval));
					}
					this.Advance();
					num++;
					break;
				case GrammarToken.Literal:
					production.rhs.Add(this.grammar.LookupTerminal(this.token, this.scanner.yylval));
					this.Advance();
					num++;
					break;
				case GrammarToken.Action:
				{
					SemanticAction semanticAction = new SemanticAction(production, this.tokenStartLine, num, this.scanner.yylval);
					this.Advance();
					if (this.token == GrammarToken.Divider || this.token == GrammarToken.SemiColon || this.token == GrammarToken.Prec)
					{
						production.semanticAction = semanticAction;
					}
					else
					{
						Grammar arg_1BA_0 = this.grammar;
						string arg_1B5_0 = "@";
						int num2 = ++this.grammar.NumActions;
						NonTerminal nonTerminal = arg_1BA_0.LookupNonTerminal(arg_1B5_0 + num2.ToString());
						Production production2 = new Production(nonTerminal);
						production2.semanticAction = semanticAction;
						this.grammar.AddProduction(production2);
						production.rhs.Add(nonTerminal);
					}
					num++;
					break;
				}
				default:
					if (grammarToken == GrammarToken.Prec)
					{
						this.Advance();
						if (this.token == GrammarToken.Symbol)
						{
							production.prec = this.grammar.LookupTerminal(this.token, this.scanner.yylval).prec;
							this.Advance();
						}
						else
						{
							this.scanner.ReportError("Expected symbol after %prec", new object[0]);
						}
					}
					break;
				}
			}
			this.grammar.AddProduction(production);
			Precedence.Calculate(production);
		}
コード例 #2
0
ファイル: Parser.cs プロジェクト: xmaxmex/Phalanger
        private void ParseRhs(NonTerminal lhs)
        {
            Production production = new Production(lhs);
            int        num        = 0;

            while (this.token == GrammarToken.Symbol || this.token == GrammarToken.Literal || this.token == GrammarToken.Action || this.token == GrammarToken.Prec)
            {
                GrammarToken grammarToken = this.token;
                switch (grammarToken)
                {
                case GrammarToken.Symbol:
                    if (this.grammar.terminals.ContainsKey(this.scanner.yylval))
                    {
                        production.rhs.Add(this.grammar.terminals[this.scanner.yylval]);
                    }
                    else
                    {
                        production.rhs.Add(this.grammar.LookupNonTerminal(this.scanner.yylval));
                    }
                    this.Advance();
                    num++;
                    break;

                case GrammarToken.Literal:
                    production.rhs.Add(this.grammar.LookupTerminal(this.token, this.scanner.yylval));
                    this.Advance();
                    num++;
                    break;

                case GrammarToken.Action:
                {
                    SemanticAction semanticAction = new SemanticAction(production, this.tokenStartLine, num, this.scanner.yylval);
                    this.Advance();
                    if (this.token == GrammarToken.Divider || this.token == GrammarToken.SemiColon || this.token == GrammarToken.Prec)
                    {
                        production.semanticAction = semanticAction;
                    }
                    else
                    {
                        Grammar     arg_1BA_0   = this.grammar;
                        string      arg_1B5_0   = "@";
                        int         num2        = ++this.grammar.NumActions;
                        NonTerminal nonTerminal = arg_1BA_0.LookupNonTerminal(arg_1B5_0 + num2.ToString());
                        Production  production2 = new Production(nonTerminal);
                        production2.semanticAction = semanticAction;
                        this.grammar.AddProduction(production2);
                        production.rhs.Add(nonTerminal);
                    }
                    num++;
                    break;
                }

                default:
                    if (grammarToken == GrammarToken.Prec)
                    {
                        this.Advance();
                        if (this.token == GrammarToken.Symbol)
                        {
                            production.prec = this.grammar.LookupTerminal(this.token, this.scanner.yylval).prec;
                            this.Advance();
                        }
                        else
                        {
                            this.scanner.ReportError("Expected symbol after %prec", new object[0]);
                        }
                    }
                    break;
                }
            }
            this.grammar.AddProduction(production);
            Precedence.Calculate(production);
        }
コード例 #3
0
        private void ParseRhs(NonTerminal lhs)
        {
            Production production = new Production(lhs);
            int        pos        = 0;

            while (token == GrammarToken.Symbol || token == GrammarToken.Literal ||
                   token == GrammarToken.Action || token == GrammarToken.Prec)
            {
                switch (token)
                {
                case GrammarToken.Literal:
                {
                    production.rhs.Add(grammar.LookupTerminal(token, scanner.yylval));
                    Advance();
                    pos++;
                    break;
                }

                case GrammarToken.Symbol:
                {
                    if (grammar.terminals.ContainsKey(scanner.yylval))
                    {
                        production.rhs.Add(grammar.terminals[scanner.yylval]);
                    }
                    else
                    {
                        production.rhs.Add(grammar.LookupNonTerminal(scanner.yylval));
                    }
                    Advance();
                    pos++;
                    break;
                }

                case GrammarToken.Prec:
                {
                    Advance();
                    if (token == GrammarToken.Symbol)
                    {
                        production.prec = grammar.LookupTerminal(token, scanner.yylval).prec;
                        Advance();
                    }
                    else
                    {
                        scanner.ReportError("Expected symbol after %prec");
                    }
                    break;
                }

                case GrammarToken.Action:
                {
                    SemanticAction semanticAction = new SemanticAction(production, pos, scanner.yylval);
                    Advance();

                    if (token == GrammarToken.Divider || token == GrammarToken.SemiColon || token == GrammarToken.Prec)                             // reduce action
                    {
                        production.semanticAction = semanticAction;
                    }
                    else
                    {
                        NonTerminal node           = grammar.LookupNonTerminal("@" + (++grammar.NumActions).ToString());
                        Production  nullProduction = new Production(node);
                        nullProduction.semanticAction = semanticAction;
                        grammar.AddProduction(nullProduction);
                        production.rhs.Add(node);
                    }
                    pos++;
                    break;
                }
                }
            }

            grammar.AddProduction(production);

            Precedence.Calculate(production);
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: gregorypilar/interlace
        private void ParseRhs(NonTerminal lhs)
        {
            Production production = new Production(lhs);
            int pos = 0;

            while (token == GrammarToken.Symbol || token == GrammarToken.Literal ||
                   token == GrammarToken.Action || token == GrammarToken.Prec)
            {
                switch (token)
                {
                    case GrammarToken.Literal:
                    {
                        production.rhs.Add(grammar.LookupTerminal(token, scanner.yylval));
                        Advance();
                        pos++;
                        break;
                    }
                    case GrammarToken.Symbol:
                    {
                        if (grammar.terminals.ContainsKey(scanner.yylval))
                            production.rhs.Add(grammar.terminals[scanner.yylval]);
                        else
                            production.rhs.Add(grammar.LookupNonTerminal(scanner.yylval));
                        Advance();
                        pos++;
                        break;
                    }
                    case GrammarToken.Prec:
                    {
                        Advance();
                        if (token == GrammarToken.Symbol)
                        {
                            production.prec = grammar.LookupTerminal(token, scanner.yylval).prec;
                            Advance();
                        }
                        else
                            scanner.ReportError("Expected symbol after %prec");
                        break;
                    }
                    case GrammarToken.Action:
                    {
                        SemanticAction semanticAction = new SemanticAction(production, pos, scanner.yylval);
                        Advance();

                        if (token == GrammarToken.Divider || token == GrammarToken.SemiColon || token == GrammarToken.Prec) // reduce action
                            production.semanticAction = semanticAction;
                        else
                        {
                            NonTerminal node = grammar.LookupNonTerminal("@" + (++grammar.NumActions).ToString());
                            Production nullProduction = new Production(node);
                            nullProduction.semanticAction = semanticAction;
                            grammar.AddProduction(nullProduction);
                            production.rhs.Add(node);
                        }
                        pos++;
                        break;
                    }
                }
            }

            grammar.AddProduction(production);

            Precedence.Calculate(production);
        }