Exemplo n.º 1
0
        private static IEnumerable <Production> Terminals()
        {
            return(new List <Production> {
                new Production(
                    Nonterminal.Of("TerminalString"),
                    new Sentence {
                    Nonterminal.Of("FirstQuoteSymbol"),
                    Nonterminal.Of("FirstTerminalCharacterList1"),
                    Nonterminal.Of("FirstQuoteSymbol"),
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => Tuple.Create("'", ((List <string>)args[1].Payload).Select(x => Terminal.Of(x)).ToList()))
                })
                    ),
                new Production(
                    Nonterminal.Of("TerminalString"),
                    new Sentence {
                    Nonterminal.Of("SecondQuoteSymbol"),
                    Nonterminal.Of("SecondTerminalCharacterList1"),
                    Nonterminal.Of("SecondQuoteSymbol"),
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => Tuple.Create("\"", ((List <string>)args[1].Payload).Select(x => Terminal.Of(x)).ToList()))
                })
                    ),

                new Production("TerminalCharacterBasic", Nonterminal.Of("Letter")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("DecimalDigit")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("CommentlessTerminal")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("ConcatenateSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("DefiningSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("DefinitionSeparatorSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("EndCommentSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("EndGroupSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("EndOptionSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("EndRepeatSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("ExceptSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("RepetitionSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("SpecialSequenceSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("StartCommentSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("StartGroupSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("StartOptionSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("StartRepeatSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("TerminatorSymbol")),
                new Production("TerminalCharacterBasic", Nonterminal.Of("OtherCharacter")),

                new Production("FirstTerminalCharacter", Nonterminal.Of("TerminalCharacterBasic")),
                new Production("FirstTerminalCharacter", Nonterminal.Of("SpaceCharacter")),
                new Production("FirstTerminalCharacter", Nonterminal.Of("SecondQuoteSymbol")),

                new Production("SecondTerminalCharacter", Nonterminal.Of("TerminalCharacterBasic")),
                new Production("SecondTerminalCharacter", Nonterminal.Of("SpaceCharacter")),
                new Production("SecondTerminalCharacter", Nonterminal.Of("FirstQuoteSymbol")),
            }.Concat(
                       MakeList <string>("FirstTerminalCharacter", 1)
                       ).Concat(
                       MakeList <string>("SecondTerminalCharacter", 1)
                       ));
        }
Exemplo n.º 2
0
        private static IEnumerable <Production> SecondPart()
        {
            return(new List <Production> {
                new Production("TerminalCharacter", Nonterminal.Of("TerminalCharacterBasic")),
                new Production("TerminalCharacter", Nonterminal.Of("FirstQuoteSymbol")),
                new Production("TerminalCharacter", Nonterminal.Of("SecondQuoteSymbol")),
                new Production("TerminalCharacter", Nonterminal.Of("SpaceCharacter")),

                new Production("GapFreeSymbolTerminal", Nonterminal.Of("TerminalCharacterBasic")),
                // new Production("GapFreeSymbolTerminal", Nonterminal.Of("SpecialSequenceSymbol")),

                new Production(
                    Nonterminal.Of("GapFreeSymbol"),
                    new Sentence {
                    Nonterminal.Of("GapFreeSymbolTerminal")
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => new List <Terminal> {
                        Terminal.Of((string)args[0].Payload)
                    })
                })
                    ),
                new Production(
                    Nonterminal.Of("GapFreeSymbol"),
                    new Sentence {
                    Nonterminal.Of("TerminalString")
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => {
                        var tup = (Tuple <string, List <Terminal> >)args[0].Payload;
                        // TODO shouldn't mutate
                        var list = tup.Item2;
                        list.Insert(0, Terminal.Of(tup.Item1));
                        list.Add(Terminal.Of(tup.Item1));
                        return list;
                    })
                })
                    ),

                new Production("GapSeparator", Nonterminal.Of("SpaceCharacter")),
                new Production("GapSeparator", Nonterminal.Of("HorizontalTabulationCharacter")),
                new Production("GapSeparator", Nonterminal.Of("NewLine")),
                new Production("GapSeparator", Nonterminal.Of("CarriageReturn")),
                new Production("GapSeparator", Nonterminal.Of("VerticalTabulationCharacter")),
                new Production("GapSeparator", Nonterminal.Of("FormFeed")),

                // TODO
                new Production(
                    Nonterminal.Of("SyntaxLayout"),
                    new Sentence {
                    Nonterminal.Of("GapSeparatorList0"),
                    Nonterminal.Of("GapFreeSymbolWithOptionalGapSeparatorList1"),
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => ((List <List <Terminal> >)args[1].Payload).SelectMany(term => term).ToList())
                })
                    ),

                new Production(
                    Nonterminal.Of("GapFreeSymbolWithOptionalGapSeparator"),
                    new Sentence {
                    Nonterminal.Of("GapFreeSymbol"),
                    Nonterminal.Of("GapSeparatorList0"),
                },
                    1,
                    new Annotations(new List <IAnnotation> {
                    new ActionAnnotation(args => (List <Terminal>)args[0].Payload)
                })
                    ),
            }.Concat(
                       MakeList <object>("GapSeparator", 0)
                       ).Concat(
                       MakeList <List <Terminal> >("GapFreeSymbolWithOptionalGapSeparator", 1)
                       ));
        }
