         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
		.Ltext0:
				.align	1
				.global	main
				.thumb
				.thumb_func
		main:
		.LFB185:
				@ args = 0, pretend = 0, frame = 5640
				@ frame_needed = 0, uses_anonymous_args = 0
		.LVL0:
				push	{r4, r5, r6, r7, r8, r9, lr}
				sub	sp, sp, #5856
				sub	sp, sp, #28
				ldr	r3, .L4
		.LPIC0:
				add	r3, pc
				ldr	r2, .L4+4
				ldr	r3, [r3, r2]
				ldr	r3, [r3]
				add	r2, sp, #5856
				adds	r2, r2, #20
				str	r3, [r2]
    2
				bl	_imp_initialise(PLT)
		.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)
				ldr	r6, .L4+8
		.LPIC1:
				add	r6, pc
				mov	r4, #256
				mov	r2, r4
				mov	r1, r6
				add	r5, sp, #5600
				adds	r5, r5, #20
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL2:
				mov	r2, r4
				mov	r1, r5
				add	r7, sp, #244
				mov	r0, r7
				bl	memcpy(PLT)
		.LVL3:
				mov	r2, r4
				mov	r1, r7
				addw	r8, sp, #3060
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL4:
		.LBE171:
		.LBB172:
		.LBB173:
				movs	r7, #240
				mov	r2, r7
				addw	r1, sp, #3076
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL5:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL6:
		.LBE173:
		.LBE172:
		.LBB174:
		.LBB175:
				movs	r0, #2
				bl	_imp_newlines(PLT)
		.LVL7:
		.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	r2, r4
				adds	r1, r6, r4
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL8:
				mov	r2, r4
				mov	r1, r5
				add	r8, sp, #500
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL9:
				mov	r2, r4
				mov	r1, r8
				add	r8, sp, #4320
				add	r8, r8, #20
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL10:
		.LBE176:
		.LBB177:
		.LBB178:
				mov	r2, r7
				add	r1, sp, #4352
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL11:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL12:
		.LBE178:
		.LBE177:
		.LBB179:
		.LBB180:
				bl	_imp_newline(PLT)
		.LVL13:
		.LBE180:
		.LBE179:
		.LBB181:
		.LBB182:
				bl	_imp_newline(PLT)
		.LVL14:
		.LBE182:
		.LBE181:
		.LBB183:
   94     newline
   95     print string("This grammar would support the above:"); newline
				add	r9, r6, #512
				mov	r2, r4
				mov	r1, r9
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL15:
				mov	r2, r4
				mov	r1, r5
				add	r8, sp, #756
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL16:
				mov	r2, r4
				mov	r1, r8
				addw	r8, sp, #4084
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL17:
		.LBE183:
		.LBB184:
		.LBB185:
				mov	r2, r7
				add	r1, sp, #4096
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL18:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL19:
		.LBE185:
		.LBE184:
		.LBB186:
		.LBB187:
				bl	_imp_newline(PLT)
		.LVL20:
		.LBE187:
		.LBE186:
		.LBB188:
		.LBB189:
				bl	_imp_newline(PLT)
		.LVL21:
		.LBE189:
		.LBE188:
		.LBB190:
   96     newline
   97     print string("P<expr> = <term-op-list> <term> ;"); newline
				mov	r2, r4
				add	r1, r6, #768
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL22:
				mov	r2, r4
				mov	r1, r5
				add	r8, sp, #1012
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL23:
				mov	r2, r4
				mov	r1, r8
				addw	r8, sp, #3828
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL24:
		.LBE190:
		.LBB191:
		.LBB192:
				mov	r2, r7
				addw	r1, sp, #3844
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL25:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL26:
		.LBE192:
		.LBE191:
		.LBB193:
		.LBB194:
				bl	_imp_newline(PLT)
		.LVL27:
		.LBE194:
		.LBE193:
		.LBB195:
   98     print string("P<term-op-list> = <term-op> <term-op-list> | ;"); newline
				mov	r2, r4
				add	r1, r6, #1024
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL28:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #1268
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL29:
				mov	r2, r4
				mov	r1, r8
				addw	r8, sp, #3572
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL30:
		.LBE195:
		.LBB196:
		.LBB197:
				mov	r2, r7
				addw	r1, sp, #3588
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL31:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL32:
		.LBE197:
		.LBE196:
		.LBB198:
		.LBB199:
				bl	_imp_newline(PLT)
		.LVL33:
		.LBE199:
		.LBE198:
		.LBB200:
   99     print string("P<term-op> = <term> <op> ;"); newline
				mov	r2, r4
				add	r1, r6, #1280
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL34:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #1524
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL35:
				mov	r2, r4
				mov	r1, r8
				addw	r8, sp, #3316
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL36:
		.LBE200:
		.LBB201:
		.LBB202:
				mov	r2, r7
				addw	r1, sp, #3332
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL37:
				ldm	r8, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL38:
		.LBE202:
		.LBE201:
		.LBB203:
		.LBB204:
				bl	_imp_newline(PLT)
		.LVL39:
		.LDL3:
		.LDL4:
		.LBE204:
		.LBE203:
		.LBB205:
		.LBB206:
				bl	_imp_newline(PLT)
		.LVL40:
		.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	r2, r4
				add	r1, r6, #1536
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL41:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #1780
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL42:
				mov	r2, r4
				mov	r1, r8
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL43:
		.LBE207:
		.LBB208:
		.LBB209:
				mov	r2, r7
				add	r1, sp, #5632
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL44:
				ldm	r5, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL45:
		.LBE209:
		.LBE208:
		.LBB210:
		.LBB211:
				bl	_imp_newline(PLT)
		.LVL46:
		.LBE211:
		.LBE210:
		.LBB212:
		.LBB213:
				bl	_imp_newline(PLT)
		.LVL47:
		.LBE213:
		.LBE212:
		.LBB214:
  121     newline
  122     print string("This grammar would support the above:"); newline
				mov	r2, r4
				mov	r1, r9
				add	r5, sp, #5344
				adds	r5, r5, #20
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL48:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #2036
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL49:
				mov	r2, r4
				mov	r1, r8
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL50:
		.LBE214:
		.LBB215:
		.LBB216:
				mov	r2, r7
				add	r1, sp, #5376
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL51:
				ldm	r5, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL52:
		.LBE216:
		.LBE215:
		.LBB217:
		.LBB218:
				bl	_imp_newline(PLT)
		.LVL53:
		.LBE218:
		.LBE217:
		.LBB219:
		.LBB220:
				bl	_imp_newline(PLT)
		.LVL54:
		.LBE220:
		.LBE219:
		.LBB221:
  123     newline
  124     print string("P<expr> = <term-exp-list> <term> ;"); newline
				mov	r2, r4
				add	r1, r6, #1792
				add	r5, sp, #5088
				adds	r5, r5, #20
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL55:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #2292
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL56:
				mov	r2, r4
				mov	r1, r8
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL57:
		.LBE221:
		.LBB222:
		.LBB223:
				mov	r2, r7
				add	r1, sp, #5120
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL58:
				ldm	r5, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL59:
		.LBE223:
		.LBE222:
		.LBB224:
		.LBB225:
				bl	_imp_newline(PLT)
		.LVL60:
		.LBE225:
		.LBE224:
		.LBB226:
  125     print string("P<term-exp-list> = <term-exp> <term-exp-list> | ;"); newline
				mov	r2, r4
				add	r1, r6, #2048
				add	r5, sp, #4832
				adds	r5, r5, #20
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL61:
				mov	r2, r4
				mov	r1, r5
				addw	r8, sp, #2548
				mov	r0, r8
				bl	memcpy(PLT)
		.LVL62:
				mov	r2, r4
				mov	r1, r8
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL63:
		.LBE226:
		.LBB227:
		.LBB228:
				mov	r2, r7
				add	r1, sp, #4864
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL64:
				ldm	r5, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL65:
		.LBE228:
		.LBE227:
		.LBB229:
		.LBB230:
				bl	_imp_newline(PLT)
		.LVL66:
		.LBE230:
		.LBE229:
		.LBB231:
  126     print string("P<term-exp> = <term> ""^^"" ;"); newline
				mov	r2, r4
				add	r1, r6, #2304
				add	r5, sp, #4576
				adds	r5, r5, #20
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL67:
				mov	r2, r4
				mov	r1, r5
				addw	r6, sp, #2804
				mov	r0, r6
				bl	memcpy(PLT)
		.LVL68:
				mov	r2, r4
				mov	r1, r6
				mov	r0, r5
				bl	memcpy(PLT)
		.LVL69:
		.LBE231:
		.LBB232:
		.LBB233:
				mov	r2, r7
				add	r1, sp, #4608
				adds	r1, r1, #4
				mov	r0, sp
				bl	memcpy(PLT)
		.LVL70:
				ldm	r5, {r0, r1, r2, r3}
				bl	_imp_printstring(PLT)
		.LVL71:
		.LBE233:
		.LBE232:
		.LBB234:
		.LBB235:
				bl	_imp_newline(PLT)
		.LVL72:
		.LDL6:
		.LBE235:
		.LBE234:
		.LBB236:
		.LBB237:
				bl	_imp_newline(PLT)
		.LVL73:
		.LBE237:
		.LBE236:
		.LBB238:
		.LBB239:
				movs	r0, #0
				bl	exit(PLT)
		.LVL74:
		.L5:
				.align	2
		.L4:
				.word	_GLOBAL_OFFSET_TABLE_-(.LPIC0+4)
				.word	__stack_chk_guard(GOT)
				.word	.LANCHOR0-(.LPIC1+4)
		.LBE239:
		.LBE238:
		.LFE185:
				.section	.rodata
				.align	2
				.set	.LANCHOR0,. + 0
		.LC0:
				.byte	40
				.ascii	"Imp77 precedence and associativity test.\000"
				.space	214
		.LC11:
				.byte	85
				.ascii	"a * b // c * d is left associative and with equal p"
				.ascii	"recedence, i.e. ((a * b) // c) * d\000"
				.space	169
		.LC7:
				.byte	37
				.ascii	"This grammar would support the above:\000"
				.space	217
		.LC12:
				.byte	33
				.ascii	"P<expr> = <term-op-list> <term> ;\000"
				.space	221
		.LC13:
				.byte	46
				.ascii	"P<term-op-list> = <term-op> <term-op-list> | ;\000"
				.space	208
		.LC14:
				.byte	26
				.ascii	"P<term-op> = <term> <op> ;\000"
				.space	228
		.LC20:
				.byte	51
				.ascii	"p ^^ q ^^ r is left associative, i.e. (p ^^ q) ^^ r"
				.ascii	"\000"
				.space	203
		.LC21:
				.byte	34
				.ascii	"P<expr> = <term-exp-list> <term> ;\000"
				.space	220
		.LC22:
				.byte	49
				.ascii	"P<term-exp-list> = <term-exp> <term-exp-list> | ;\000"
				.space	205
		.LC23:
				.byte	27
				.ascii	"P<term-exp> = <term> \"^^\" ;\000"
				.space	227
		.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
