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