Exemplo n.º 3
0
        private static IEnumerable <Production> BasicSymbols()
        {
            return(new List <Production> {
                new Production("Integer", Nonterminal.Of("DecimalDigitList1")),

                new Production("ConcatenateSymbol", Terminal.Of(",")),
                new Production("DefiningSymbol", Terminal.Of("=")),
                new Production("DefinitionSeparatorSymbol", Terminal.Of("|")),
                new Production("DefinitionSeparatorSymbol", Terminal.Of("/")),
                new Production("DefinitionSeparatorSymbol", Terminal.Of("!")),
                new Production("EndCommentSymbol", Terminal.Of("*)")),
                new Production("EndGroupSymbol", Terminal.Of(")")),
                new Production("EndOptionSymbol", Terminal.Of("]")),
                new Production("EndOptionSymbol", Terminal.Of("/)")),
                new Production("EndRepeatSymbol", Terminal.Of("}")),
                new Production("EndRepeatSymbol", Terminal.Of(":)")),
                new Production("ExceptSymbol", Terminal.Of("-")),
                new Production("FirstQuoteSymbol", Terminal.Of("'")),
                new Production("RepetitionSymbol", Terminal.Of("*")),
                new Production("SecondQuoteSymbol", Terminal.Of("\"")),
                new Production("SpecialSequenceSymbol", Terminal.Of("?")),
                new Production("StartCommentSymbol", Terminal.Of("(*")),
                new Production("StartGroupSymbol", Terminal.Of("(")),
                new Production("StartOptionSymbol", Terminal.Of("[")),
                new Production("StartOptionSymbol", Terminal.Of("(/")),
                new Production("StartRepeatSymbol", Terminal.Of("{")),
                new Production("StartRepeatSymbol", Terminal.Of("(:")),
                new Production("TerminatorSymbol", Terminal.Of(";")),
                new Production("TerminatorSymbol", Terminal.Of(".")),

                new Production("SpaceCharacter", Terminal.Of(" ")),
                new Production("HorizontalTabulationCharacter", Terminal.Of("\t")),
                new Production("NewLine", Terminal.Of("\n")),
                new Production("CarriageReturn", Terminal.Of("\r")),
                //new Production("NewLine", Terminal.Of("\r\n")),
                new Production("VerticalTabulationCharacter", Terminal.Of("\v")),
                new Production("FormFeed", Terminal.Of("\f")),
            }.Concat(
                       ":+_%@&#$<>\\^`~".Select((x) => new Production("OtherCharacter", Terminal.Of(x.ToString())))
                       ).Concat(
                       MakeList <object>("DecimalDigit", 1)
                       ));
            // !, ., and / are defined elsewhere
            // including space seems like a bug
        }