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