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