head	1.1;
access;
symbols;
locks
	gtoal:1.1; strict;
comment	@ * @;


1.1
date	2022.02.15.00.57.56;	author gtoal;	state Exp;
branches;
next	;


desc
@program for confirming actual implementation of imp77
@


1.1
log
@Initial revision
@
text
@#include <stdio.h>
int main(void) {
  const int a = 19, b = 17, c = 5, d = 3;
  int x = a * b / c * d;
  printf("C precedence and associativity test.\n\n");
  if (x == 21) {
    printf("In a * b / c * d, '*' has higher priority than '/'.\n");
    printf("A second test with '/' will be needed to determine associativity:\n");
    x = a / c / d;
    if (x == 1) {
      printf("a / c / d is right associative, i.e. a / (b / c)\n");
    } else if (x == 19) {
      printf("a / c / d is left associative, i.e. (a / b) / c\n");
    } else {
      printf("a / c / d is something weird!  I give up.\n");
    }
  } else if (x == 19) {
    printf("a * b / c * d is right associative and with equal precedence, i.e. a * (b / (c * d))\n");
    printf("\n");
    printf("This grammar would support the above:\n");
    printf("\n");
    printf("P<expr> = <term> <op-term-list> ;\n");
    printf("P<op-term-list> = <op-term> <op-term-list> | ;\n");
    printf("P<op-term> = <op> <term> ;\n");
  } else if (x == 192) {
    printf("a * b / c * d is left associative and with equal precedence, i.e. ((a * b) / c) * d\n");
    printf("\n");
    printf("This grammar would support the above:\n");
    printf("\n");
    printf("P<expr> = <term-op-list> <term> ;\n");
    printf("P<term-op-list> = <term-op> <term-op-list> | ;\n");
    printf("P<term-op> = <term> <op> ;\n");
  } else {
    printf("a * b / c * d uses some weird non-standard combination of precedence and associativity!\n");
  }
  return 0;
}
@
