comparison tests/agcl/ffcalc/ffcs-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: FFCALC.SYN */}
2
3 // -- CONFIGURATION SECTION ----------------------------
4 [
5 default token type = double
6 disregard white space
7 lexeme { real}
8 traditional engine
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 | '(', expression:x, ')' = x; | '-', factor:f = -f;
34
35 // -- LEXICAL UNITS ------------------------------------
36 digit = '0-9'
37 eof = -1
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; | integer part, '.'? | '.', fraction part:f = f;
48
49 integer part
50 -> digit:d = d-'0';
51 -> integer part:x, digit:d = 10*x + d-'0';
52
53 fraction part
54 -> digit:d =(d-'0')/10.;
55 -> digit:d, fraction part:f =(d-'0' + f)/10.;
56
57 { /* -- EMBEDDED C ---------------------------------- */
58 double value[64]; /* registers */
59 void main(void) {
60 ffcalc();
61 }
62 } // -- END OF EMBEDDED C ------------------------------