示例#1
0
        private void Parse(string dec, DecGrammar g)
        {
            List <ProductionEntry> entries = new List <ProductionEntry>();

            int index = 0;

            while (index < dec.Length)
            {
                bool isToken = true;

                dec.ReadWhile(ref index, c => " \t".Contains(c));
                if (index >= dec.Length)
                {
                    break;
                }
                string entry = dec.ReadUntil(ref index, c => " \t".Contains(c) ||
                                             ((index > 0 && dec[index - 1] == '{') && (index == 1 || (" \t".Contains(dec[index - 2]) && !"\'\\".Contains(dec[index - 2])))));

                if (HasAction)
                {
                    HasAction = false;
                    var marker = new MarkerNonTerminal(g, "{" + _actionString + "}");

                    entries.Add(marker);
                    g.AddNonTerminal(marker);
                }

                parse :  switch (entry[0])
                {
                case '\\' :
                    entry = entry.Substring(1);
                    break;

                case '\'':
                    entry   = entry[1..^ 1];
示例#2
0
        public Production(NonTerminal lhs, DecGrammar g, string dec)
        {
            Lhs = lhs;

            string[] split = dec.Split(" ");
            if (split.Length == 0 || dec == "ε")
            {
                IsEmpty = true;
                Rhs     = new ProductionEntry[] { };
            }
            else
            {
                Parse(dec, g);
            }
        }
示例#3
0
 public NonTerminal(DecGrammar g, string tag, params string[] productions) : base('/' + tag)
 {
     _grammar          = g;
     Tag               = tag;
     productionStrings = productions;
 }
示例#4
0
 public MarkerNonTerminal(DecGrammar g, string actionString)
     : base(g, GrammarConstants.MarkerChar + actionString, actionString)
 {
 }