Exemplo n.º 1
0
        public ICollection <Term> CalculateTerms(IEnumerable <NonTerminalToken> nonTerminals, IEnumerable <string> lines)
        {
            var terms = new List <Term>();

            foreach (var line in lines)
            {
                var caller = SeparateForPremise(line).FirstOrDefault()?.Trim().ToNonTerminal();
                var called = SeparateForPremise(line).LastOrDefault()?.Trim() ?? "";

                var productions = called.GetProductions();
                var p           = new List <Production>();

                foreach (var production in productions)
                {
                    var lex    = new TopDownTokenization(nonTerminals, production);
                    var tokens = lex.GetAllTokens();

                    p.Add(new Production(tokens));
                }

                terms.Add(new Term(caller, p));
            }

            Terms = terms;
            return(terms);
        }
Exemplo n.º 2
0
 public TmCodeGenerator(TopDownParser parser, string input)
 {
     _parser        = parser;
     _input         = input;
     Tokenization   = new TopDownTokenization(_parser.NonTerminals, input);
     Instructions   = new List <string>();
     Registradores  = new int[8];
     VarDictionary  = new Dictionary <Token, int>();
     Stack          = new Stack <Token>();
     IfBackpack     = new Stack <IfBackpackItem>();
     RepeatBackpack = new Stack <RepeatBackpack>();
 }
Exemplo n.º 3
0
 public CmsCodeGenerator(TopDownParser parser, string input)
 {
     _parser                 = parser;
     _input                  = input;
     Codes                   = new List <CmsCode>();
     Tokenization            = new TopDownTokenization(_parser.NonTerminals, input);
     VariableArea            = new Dictionary <string, CmsCode>();
     StopReference           = new CmsCode(0X0000);
     TokenStack              = new Stack <Token>();
     AttributionTokenStack   = new Stack <Token>();
     JFCodeReferenceStack    = new Stack <CmsCodeReference>();
     StartWhileCodeReference = new Stack <CmsCodeReference>();
     RepeatReferenceStack    = new Stack <CmsCode>();
 }