comparison tests/agcl/ffcalc/ffc-wa.syn @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 {/*
2 FOUR FUNCTION CALCULATOR: FFCALC.SYN
3 */
4 #include "Number.h"
5
6 int Number::nCreated = 0;
7 char Number::buf[100];
8
9 }
10
11 // -- CONFIGURATION SECTION ----------------------------
12 [
13 disregard white space
14 lexeme { real}
15 parser file name = "#.cpp"
16 wrapper {Number}
17 line numbers
18 allow macros = OFF
19 auto resynch
20 error frame
21 ]
22
23 // -- FOUR FUNCTION CALCULATOR -------------------------
24 calculator $
25 -> [calculation?, '\n']..., eof
26
27 calculation
28 -> expression:x =printf("%s\n", x.asString()),fflush(stdout);
29 -> name:n, '=', expression:x ={
30 printf("%c = %s\n",n+'A', fflush(stdout), (value[n]=x).asString());}
31
32 (Number) expression
33 -> term
34 -> expression:x, '+', term:t = {
35 printf("x = %s\n", x.asString());
36 printf("t = %s\n", t.asString());
37 fflush(stdout);
38 x+=t;
39 printf("x = %s\n", x.asString());
40 fflush(stdout);
41 return x;
42 }
43 -> expression:x, '-', term:t = x-=t;
44
45 (Number) term
46 -> factor
47 -> term:t, '*', factor:f = t*=f;
48 -> term:t, '/', factor:f = t/=f;
49
50 (Number) factor
51 -> name:n = value[n];
52 -> real:x =Number(x);
53 -> '(', expression:x, ')' = x;
54 -> '-', factor:f = -f;
55
56 // -- LEXICAL UNITS ------------------------------------
57 digit = '0-9'
58 eof = -1
59
60 white space
61 -> ' ' + '\t' + '\r' + '\f' + '\v'
62 -> "/*", ~eof?..., "*/"
63
64 (int) name
65 -> 'a-z' + 'A-Z':c = c-'A';
66
67 (double) real
68 -> integer part:i, '.', fraction part:f = i+f;
69 -> integer part, '.'?
70 -> '.', fraction part:f = f;
71
72 (double) integer part
73 -> digit:d = d-'0';
74 -> integer part:x, digit:d = 10*x + d-'0';
75
76 (double) fraction part
77 -> digit:d =(d-'0')/10.;
78 -> digit:d, fraction part:f =(d-'0' + f)/10.;
79
80 { /* -- EMBEDDED C ---------------------------------- */
81
82 #define SYNTAX_ERROR printf("%s, line %d, column %d\n", \
83 (PCB).error_message, (PCB).line, (PCB).column), fflush(stdout)
84
85 Number value[64]; /* registers */
86 int main(void) {
87 ffcalcr();
88 return 0;
89 }
90 } /* -- END OF EMBEDDED C ----------------------------*/