Example #1
0
        private GrammarBuilder Productions(ParseTree.ProductionList prodList)
        {
            var ruleId = 0;

            TypeTable.Write("types.txt");

            foreach (var prod in prodList)
            {
                symbols.TryGetValue(prod.Name.Value, out var id, out var isTerminal);

                foreach (var definition in prod.Definitions)
                {
                    var terms         = definition.Build(this);
                    var reduceContext = new ReduceContext(
                        TypeTable,
                        terms,
                        definition.Action,
                        noAction,
                        id);
                    var reduction  = terms.Reduction(reduceContext);
                    var production = new Production(
                        prod.Name,
                        id,
                        ruleId++,
                        terms,
                        reduction);
                    productions.Add(production);
                }
            }
            return(this);
        }
Example #2
0
        public static IReduceExpr[] CreateArgs(this ITerminals terminals, ReduceContext context)
        {
            var result = new IReduceExpr[terminals.Length];

            for (var i = 0; i < result.Length; i++)
            {
                result[i] = terminals[i].Reduce(context);
            }
            return(result);
        }
Example #3
0
 public IReduceExpr Reduce(ReduceContext context) =>
 context.TryFindType(Name, out var type) ?
 new ReduceCastedArgExpr(0, type !) :
Example #4
0
 public abstract IReduceExpr Reduce(ReduceContext context);
Example #5
0
 public override IReduceExpr Reduce(ReduceContext context) =>
 new ReduceNullExpr();