예제 #1
0
        public override void PrefixAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
        {
            altTree     = GrammarAST.DupTree(altTree);
            rewriteTree = GrammarAST.DupTree(rewriteTree);

            StripSynPred(altTree);

            int nextPrec = Precedence(alt);
            // rewrite e to be e_[rec_arg]
            StringTemplate refST = recRuleTemplates.GetInstanceOf("recRuleRef");

            refST.SetAttribute("ruleName", ruleName);
            refST.SetAttribute("arg", nextPrec);
            altTree = ReplaceRuleRefs(altTree, refST.Render());
            string altText = Text(altTree);

            altText  = altText.Trim();
            altText += "{}"; // add empty alt to prevent pred hoisting

            StringTemplate nameST = recRuleTemplates.GetInstanceOf("recRuleName");

            nameST.SetAttribute("ruleName", ruleName);
            rewriteTree = ReplaceRuleRefs(rewriteTree, nameST.Render());
            string rewriteText = Text(rewriteTree);

            prefixAlts.Add(altText + (rewriteText != null ? " " + rewriteText : ""));
            //System.out.println("prefixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
        }
예제 #2
0
        public override void OtherAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
        {
            altTree     = GrammarAST.DupTree(altTree);
            rewriteTree = GrammarAST.DupTree(rewriteTree);
            StripSynPred(altTree);
            StripLeftRecursion(altTree);
            string altText = Text(altTree);

            string rewriteText = Text(rewriteTree);

            otherAlts.Add(altText + (rewriteText != null ? " " + rewriteText : ""));
            //System.out.println("otherAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
        }
예제 #3
0
        public override void SuffixAlt(GrammarAST altTree, GrammarAST rewriteTree, int alt)
        {
            altTree     = GrammarAST.DupTree(altTree);
            rewriteTree = GrammarAST.DupTree(rewriteTree);
            StripSynPred(altTree);
            StripLeftRecursion(altTree);
            StringTemplate nameST = recRuleTemplates.GetInstanceOf("recRuleName");

            nameST.SetAttribute("ruleName", ruleName);
            rewriteTree = ReplaceRuleRefs(rewriteTree, "$" + nameST.Render());
            string rewriteText = Text(rewriteTree);
            string altText     = Text(altTree);

            altText = altText.Trim();
            suffixAlts.Add(alt, altText + (rewriteText != null ? " " + rewriteText : ""));
            //		System.out.println("suffixAlt " + alt + ": " + altText + ", rewrite=" + rewriteText);
        }