Hello,

I tested the theory in the previous message, and it's looking good. The
only change required is to add a special token rules named on
right-hand-sides to the results returned on FIRST set computations. The
bold part after the '|' here:

class RuleRef(Model):
    def _first(self, k, f):
        return f[self.name] *| {ref(self.name <http://self.name>)}*

After that,

def is_leftrec(rule):
   return ref(rule.name) in rule.LL_LOOKAHEAD()

Nullabillity is `() in exp.LL_LOOKAHEAD()`, and so on.

Would anyone be interested in confirming these results?

I'm interested because of the  the LL lookahead algorithm is simple enough
to implement on my ongoing projects. This is FIRST:

    def _calc_first_sets(self, k=1):
        f = defaultdict(set)
        f1 = None
        while f1 != f:
            f1 = copy(f)
            for rule in self.rules:
                f[rule.name] |= rule._first(k, f)

        # cache results
        for rule in self.rules:
            rule._firstset = f[rule.name]


Regards,



On Mon, Jun 10, 2019 at 5:20 PM Juancarlo Añez <apal...@gmail.com> wrote:

> Hello,
>
> When looking at the resolutions of PEG/leftre with IS_NULLABLE,
> IS_LEFTREC, it occured to me that the same could be solved, perhaps in a
> more algebraic way, by using LL FIRST/FOLLOW analysis with the modification
> of allowing RHS symbols in the sets.
>
> IS_NULLABLE(rule) == e in pFIRST(rule)
> IS_LEFTREC(rule). == rule inf pFIRST(rule)
>
> Something like that.
>
> Has anyone explored this approach.
>
> TIA, and Cheers,
>
> --
> Juancarlo *Añez*
>


-- 
Juancarlo *Añez*
_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to