A quick text search for the word "assoc" in Niklaus Wirth's "Compiler
Construction" reveals:
In Section 5.2: "Evaluation Rules" (on p. 27) it says:
> exp(v0) = term(v1) | v0 := v1
> exp(v1) "+" term(v2) | v0 := v1 + v2
> exp(v1) "-" term(v2). v0 := v1 - v2
> term(v0) = factor(v1) | v0 := v1
> term(v1) "*" factor(v2) | v0 := v1 * v2
> term(v1) "/" factor(v2). v0 := v1 / v2
> factor(v0) = number(v1) | v0 := v1
> "(" exp(v1) ")". v0 := v1
Otherwise, it's presumably easy to change (the flexibility of this would be
interesting to consider in relation to your tool/formalism).
Cheers,
/Claus.
***
--
Claus Brabrand, Ph.D.
Associate Professor
IT University of Copenhagen (ITU)
Email: ((( brab...@itu.dk )))
WWW: ((( http://www.itu.dk/people/brabrand/ )))
-Eric
The answer to the original question is not clear in the book, but with some poking around in the code I think we can conclude that binary operators are left associative.
Finding an answer is complicated by the fact that the Oberon-0 parser calls the code generator during the parse; no AST is built. My reasoning is as follows. Consider the parsing routine for terms:
PROCEDURE term(VAR x: OSG.Item);
VAR y: OSG.Item; op: INTEGER;
BEGIN
factor(x);
WHILE (sym >= OSS.times) & (sym <= OSS.and) DO
op := sym;
OSS.Get(sym);
IF op = OSS.and THEN OSG.Op1(op, x) END ;
factor(y); OSG.Op2(op, x, y)
END
END term;
This parses the left and right sides of a *, DIV, MOD, or & as factors, then immediately calls the code generator with the operator and the two operands. OSG.Op2 produces the instruction for this operation. (The code generation for & is more complex, since short-circuit evaluation is used.) Thus, you can see that evaluation proceeds left to right for all operators at this precedence level, since the code for a * b in a * b * c is generated even before the c has been parsed. Similar reasoning seems to apply for the other binary operators.
Tony