         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
				NO_APP
		.Ltext0:
				.section	.rodata
		.LC0:
		 		.byte	40
		 		.string	"Imp77 precedence and associativity test."
		 		.zero	214
		.LC11:
		 		.byte	85
		 		.string	"a * b // c * d is left associative and with equal precedence, i.e. ((a * b) // c) * d"
		 		.zero	169
		.LC7:
		 		.byte	37
		 		.string	"This grammar would support the above:"
		 		.zero	217
		.LC12:
		 		.byte	33
		 		.string	"P<expr> = <term-op-list> <term> ;"
		 		.zero	221
		.LC13:
		 		.byte	46
		 		.string	"P<term-op-list> = <term-op> <term-op-list> | ;"
		 		.zero	208
		.LC14:
		 		.byte	26
		 		.string	"P<term-op> = <term> <op> ;"
		 		.zero	228
		.LC20:
		 		.byte	51
		 		.string	"p ^^ q ^^ r is left associative, i.e. (p ^^ q) ^^ r"
		 		.zero	203
		.LC21:
		 		.byte	34
		 		.string	"P<expr> = <term-exp-list> <term> ;"
		 		.zero	220
		.LC22:
		 		.byte	49
		 		.string	"P<term-exp-list> = <term-exp> <term-exp-list> | ;"
		 		.zero	205
		.LC23:
		 		.byte	27
		 		.string	"P<term-exp> = <term> \"^^\" ;"
		 		.zero	227
				.align	2
				.globl	main
		main:
		.LFB185:
		.LVL0:
		 		link.w %fp,#-5632
		 		movem.l #15928,-(%sp)
    2
		 		move.l 12(%fp),-(%sp)
		 		move.l 8(%fp),-(%sp)
		 		jsr _imp_initialise
		.LVL1:
		.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)
		 		move.l %fp,%d3
		.LVL2:
		 		add.l #-256,%d3
		.LVL3:
		 		move.l #256,%d2
		 		move.l %d2,-(%sp)
		 		pea .LC0
		 		move.l %d3,-(%sp)
		 		lea memcpy,%a2
		 		jsr (%a2)
		.LVL4:
		 		move.l %fp,%d5
		.LVL5:
		 		add.l #-5632,%d5
		.LVL6:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL7:
		 		move.l %fp,%d4
		.LVL8:
		 		add.l #-2816,%d4
		.LVL9:
		 		lea (32,%sp),%sp
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL10:
		.LBE171:
		.LBB172:
		.LBB173:
		 		lea (-256,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL11:
		 		lea (12,%sp),%sp
		 		lea _imp_printstring,%a4
		 		jsr (%a4)
		.LVL12:
		.LBE173:
		.LBE172:
		.LBB174:
		.LBB175:
		 		lea (268,%sp),%sp
		 		pea 2.w
		 		jsr _imp_newlines
		.LVL13:
		.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
		 		move.l %d2,-(%sp)
		 		pea .LC11
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL14:
		 		add.l #256,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL15:
		 		add.l #1280,%d4
		.LVL16:
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL17:
		.LBE176:
		.LBB177:
		.LBB178:
		 		lea (-216,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL18:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL19:
		.LBE178:
		.LBE177:
		.LBB179:
		.LBB180:
		 		add.l %d2,%sp
		 		lea _imp_newline,%a3
		 		jsr (%a3)
		.LVL20:
		.LBE180:
		.LBE179:
		.LBB181:
		.LBB182:
		 		jsr (%a3)
		.LVL21:
		.LBE182:
		.LBE181:
		.LBB183:
   94     newline
   95     print string("This grammar would support the above:"); newline
		 		move.l #.LC7,%d4
		.LVL22:
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL23:
		 		move.l %fp,%d6
		.LVL24:
		 		add.l #-5120,%d6
		.LVL25:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d6,-(%sp)
		 		jsr (%a2)
		.LVL26:
		 		add.l #3584,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d6,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL27:
		.LBE183:
		.LBB184:
		.LBB185:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL28:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL29:
		.LBE185:
		.LBE184:
		.LBB186:
		.LBB187:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL30:
		.LBE187:
		.LBE186:
		.LBB188:
		.LBB189:
		 		jsr (%a3)
		.LVL31:
		.LBE189:
		.LBE188:
		.LBB190:
   96     newline
   97     print string("P<expr> = <term-op-list> <term> ;"); newline
		 		move.l %d2,-(%sp)
		 		pea .LC12
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL32:
		 		add.l #256,%d6
		.LVL33:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d6,-(%sp)
		 		jsr (%a2)
		.LVL34:
		 		add.l #-256,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d6,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL35:
		.LBE190:
		.LBB191:
		.LBB192:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL36:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL37:
		.LBE192:
		.LBE191:
		.LBB193:
		.LBB194:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL38:
		.LBE194:
		.LBE193:
		.LBB195:
   98     print string("P<term-op-list> = <term-op> <term-op-list> | ;"); newline
		 		move.l %d2,-(%sp)
		 		pea .LC13
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL39:
		 		add.l #256,%d6
		.LVL40:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d6,-(%sp)
		 		jsr (%a2)
		.LVL41:
		 		add.l #-256,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d6,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL42:
		.LBE195:
		.LBB196:
		.LBB197:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL43:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL44:
		.LBE197:
		.LBE196:
		.LBB198:
		.LBB199:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL45:
		.LBE199:
		.LBE198:
		.LBB200:
   99     print string("P<term-op> = <term> <op> ;"); newline
		 		move.l %d2,-(%sp)
		 		pea .LC14
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL46:
		 		add.l #256,%d6
		.LVL47:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d6,-(%sp)
		 		jsr (%a2)
		.LVL48:
		 		add.l #-256,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d6,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL49:
		.LBE200:
		.LBB201:
		.LBB202:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL50:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL51:
		.LBE202:
		.LBE201:
		.LBB203:
		.LBB204:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL52:
		.LDL3:
		.LDL4:
		.LBE204:
		.LBE203:
		.LBB205:
		.LBB206:
		 		jsr (%a3)
		.LVL53:
		.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
		 		move.l %d2,-(%sp)
		 		pea .LC20
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL54:
		 		add.l #-1536,%d5
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d5,-(%sp)
		 		jsr (%a2)
		.LVL55:
		 		move.l %d2,-(%sp)
		 		move.l %d5,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL56:
		.LBE207:
		.LBB208:
		.LBB209:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL57:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL58:
		.LBE209:
		.LBE208:
		.LBB210:
		.LBB211:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL59:
		.LBE211:
		.LBE210:
		.LBB212:
		.LBB213:
		 		jsr (%a3)
		.LVL60:
		.LBE213:
		.LBE212:
		.LBB214:
  121     newline
  122     print string("This grammar would support the above:"); newline
		 		add.l #-256,%d3
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL61:
		 		move.l %fp,%d4
		.LVL62:
		 		add.l #-3840,%d4
		.LVL63:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL64:
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL65:
		.LBE214:
		.LBB215:
		.LBB216:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL66:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL67:
		.LBE216:
		.LBE215:
		.LBB217:
		.LBB218:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL68:
		.LBE218:
		.LBE217:
		.LBB219:
		.LBB220:
		 		jsr (%a3)
		.LVL69:
		.LBE220:
		.LBE219:
		.LBB221:
  123     newline
  124     print string("P<expr> = <term-exp-list> <term> ;"); newline
		 		add.l #-256,%d3
		 		move.l %d2,-(%sp)
		 		pea .LC21
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL70:
		 		add.l #256,%d4
		.LVL71:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL72:
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL73:
		.LBE221:
		.LBB222:
		.LBB223:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL74:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL75:
		.LBE223:
		.LBE222:
		.LBB224:
		.LBB225:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL76:
		.LBE225:
		.LBE224:
		.LBB226:
  125     print string("P<term-exp-list> = <term-exp> <term-exp-list> | ;"); newline
		 		add.l #-256,%d3
		 		move.l %d2,-(%sp)
		 		pea .LC22
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL77:
		 		add.l #256,%d4
		.LVL78:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL79:
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL80:
		.LBE226:
		.LBB227:
		.LBB228:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL81:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL82:
		.LBE228:
		.LBE227:
		.LBB229:
		.LBB230:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL83:
		.LBE230:
		.LBE229:
		.LBB231:
  126     print string("P<term-exp> = <term> ""^^"" ;"); newline
		 		add.l #-256,%d3
		 		move.l %d2,-(%sp)
		 		pea .LC23
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL84:
		 		add.l #256,%d4
		.LVL85:
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d4,-(%sp)
		 		jsr (%a2)
		.LVL86:
		 		move.l %d2,-(%sp)
		 		move.l %d4,-(%sp)
		 		move.l %d3,-(%sp)
		 		jsr (%a2)
		.LVL87:
		.LBE231:
		.LBB232:
		.LBB233:
		 		lea (-220,%sp),%sp
		 		move.l %sp,%d0
		 		move.l %d2,-(%sp)
		 		move.l %d3,-(%sp)
		 		move.l %d0,-(%sp)
		 		jsr (%a2)
		.LVL88:
		 		lea (12,%sp),%sp
		 		jsr (%a4)
		.LVL89:
		.LBE233:
		.LBE232:
		.LBB234:
		.LBB235:
		 		add.l %d2,%sp
		 		jsr (%a3)
		.LVL90:
		.LDL6:
		.LBE235:
		.LBE234:
		.LBB236:
		.LBB237:
		 		jsr (%a3)
		.LVL91:
		.LBE237:
		.LBE236:
		.LBB238:
		.LBB239:
		 		clr.l -(%sp)
		 		jsr exit
		.LVL92:
		.LBE239:
		.LBE238:
		.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
