예제 #1
0
        public static Lexer CreateLexer()
        {
            LexerBuilder builder = new LexerBuilder();

            builder.Add("P", "C");
            builder.Add("C", "/", "IDN", "AS").Act(children => { var l = new List <IASTNode>()
                                                                 {
                                                                     children[0]
                                                                 }; l.AddRange(children[1].Children); return(new Command(l.ToArray())); });
            builder.Add("AS", "AS", "A").Act(children => new ASTList(new List <IASTNode>(children[0].Children)
            {
                children[1]
            }));
            builder.Add("AS");
            builder.Add("A", "IDN", ":", "E");
            builder.Add("A", "E");
            //builder.Add("P", "E");
            builder.Add("E", "E", "+", "T").Act(children => new Calc(children));
            builder.Add("E", "E", "-", "T").Act(children => new Calc(children));
            builder.Add("E", "T");
            builder.Add("T", "T", "*", "F").Act(children => new Calc(children));
            builder.Add("T", "T", "/", "F").Act(children => new Calc(children));
            builder.Add("T", "T", "%", "F").Act(children => new Calc(children));
            builder.Add("T", "F");
            builder.Add("F", "(", "E", ")").Act(children => children[1]);
            builder.Add("F", "IDN");
            builder.Add("F", "DIG");
            builder.Add("F", "DEC");

            Lexer lexer = builder.Build("P");

            builder.PrintBuilder();
            builder.PrintTable();
            //builder.PrintLexerCode();

            return(lexer);
        }