comparison examples/ffcalc/ffcalc.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 {/* FOUR FUNCTION CALCULATOR: FFCALC.SYN */}
2
3 // -- CONFIGURATION SECTION ----------------------------
4 [
5 default token type = double
6 disregard white space
7 lexeme { real}
8 ]
9
10 // -- FOUR FUNCTION CALCULATOR -------------------------
11 (void) calculator $
12 -> [calculation?, '\n']..., eof
13
14 (void) calculation
15 -> expression:x =printf("%g\n",x);
16 -> name:n, '=', expression:x ={
17 printf("%c = %g\n",n+'A',value[n]=x);}
18 -> error
19
20 expression
21 -> term
22 -> expression:x, '+', term:t = x+t;
23 -> expression:x, '-', term:t = x-t;
24
25 term
26 -> factor
27 -> term:t, '*', factor:f = t*f;
28 -> term:t, '/', factor:f = t/f;
29
30 factor
31 -> name:n = value[n];
32 -> real
33 -> '(', expression:x, ')' = x;
34 -> '-', factor:f = -f;
35
36 // -- LEXICAL UNITS ------------------------------------
37 digit = '0-9'
38 eof = -1
39
40 (void) white space
41 -> ' ' + '\t' + '\r' + '\f' + '\v'
42 -> "/*", ~eof?..., "*/"
43
44 (int) name
45 -> 'a-z' + 'A-Z':c = c-'A';
46
47 real
48 -> integer part:i, '.', fraction part:f = i+f;
49 -> integer part, '.'?
50 -> '.', fraction part:f = f;
51
52 integer part
53 -> digit:d = d-'0';
54 -> integer part:x, digit:d = 10*x + d-'0';
55
56 fraction part
57 -> digit:d =(d-'0')/10.;
58 -> digit:d, fraction part:f =(d-'0' + f)/10.;
59
60 { /* -- EMBEDDED C ---------------------------------- */
61 double value[64]; /* registers */
62 int main(void) {
63 ffcalc();
64 return 0;
65 }
66 } /* -- END OF EMBEDDED C ----------------------------*/