view tests/agcl/ffcalc/ffc-wa.syn @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -0400
parents 13d2b8934445
children
line wrap: on
line source

{/*
	   FOUR FUNCTION CALCULATOR: FFCALC.SYN
*/
#include "Number.h"

int Number::nCreated = 0;
char Number::buf[100];

}

// -- CONFIGURATION SECTION ----------------------------
[
  disregard white space
  lexeme { real}
	parser file name = "#.cpp"
	wrapper {Number}
	line numbers
	allow macros = OFF
	auto resynch
	error frame
]

// -- FOUR FUNCTION CALCULATOR -------------------------
calculator $
 -> [calculation?, '\n']..., eof

calculation
 -> expression:x                      =printf("%s\n", x.asString()),fflush(stdout);
 -> name:n, '=', expression:x                         ={
                  printf("%c = %s\n",n+'A', fflush(stdout), (value[n]=x).asString());}

(Number) expression
 -> term
 -> expression:x, '+', term:t                     = {
		printf("x = %s\n", x.asString());
		printf("t = %s\n", t.asString());
		fflush(stdout);
    x+=t;
		printf("x = %s\n", x.asString());
		fflush(stdout);
		return x;
 }
 -> expression:x, '-', term:t                     = x-=t;

(Number) term
 -> factor
 -> term:t, '*', factor:f                         = t*=f;
 -> term:t, '/', factor:f                         = t/=f;

(Number) factor
 -> name:n                                   = value[n];
 -> real:x                                   =Number(x);
 -> '(', expression:x, ')'                          = x;
 -> '-', factor:f                                  = -f;

// -- LEXICAL UNITS ------------------------------------
digit   = '0-9'
eof     = -1

white space
 -> ' ' + '\t' + '\r' + '\f' + '\v'
 -> "/*", ~eof?..., "*/"

(int) name
 -> 'a-z' + 'A-Z':c                             = c-'A';

(double) real
 -> integer part:i, '.', fraction part:f          = i+f;
 -> integer part, '.'?
 -> '.', fraction part:f                            = f;

(double) integer part
 -> digit:d                                     = d-'0';
 -> integer part:x, digit:d              = 10*x + d-'0';

(double) fraction part
 -> digit:d                                =(d-'0')/10.;
 -> digit:d, fraction part:f           =(d-'0' + f)/10.;

{ /* -- EMBEDDED C ---------------------------------- */

#define SYNTAX_ERROR printf("%s, line %d, column %d\n", \
  (PCB).error_message, (PCB).line, (PCB).column), fflush(stdout)

  Number value[64];                      /* registers */
  int main(void) {
    ffcalcr();
    return 0;
  }
} /* -- END OF EMBEDDED C ----------------------------*/