Ejemplo n.º 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];
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
 public NonTerminal(DecGrammar g, string tag, params string[] productions) : base('/' + tag)
 {
     _grammar          = g;
     Tag               = tag;
     productionStrings = productions;
 }
Ejemplo n.º 4
0
 public MarkerNonTerminal(DecGrammar g, string actionString)
     : base(g, GrammarConstants.MarkerChar + actionString, actionString)
 {
 }