Exemplo n.º 1
0
        public static ParsingTable Create()
        {
            var parsingTable = new ParsingTable(Symbol.Expr, Symbol.End);

            parsingTable.AddRule(R1, Symbol.Expr, Symbol.OpenBracket, Symbol.Identifier);
            parsingTable.AddRule(R2, Symbol.SimpleExprTail, Symbol.Plus);
            parsingTable.AddRule(R3, Symbol.SimpleExprTail, Symbol.End, Symbol.CloseBracket);
            parsingTable.AddRule(R4, Symbol.Term, Symbol.OpenBracket, Symbol.Identifier);
            parsingTable.AddRule(R5, Symbol.TermTail, Symbol.Times);
            parsingTable.AddRule(R6, Symbol.TermTail, Symbol.Plus, Symbol.End, Symbol.CloseBracket);
            parsingTable.AddRule(R7, Symbol.Factor, Symbol.OpenBracket);
            parsingTable.AddRule(R8, Symbol.Factor, Symbol.Identifier);

            return(parsingTable);
        }
        public static ParsingTable Create()
        {
            var parsingTable = new ParsingTable(Symbol.Program, Symbol.End);

            parsingTable.AddRule(R1, Symbol.Program, Symbol.Identifier);
            parsingTable.AddRule(R2, Symbol.DefTail, Symbol.Identifier);
            parsingTable.AddRule(R3, Symbol.DefTail, Symbol.End);
            parsingTable.AddRule(R4, Symbol.Def, Symbol.Identifier);
            parsingTable.AddRule(R5, Symbol.Formals, Symbol.CloseBracket);
            parsingTable.AddRule(R6, Symbol.Formals, Symbol.Identifier);
            parsingTable.AddRule(R7, Symbol.NonEmptyFormals, Symbol.Identifier);
            parsingTable.AddRule(R8, Symbol.FormalTail, Symbol.Comma);
            parsingTable.AddRule(R9, Symbol.FormalTail, Symbol.CloseBracket);
            parsingTable.AddRule(R10, Symbol.Formal, Symbol.Identifier);
            parsingTable.AddRule(R11, Symbol.Type, Symbol.IntegerType);
            parsingTable.AddRule(R12, Symbol.Type, Symbol.BooleanType);

            return(parsingTable);
        }
Exemplo n.º 3
0
        public static ParsingTable Create()
        {
            var parsingTable = new ParsingTable(Symbol.Program, Symbol.End);

            parsingTable.AddRule(R1, Symbol.Program, Symbol.Identifier);
            parsingTable.AddRule(R2, Symbol.DefTail, Symbol.Identifier);
            parsingTable.AddRule(R3, Symbol.DefTail, Symbol.End);
            parsingTable.AddRule(R4, Symbol.Def, Symbol.Identifier);
            parsingTable.AddRule(R5, Symbol.Formals, Symbol.CloseBracket);
            parsingTable.AddRule(R6, Symbol.Formals, Symbol.Identifier);
            parsingTable.AddRule(R7, Symbol.NonEmptyFormals, Symbol.Identifier);
            parsingTable.AddRule(R8, Symbol.FormalTail, Symbol.Comma);
            parsingTable.AddRule(R9, Symbol.FormalTail, Symbol.CloseBracket);
            parsingTable.AddRule(R10, Symbol.Formal, Symbol.Identifier);
            parsingTable.AddRule(R11, Symbol.Body, Symbol.PrintKeyword);
            parsingTable.AddRule(R12, Symbol.Body, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R13, Symbol.Type, Symbol.IntegerType);
            parsingTable.AddRule(R14, Symbol.Type, Symbol.BooleanType);
            parsingTable.AddRule(R15, Symbol.Expr, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R16, Symbol.SimpleExprTail, Symbol.LessThan);
            parsingTable.AddRule(R17, Symbol.SimpleExprTail, Symbol.Equality);
            parsingTable.AddRule(R18, Symbol.SimpleExprTail, Symbol.Identifier, Symbol.End, Symbol.Then, Symbol.Else, Symbol.CloseBracket, Symbol.And, Symbol.Times, Symbol.Divide, Symbol.Or, Symbol.Plus, Symbol.Minus, Symbol.Comma);
            parsingTable.AddRule(R19, Symbol.SimpleExpr, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R20, Symbol.TermTail, Symbol.Or);
            parsingTable.AddRule(R21, Symbol.TermTail, Symbol.Plus);
            parsingTable.AddRule(R22, Symbol.TermTail, Symbol.Minus);
            parsingTable.AddRule(R23, Symbol.TermTail, Symbol.Identifier, Symbol.End, Symbol.Then, Symbol.Else, Symbol.CloseBracket, Symbol.And, Symbol.Times, Symbol.Divide, Symbol.LessThan, Symbol.Equality, Symbol.Comma);
            parsingTable.AddRule(R24, Symbol.Term, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R25, Symbol.FactorTail, Symbol.And);
            parsingTable.AddRule(R26, Symbol.FactorTail, Symbol.Times);
            parsingTable.AddRule(R27, Symbol.FactorTail, Symbol.Divide);
            parsingTable.AddRule(R28, Symbol.FactorTail, Symbol.Identifier, Symbol.End, Symbol.Then, Symbol.Else, Symbol.CloseBracket, Symbol.Or, Symbol.Plus, Symbol.Minus, Symbol.LessThan, Symbol.Equality, Symbol.Comma);
            parsingTable.AddRule(R29, Symbol.Factor, Symbol.If);
            parsingTable.AddRule(R30, Symbol.Factor, Symbol.Not);
            parsingTable.AddRule(R31, Symbol.Factor, Symbol.Identifier);
            parsingTable.AddRule(R32, Symbol.Factor, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse);
            parsingTable.AddRule(R33, Symbol.Factor, Symbol.Minus);
            parsingTable.AddRule(R34, Symbol.Factor, Symbol.OpenBracket);
            parsingTable.AddRule(R35, Symbol.Func, Symbol.Identifier);
            parsingTable.AddRule(R36, Symbol.FuncTail, Symbol.OpenBracket);
            parsingTable.AddRule(R37, Symbol.FuncTail, Symbol.Identifier, Symbol.End, Symbol.Then, Symbol.Else, Symbol.CloseBracket, Symbol.And, Symbol.Times, Symbol.Divide, Symbol.Or, Symbol.Plus, Symbol.Minus, Symbol.LessThan, Symbol.Equality, Symbol.Comma);
            parsingTable.AddRule(R38, Symbol.Actuals, Symbol.CloseBracket);
            parsingTable.AddRule(R39, Symbol.Actuals, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R40, Symbol.NonEmptyActuals, Symbol.If, Symbol.Not, Symbol.Identifier, Symbol.IntegerLiteral, Symbol.BooleanTrue, Symbol.BooleanFalse, Symbol.Minus, Symbol.OpenBracket);
            parsingTable.AddRule(R41, Symbol.ActualsTail, Symbol.Comma);
            parsingTable.AddRule(R42, Symbol.ActualsTail, Symbol.CloseBracket);
            parsingTable.AddRule(R43, Symbol.Literal, Symbol.IntegerLiteral);
            parsingTable.AddRule(R44, Symbol.Literal, Symbol.BooleanTrue);
            parsingTable.AddRule(R45, Symbol.Literal, Symbol.BooleanFalse);
            parsingTable.AddRule(R46, Symbol.Print, Symbol.PrintKeyword);

            return(parsingTable);
        }