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