         Edinburgh IMP77 Compiler - Version 8.4
    1 %begin
		.Ltext0:
				.align	2
				.global	main
		main:
		.LFB185:
		.LVL0:
				mov	x16, 5984
				sub	sp, sp, x16
				stp	x29, x30, [sp]
				add	x29, sp, 0
				stp	x19, x20, [sp, 16]
				stp	x21, x22, [sp, 32]
				stp	x23, x24, [sp, 48]
				stp	x25, x26, [sp, 64]
				adrp	x2, :got:__stack_chk_guard
				ldr	x2, [x2, #:got_lo12:__stack_chk_guard]
				ldr	x3, [x2]
				str	x3, [x29, 5976]
				mov	x3,0
    2
				bl	_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)
				adrp	x22, .LANCHOR0
				add	x22, x22, :lo12:.LANCHOR0
				add	x21, x29, 4096
				add	x21, x21, 1624
				mov	x19, 256
				mov	x2, x19
				mov	x1, x22
				mov	x0, x21
				bl	memcpy
		.LVL2:
				add	x20, x29, 344
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL3:
				add	x23, x29, 3160
				mov	x2, x19
				mov	x1, x20
				mov	x0, x23
				bl	memcpy
		.LVL4:
		.LBE171:
		.LBB172:
		.LBB173:
				add	x20, x29, 80
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL5:
				mov	x0, x20
				bl	_imp_printstring
		.LVL6:
		.LBE173:
		.LBE172:
		.LBB174:
		.LBB175:
				mov	w0, 2
				bl	_imp_newlines
		.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	x2, x19
				add	x1, x22, x19
				mov	x0, x21
				bl	memcpy
		.LVL8:
				add	x24, x29, 600
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL9:
				add	x23, x29, 4096
				add	x23, x23, 344
				mov	x2, x19
				mov	x1, x24
				mov	x0, x23
				bl	memcpy
		.LVL10:
		.LBE176:
		.LBB177:
		.LBB178:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL11:
				mov	x0, x20
				bl	_imp_printstring
		.LVL12:
		.LBE178:
		.LBE177:
		.LBB179:
		.LBB180:
				bl	_imp_newline
		.LVL13:
		.LBE180:
		.LBE179:
		.LBB181:
		.LBB182:
				bl	_imp_newline
		.LVL14:
		.LBE182:
		.LBE181:
		.LBB183:
   94     newline
   95     print string("This grammar would support the above:"); newline
				add	x26, x22, 1024
				add	x25, x22, 512
				mov	x2, x19
				mov	x1, x25
				mov	x0, x21
				bl	memcpy
		.LVL15:
				add	x24, x29, 856
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL16:
				add	x23, x29, 4096
				add	x23, x23, 88
				mov	x2, x19
				mov	x1, x24
				mov	x0, x23
				bl	memcpy
		.LVL17:
		.LBE183:
		.LBB184:
		.LBB185:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL18:
				mov	x0, x20
				bl	_imp_printstring
		.LVL19:
		.LBE185:
		.LBE184:
		.LBB186:
		.LBB187:
				bl	_imp_newline
		.LVL20:
		.LBE187:
		.LBE186:
		.LBB188:
		.LBB189:
				bl	_imp_newline
		.LVL21:
		.LBE189:
		.LBE188:
		.LBB190:
   96     newline
   97     print string("P<expr> = <term-op-list> <term> ;"); newline
				mov	x2, x19
				add	x1, x22, 768
				mov	x0, x21
				bl	memcpy
		.LVL22:
				add	x24, x29, 1112
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL23:
				add	x23, x29, 3928
				mov	x2, x19
				mov	x1, x24
				mov	x0, x23
				bl	memcpy
		.LVL24:
		.LBE190:
		.LBB191:
		.LBB192:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL25:
				mov	x0, x20
				bl	_imp_printstring
		.LVL26:
		.LBE192:
		.LBE191:
		.LBB193:
		.LBB194:
				bl	_imp_newline
		.LVL27:
		.LBE194:
		.LBE193:
		.LBB195:
   98     print string("P<term-op-list> = <term-op> <term-op-list> | ;"); newline
				mov	x2, x19
				mov	x1, x26
				mov	x0, x21
				bl	memcpy
		.LVL28:
				add	x24, x29, 1368
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL29:
				add	x23, x29, 3672
				mov	x2, x19
				mov	x1, x24
				mov	x0, x23
				bl	memcpy
		.LVL30:
		.LBE195:
		.LBB196:
		.LBB197:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL31:
				mov	x0, x20
				bl	_imp_printstring
		.LVL32:
		.LBE197:
		.LBE196:
		.LBB198:
		.LBB199:
				bl	_imp_newline
		.LVL33:
		.LBE199:
		.LBE198:
		.LBB200:
   99     print string("P<term-op> = <term> <op> ;"); newline
				mov	x2, x19
				add	x1, x22, 1280
				mov	x0, x21
				bl	memcpy
		.LVL34:
				add	x24, x29, 1624
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL35:
				add	x23, x29, 3416
				mov	x2, x19
				mov	x1, x24
				mov	x0, x23
				bl	memcpy
		.LVL36:
		.LBE200:
		.LBB201:
		.LBB202:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x20
				bl	memcpy
		.LVL37:
				mov	x0, x20
				bl	_imp_printstring
		.LVL38:
		.LBE202:
		.LBE201:
		.LBB203:
		.LBB204:
				bl	_imp_newline
		.LVL39:
		.LDL3:
		.LDL4:
		.LBE204:
		.LBE203:
		.LBB205:
		.LBB206:
				bl	_imp_newline
		.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
				add	x23, x22, 2048
				mov	x2, x19
				add	x1, x22, 1536
				mov	x0, x21
				bl	memcpy
		.LVL41:
				add	x24, x29, 1880
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL42:
				mov	x2, x19
				mov	x1, x24
				mov	x0, x21
				bl	memcpy
		.LVL43:
		.LBE207:
		.LBB208:
		.LBB209:
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL44:
				mov	x0, x20
				bl	_imp_printstring
		.LVL45:
		.LBE209:
		.LBE208:
		.LBB210:
		.LBB211:
				bl	_imp_newline
		.LVL46:
		.LBE211:
		.LBE210:
		.LBB212:
		.LBB213:
				bl	_imp_newline
		.LVL47:
		.LBE213:
		.LBE212:
		.LBB214:
  121     newline
  122     print string("This grammar would support the above:"); newline
				add	x21, x29, 4096
				add	x21, x21, 1368
				mov	x2, x19
				mov	x1, x25
				mov	x0, x21
				bl	memcpy
		.LVL48:
				add	x24, x29, 2136
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL49:
				mov	x2, x19
				mov	x1, x24
				mov	x0, x21
				bl	memcpy
		.LVL50:
		.LBE214:
		.LBB215:
		.LBB216:
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL51:
				mov	x0, x20
				bl	_imp_printstring
		.LVL52:
		.LBE216:
		.LBE215:
		.LBB217:
		.LBB218:
				bl	_imp_newline
		.LVL53:
		.LBE218:
		.LBE217:
		.LBB219:
		.LBB220:
				bl	_imp_newline
		.LVL54:
		.LBE220:
		.LBE219:
		.LBB221:
  123     newline
  124     print string("P<expr> = <term-exp-list> <term> ;"); newline
				add	x21, x29, 4096
				add	x21, x21, 1112
				mov	x2, x19
				add	x1, x22, 1792
				mov	x0, x21
				bl	memcpy
		.LVL55:
				add	x24, x29, 2392
				mov	x2, x19
				mov	x1, x21
				mov	x0, x24
				bl	memcpy
		.LVL56:
				mov	x2, x19
				mov	x1, x24
				mov	x0, x21
				bl	memcpy
		.LVL57:
		.LBE221:
		.LBB222:
		.LBB223:
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL58:
				mov	x0, x20
				bl	_imp_printstring
		.LVL59:
		.LBE223:
		.LBE222:
		.LBB224:
		.LBB225:
				bl	_imp_newline
		.LVL60:
		.LBE225:
		.LBE224:
		.LBB226:
  125     print string("P<term-exp-list> = <term-exp> <term-exp-list> | ;"); newline
				add	x21, x29, 4096
				add	x21, x21, 856
				mov	x2, x19
				mov	x1, x23
				mov	x0, x21
				bl	memcpy
		.LVL61:
				add	x23, x29, 2648
				mov	x2, x19
				mov	x1, x21
				mov	x0, x23
				bl	memcpy
		.LVL62:
				mov	x2, x19
				mov	x1, x23
				mov	x0, x21
				bl	memcpy
		.LVL63:
		.LBE226:
		.LBB227:
		.LBB228:
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL64:
				mov	x0, x20
				bl	_imp_printstring
		.LVL65:
		.LBE228:
		.LBE227:
		.LBB229:
		.LBB230:
				bl	_imp_newline
		.LVL66:
		.LBE230:
		.LBE229:
		.LBB231:
  126     print string("P<term-exp> = <term> ""^^"" ;"); newline
				add	x21, x29, 4096
				add	x21, x21, 600
				mov	x2, x19
				add	x1, x22, 2304
				mov	x0, x21
				bl	memcpy
		.LVL67:
				add	x22, x29, 2904
				mov	x2, x19
				mov	x1, x21
				mov	x0, x22
				bl	memcpy
		.LVL68:
				mov	x2, x19
				mov	x1, x22
				mov	x0, x21
				bl	memcpy
		.LVL69:
		.LBE231:
		.LBB232:
		.LBB233:
				mov	x2, x19
				mov	x1, x21
				mov	x0, x20
				bl	memcpy
		.LVL70:
				mov	x0, x20
				bl	_imp_printstring
		.LVL71:
		.LBE233:
		.LBE232:
		.LBB234:
		.LBB235:
				bl	_imp_newline
		.LVL72:
		.LDL6:
		.LBE235:
		.LBE234:
		.LBB236:
		.LBB237:
				bl	_imp_newline
		.LVL73:
		.LBE237:
		.LBE236:
		.LBB238:
		.LBB239:
				mov	w0, 0
				bl	exit
		.LVL74:
		.LBE239:
		.LBE238:
		.LFE185:
				.section	.rodata
				.align	3
				.set	.LANCHOR0,. + 0
		.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
		.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
