Hi, PROCEDURE M.P(); (*procedure*) PROCEDURE M.P; (*command*) Actually () really matters sometimes MODULE M; PROCEDURE P1(): REAL; PROCEDURE P2(x: REAL); M.P2( P1() ) While P1 on its own refers to procedure pointer. m: Methods; m.do := P1; Read a bit on `Compiler construction', formalism and context free allows for simple compiler coding from EBNF. Oberon-07 has a few exceptions to free context, if I got the idea right? -- Tomas Kral <thomas.kral@email.cz>
Hello Tomas, Am 16.06.2020 um 09:36 schrieb Tomas Kral:
Read a bit on `Compiler construction', formalism and context free allows for simple compiler coding from EBNF.
Oberon-07 has a few exceptions to free context, if I got the idea right?
From my head, I cannot think of a case why Oberon is not LL(k), but
I believe that Oberon-07 (at least the EBNF in the book) can be parsed with a context-free parser, and I think the actual ORP implementation is even LL(k) [or even LL(1)?] In general, Oberon-07 is not LL(1), since I can think of at least one case where the parse tree cannot be constructed without a larger lookahead: While parsing a type guard a(B).c when parser is at the "B" (which can even be M.B when qualified by a module), the parser can not yet tell whether "a" is a procedure variable and "B" is its argument or "a" is a record variable and "B" is a type. With a finite lookahead the compiler can see the "." and therefore disambiguate the situation. ORP does not have the problem as it will check the type of "a" during parsing, and if it is a record type or pointer type it can be parsed as a type guard: https://schierlm.github.io/OberonXref/ProjectOberon2013/ORP.html#L_150 probably somebody else has a good example. Regards, Michael
Michael
and I think the actual ORP implementation is even LL(k) [or even LL(1)?]
It depends how we define an "LL(1) implementation". Generally, ORP has only ONE variable "sym" that represents the symbol just read. And all IFs are based on this ONE symbol. As it is only ONE symbol (and not an array of k symbols) you could say, ORP is coded as LL(1). There are however cases where this "sym" is temporarily stored for later use: In term(), SimpleExpression() and expression0(). You always store the operator symbol, parse the second operand and generate the correct operation based on the stored symbol afterwards. One could say, it's just a code optimization: At the time we read the symbol "ORS.times", we principally know that is a multiplication. So one lookahead is fine. But as the code generation is later, we store the operator. In theory, you could copy the whole code several times and call the correct ORG.RealOp(ORS.times, x, y), ORG.IntRel(ORS.eql, x, y) in the end, instead of storing the symbol in "op" or "rel" and simply calling ORG.RealOp(op, x, y), ORG.IntRel(rel, x, y) afterwards. But I actually don't know whether this ORP code is really an LL(k) case or still is an "LL(1) implementation with temporary symbol storage". br Jörg
participants (3)
-
Jörg -
Michael Schierl -
Tomas Kral