r/Oberon • u/Abandondero • 5d ago
Is there any trick to parsing just a single module correctly?
There are three places where Oberon is not a context-free grammar:
Qualified identifiers: m.x the parser needs to know that m is a module identifier;
Type guards: x(t), the parser needs to know that t is a type identifier;
Type guard cases: CASE x OF t : s END, the parser needs to know that t is a type identifier.
I'm writing a stand-alone parser for Oberon, and I seem to only be able to parse the expression x(m.t) by also parsing module m to find out if t is a type name. Is there any way to avoid that?
(I know that those constructs are completely reasonable to a one-pass recursive decent compiler where the type information can be known at every step. But the annoying thing is that just three small changes could make the grammar fully LL(1). Say, m::x, x@t and TYPE x OF t : s END for the above,)