         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
				.section	".text"
		.Ltext0:
				.section	".rodata"
		.LC0:
				.byte	40
				.asciz	"Imp77 precedence and associativity test."
				.skip	214
		.LC11:
				.byte	85
				.asciz	"a * b // c * d is left associative and with equal precedence, i.e. ((a * b) // c) * d"
				.skip	169
		.LC7:
				.byte	37
				.asciz	"This grammar would support the above:"
				.skip	217
		.LC12:
				.byte	33
				.asciz	"P<expr> = <term-op-list> <term> ;"
				.skip	221
		.LC13:
				.byte	46
				.asciz	"P<term-op-list> = <term-op> <term-op-list> | ;"
				.skip	208
		.LC14:
				.byte	26
				.asciz	"P<term-op> = <term> <op> ;"
				.skip	228
		.LC20:
				.byte	51
				.asciz	"p ^^ q ^^ r is left associative, i.e. (p ^^ q) ^^ r"
				.skip	203
		.LC21:
				.byte	34
				.asciz	"P<expr> = <term-exp-list> <term> ;"
				.skip	220
		.LC22:
				.byte	49
				.asciz	"P<term-exp-list> = <term-exp> <term-exp-list> | ;"
				.skip	205
		.LC23:
				.byte	27
				.asciz	"P<term-exp> = <term> \"^^\" ;"
				.skip	227
				.section	".text"
				.align 4
				.global main
				.proc	04
		main:
		.LFB185:
				.register	%g7, #ignore
		.LVL0:
				save	%sp, -4096, %sp
		.LVL1:
				add	%sp, -1984, %sp
				ldx	[%g7+40], %g1
				stx	%g1, [%fp+2039]
				mov	0, %g1
    2
				mov	%i1, %o1
				call	_imp_initialise, 0
				 mov	%i0, %o0
		.LVL2:
		.LBB171:
    3 !
    4 ! Precedence of operators
    5 !
    6 ! Highest: 1. \ (complement, unary not)
    7 !          2. \, \\, <<, >>
    8 !          3. *, /, //, &
    9 ! Lowest:  4. +, - (unary and binary), !, !!
   10 !
   11 ! In general, sub-expressions with operators of equal precedence are evaluated from left to right.
   12 !
   13 ! The one exception to the left-hand precedence rule is that consecutive
   14 ! exponentiations are evaluated from right to left; thus A**B**C is
   15 ! evaluated as A**(B**C), not as (A**B)**C.  (Imp80 documentation)
   16
   17 ! Arithmetic operators:
   18
   19 ! |...| modulus              also: !...!  (deprecated some time ago)
   20
   21 ! !  inclusive or
   22 ! !! exclusive or
   23 ! &  and
   24
   25 ! \  real exponentiation     also:  ^  (Imp77)  or  **    (ERCC compilers)
   26 ! \\ integer exponentiation  also:  ^^ (Imp77)  or  ****
   27
   28 ! *  multiply
   29 ! /  real division
   30 ! // integer division
   31
   32 ! << left shift
   33 ! >> right shift
   34
   35 ! +  plus
   36 ! -  minus
   37
   38 ! +  unary +
   39 ! -  unary -
   40 ! \  unary not               also ~ (can be *displayed* as: ¬ (&not;))
   41
   42 ! .  string concatenation
   43
   44 ! Comparison operators:
   45 ! =  eq
   46 ! #  not equals              also \= and <> (Imp80 documentation)
   47 ! == address equals
   48 ! ## address not equals      also \==
   49 ! -> string resolution       (a difficult to classify hybrid of a comparison and an assignment operator)
   50 ! <= less than or equals
   51 ! <  less than
   52 ! >= greater than or equals
   53 ! >
   54
   55 ! Assignment operators:
   56 ! =  assignment
   57 ! == pointer assignment
   58 ! <- jam transfer
   59 ! -> string resolution
   60
   61 ! Data structure operators:
   62 ! _  record field
   63 ! () array indexing
   64 ! [] pointer increment       (a Hamish extension in 68000 Imp only)
   65
   66 ! Other:
   67 ! @  may be considered an operator in %real literals, usually handled by a BIP.
   68
   69
   70   %const %integer a = 19, b = 17, c = 5, d = 3
   71   %integer x = a * b // c * d
   72   print string("Imp77 precedence and associativity test."); newlines(2)
				mov	256, %o2
				sethi	%hi(.LC0), %o1
				or	%o1, %lo(.LC0), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL3:
				sethi	%hi(5120), %i4
				xor	%i4, -520, %i5
				add	%fp, 2047, %g1
				add	%g1, %i5, %i5
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL4:
				mov	256, %o2
				mov	%i5, %o1
				call	memcpy, 0
				 add	%fp, -777, %o0
		.LVL5:
		.LBE171:
		.LBB172:
		.LBB173:
				xor	%i4, -784, %i5
				add	%fp, 2047, %g1
				add	%g1, %i5, %i5
				mov	256, %o2
				add	%fp, -777, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL6:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL7:
		.LBE173:
		.LBE172:
		.LBB174:
		.LBB175:
				call	_imp_newlines, 0
				 mov	2, %o0
		.LVL8:
		.LDL1:
		.LDL2:
		.LBE175:
		.LBE174:
		.LBB176:
   73   %if x = 21 %start
   74     print string("In a * b // c * d, '*' has higher priority than '/'."); newline
   75     print string("A second test with '/' will be needed to determine associativity:"); newline
   76     x = a // c // d
   77     %if x = 1 %start
   78       print string("a // c // d is right associative, i.e. a // (b // c)"); newline
   79     %else %if x = 19
   80       print string("a // c // d is left associative, i.e. (a // b) // c"); newline
   81     %else
   82       print string("a // c // d is something weird!  I give up."); newline
   83     %finish
   84   %else %if x = 19
   85     print string("a * b // c * d is right associative and with equal precedence, i.e. a * (b // (c * d))"); newline
   86     newline
   87     print string("This grammar would support the above:"); newline
   88     newline
   89     print string("P<expr> = <term> <op-term-list> ;"); newline
   90     print string("P<op-term-list> = <op-term> <op-term-list> | ;"); newline
   91     print string("P<op-term> = <op> <term> ;"); newline
   92   %else %if x = 192
   93     print string("a * b // c * d is left associative and with equal precedence, i.e. ((a * b) // c) * d"); newline
				mov	256, %o2
				sethi	%hi(.LC11), %o1
				or	%o1, %lo(.LC11), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL9:
				xor	%i4, -264, %i3
				add	%fp, 2047, %g1
				add	%g1, %i3, %i3
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i3, %o0
		.LVL10:
				mov	256, %o2
				mov	%i3, %o1
				call	memcpy, 0
				 add	%fp, 503, %o0
		.LVL11:
		.LBE176:
		.LBB177:
		.LBB178:
				mov	256, %o2
				add	%fp, 503, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL12:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL13:
		.LBE178:
		.LBE177:
		.LBB179:
		.LBB180:
				call	_imp_newline, 0
				 sethi	%hi(.LC7), %i3
		.LVL14:
		.LBE180:
		.LBE179:
		.LBB181:
		.LBB182:
				call	_imp_newline, 0
				 or	%i3, %lo(.LC7), %i3
		.LVL15:
		.LBE182:
		.LBE181:
		.LBB183:
   94     newline
   95     print string("This grammar would support the above:"); newline
				mov	256, %o2
				mov	%i3, %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL16:
				xor	%i4, -8, %i4
				add	%fp, 2047, %g1
				add	%g1, %i4, %i4
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i4, %o0
		.LVL17:
				mov	256, %o2
				mov	%i4, %o1
				call	memcpy, 0
				 add	%fp, 247, %o0
		.LVL18:
		.LBE183:
		.LBB184:
		.LBB185:
				mov	256, %o2
				add	%fp, 247, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL19:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL20:
		.LBE185:
		.LBE184:
		.LBB186:
		.LBB187:
				call	_imp_newline, 0
				 sethi	%hi(4096), %i4
		.LVL21:
		.LBE187:
		.LBE186:
		.LBB188:
		.LBB189:
				call	_imp_newline, 0
				 xor	%i4, -776, %i2
		.LVL22:
		.LBE189:
		.LBE188:
		.LBB190:
   96     newline
   97     print string("P<expr> = <term-op-list> <term> ;"); newline
				mov	256, %o2
				sethi	%hi(.LC12), %o1
				or	%o1, %lo(.LC12), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL23:
				add	%fp, 2047, %g1
				add	%g1, %i2, %i2
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i2, %o0
		.LVL24:
				mov	256, %o2
				mov	%i2, %o1
				call	memcpy, 0
				 add	%fp, -9, %o0
		.LVL25:
		.LBE190:
		.LBB191:
		.LBB192:
				mov	256, %o2
				add	%fp, -9, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL26:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL27:
		.LBE192:
		.LBE191:
		.LBB193:
		.LBB194:
				call	_imp_newline, 0
				 xor	%i4, -520, %i2
		.LVL28:
		.LBE194:
		.LBE193:
		.LBB195:
   98     print string("P<term-op-list> = <term-op> <term-op-list> | ;"); newline
				mov	256, %o2
				sethi	%hi(.LC13), %o1
				or	%o1, %lo(.LC13), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL29:
				add	%fp, 2047, %g1
				add	%g1, %i2, %i2
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i2, %o0
		.LVL30:
				mov	256, %o2
				mov	%i2, %o1
				call	memcpy, 0
				 add	%fp, -265, %o0
		.LVL31:
		.LBE195:
		.LBB196:
		.LBB197:
				mov	256, %o2
				add	%fp, -265, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL32:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL33:
		.LBE197:
		.LBE196:
		.LBB198:
		.LBB199:
				call	_imp_newline, 0
				 xor	%i4, -264, %i2
		.LVL34:
		.LBE199:
		.LBE198:
		.LBB200:
   99     print string("P<term-op> = <term> <op> ;"); newline
				mov	256, %o2
				sethi	%hi(.LC14), %o1
				or	%o1, %lo(.LC14), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL35:
				add	%fp, 2047, %g1
				add	%g1, %i2, %i2
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i2, %o0
		.LVL36:
				mov	256, %o2
				mov	%i2, %o1
				call	memcpy, 0
				 add	%fp, -521, %o0
		.LVL37:
		.LBE200:
		.LBB201:
		.LBB202:
				mov	256, %o2
				add	%fp, -521, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL38:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL39:
		.LBE202:
		.LBE201:
		.LBB203:
		.LBB204:
				call	_imp_newline, 0
				 xor	%i4, -8, %i4
		.LVL40:
		.LDL3:
		.LDL4:
		.LBE204:
		.LBE203:
		.LBB205:
		.LBB206:
				call	_imp_newline, 0
				 nop
		.LVL41:
		.LDL5:
		.LBE206:
		.LBE205:
		.LBB207:
  100   %else
  101     print string("a * b // c * d uses some weird non-standard combination of precedence and associativity!"); newline
  102   %finish
  103   newline
  104
  105
  106   %const %integer p = 4, q = 3, r = 2
  107   %integer y
  108
  109   y = p ^^ q ^^ r
  110
  111   %if y = 262144 %start
  112     print string("p ^^ q ^^ r is right associative, i.e. p ^^ (q ^^ r)"); newline
  113     newline
  114     print string("This grammar would support the above:"); newline
  115     newline
  116     print string("P<expr> = <term> <exp-term-list> ;"); newline
  117     print string("P<exp-term-list> = <exp-term> <exp-term-list> | ;"); newline
  118     print string("P<exp-term> = ""^^"" <term> ;"); newline
  119   %else %if y = 4096
  120     print string("p ^^ q ^^ r is left associative, i.e. (p ^^ q) ^^ r"); newline
				mov	256, %o2
				sethi	%hi(.LC20), %o1
				or	%o1, %lo(.LC20), %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL42:
				add	%fp, 2047, %g1
				add	%g1, %i4, %i4
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i4, %o0
		.LVL43:
				mov	256, %o2
				mov	%i4, %o1
				call	memcpy, 0
				 add	%fp, 1783, %o0
		.LVL44:
		.LBE207:
		.LBB208:
		.LBB209:
				mov	256, %o2
				add	%fp, 1783, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL45:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL46:
		.LBE209:
		.LBE208:
		.LBB210:
		.LBB211:
				call	_imp_newline, 0
				 nop
		.LVL47:
		.LBE211:
		.LBE210:
		.LBB212:
		.LBB213:
				call	_imp_newline, 0
				 nop
		.LVL48:
		.LBE213:
		.LBE212:
		.LBB214:
  121     newline
  122     print string("This grammar would support the above:"); newline
				mov	256, %o2
				mov	%i3, %o1
				call	memcpy, 0
				 add	%fp, 1527, %o0
		.LVL49:
				mov	256, %o2
				add	%fp, 1527, %o1
				call	memcpy, 0
				 add	%fp, -1801, %o0
		.LVL50:
				mov	256, %o2
				add	%fp, -1801, %o1
				call	memcpy, 0
				 add	%fp, 1527, %o0
		.LVL51:
		.LBE214:
		.LBB215:
		.LBB216:
				mov	256, %o2
				add	%fp, 1527, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL52:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL53:
		.LBE216:
		.LBE215:
		.LBB217:
		.LBB218:
				call	_imp_newline, 0
				 nop
		.LVL54:
		.LBE218:
		.LBE217:
		.LBB219:
		.LBB220:
				call	_imp_newline, 0
				 nop
		.LVL55:
		.LBE220:
		.LBE219:
		.LBB221:
  123     newline
  124     print string("P<expr> = <term-exp-list> <term> ;"); newline
				mov	256, %o2
				sethi	%hi(.LC21), %o1
				or	%o1, %lo(.LC21), %o1
				call	memcpy, 0
				 add	%fp, 1271, %o0
		.LVL56:
				mov	256, %o2
				add	%fp, 1271, %o1
				call	memcpy, 0
				 add	%fp, -1545, %o0
		.LVL57:
				mov	256, %o2
				add	%fp, -1545, %o1
				call	memcpy, 0
				 add	%fp, 1271, %o0
		.LVL58:
		.LBE221:
		.LBB222:
		.LBB223:
				mov	256, %o2
				add	%fp, 1271, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL59:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL60:
		.LBE223:
		.LBE222:
		.LBB224:
		.LBB225:
				call	_imp_newline, 0
				 nop
		.LVL61:
		.LBE225:
		.LBE224:
		.LBB226:
  125     print string("P<term-exp-list> = <term-exp> <term-exp-list> | ;"); newline
				mov	256, %o2
				sethi	%hi(.LC22), %o1
				or	%o1, %lo(.LC22), %o1
				call	memcpy, 0
				 add	%fp, 1015, %o0
		.LVL62:
				mov	256, %o2
				add	%fp, 1015, %o1
				call	memcpy, 0
				 add	%fp, -1289, %o0
		.LVL63:
				mov	256, %o2
				add	%fp, -1289, %o1
				call	memcpy, 0
				 add	%fp, 1015, %o0
		.LVL64:
		.LBE226:
		.LBB227:
		.LBB228:
				mov	256, %o2
				add	%fp, 1015, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL65:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL66:
		.LBE228:
		.LBE227:
		.LBB229:
		.LBB230:
				call	_imp_newline, 0
				 nop
		.LVL67:
		.LBE230:
		.LBE229:
		.LBB231:
  126     print string("P<term-exp> = <term> ""^^"" ;"); newline
				mov	256, %o2
				sethi	%hi(.LC23), %o1
				or	%o1, %lo(.LC23), %o1
				call	memcpy, 0
				 add	%fp, 759, %o0
		.LVL68:
				mov	256, %o2
				add	%fp, 759, %o1
				call	memcpy, 0
				 add	%fp, -1033, %o0
		.LVL69:
				mov	256, %o2
				add	%fp, -1033, %o1
				call	memcpy, 0
				 add	%fp, 759, %o0
		.LVL70:
		.LBE231:
		.LBB232:
		.LBB233:
				mov	256, %o2
				add	%fp, 759, %o1
				call	memcpy, 0
				 mov	%i5, %o0
		.LVL71:
				call	_imp_printstring, 0
				 mov	%i5, %o0
		.LVL72:
		.LBE233:
		.LBE232:
		.LBB234:
		.LBB235:
				call	_imp_newline, 0
				 nop
		.LVL73:
		.LDL6:
		.LBE235:
		.LBE234:
		.LBB236:
		.LBB237:
				call	_imp_newline, 0
				 nop
		.LVL74:
		.LBE237:
		.LBE236:
		.LBB238:
		.LBB239:
				call	exit, 0
				 mov	0, %o0
		.LVL75:
		.LBE239:
		.LBE238:
				nop
		.LFE185:
		.Letext0:
  127   %else
  128     print string("p ^^ q ^^ r is something weird! ("); write(y, 0); print string(") - I give up."); newline
  129   %finish
  130   newline
  131
  132 ! The remaining issue to be checked is how left/right associativity interact when the precedence is the same,
  133 ! which is only the case for exponentiation and shifts together, eg
  134 !
  135 ! a << b << c ^^ d ^^ e   or   a ^^ b ^^ c >> d >> e
  136 !
  137
  138 %endofprogram
   89 Statements compiled
