Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/ffcalc/ffcm-a.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 -> [statement, '\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:f | |
28 -> term:t, '*', factor:f = t*f; | |
29 -> term:t, '/', factor:f = t/f; | |
30 | |
31 factor | |
32 -> identifier:n = value[n]; | |
33 -> real | |
34 -> '(', expression:x, ')' = x; | |
35 -> '-', factor:f = -f; | |
36 | |
37 identifier | |
38 -> | |
39 | |
40 // -- LEXICAL UNITS ------------------------------------ | |
41 digit = '0-9' | |
42 eof = -1 | |
43 | |
44 (void) white space | |
45 -> ' ' + '\t' + '\r' + '\f' + '\v' | |
46 -> "/*", ~eof?..., "*/" | |
47 | |
48 (int) name | |
49 -> 'a-z' + 'A-Z':c = c-'A'; | |
50 | |
51 real | |
52 -> integer part:i, '.', fraction part:f = i+f; | |
53 -> integer part, '.'? | |
54 -> '.', fraction part:f = f; | |
55 | |
56 integer part | |
57 -> digit:d = d-'0'; | |
58 -> integer part:x, digit:d = 10*x + d-'0'; | |
59 | |
60 fraction part | |
61 -> digit:d =(d-'0')/10.; | |
62 -> digit:d, fraction part:f =(d-'0' + f)/10.; | |
63 | |
64 name | |
65 -> letter: c =n_chars = 0, name[n_chars++]=c; | |
66 -> name, letter+digit: c =name[n_chars++]=c; | |
67 | |
68 { /* -- EMBEDDED C ---------------------------------- */ | |
69 double value[64]; /* registers */ | |
70 void main(void) { | |
71 ffcalc(); | |
72 } | |
73 } // -- END OF EMBEDDED C ------------------------------ |