Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/ffcalc/ffc-w.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 {/* | |
2 FOUR FUNCTION CALCULATOR: FFCALC.SYN | |
3 */ | |
4 #include "Number.h" | |
5 | |
6 int Number::nCreated = 0; | |
7 char Number::buf[100]; | |
8 | |
9 } | |
10 | |
11 // -- CONFIGURATION SECTION ---------------------------- | |
12 [ | |
13 disregard white space | |
14 lexeme { real} | |
15 parser file name = "#.cpp" | |
16 wrapper {Number} | |
17 line numbers | |
18 allow macros = OFF | |
19 default token type = Number | |
20 token names | |
21 ] | |
22 | |
23 // -- FOUR FUNCTION CALCULATOR ------------------------- | |
24 calculator $ | |
25 -> [calculation?, '\n']..., eof | |
26 | |
27 calculation | |
28 -> expression:x =printf("%s\n", x.asString()); | |
29 -> name:n, '=', expression:x ={ | |
30 printf("%c = %s\n",n+'A', (value[n]=x).asString());} | |
31 -> error | |
32 | |
33 (Number) expression | |
34 -> term | |
35 -> expression:x, '+', term:t = { | |
36 printf("x = %s\n", x.asString()); | |
37 printf("t = %s\n", t.asString()); | |
38 x+=t; | |
39 printf("x = %s\n", x.asString()); | |
40 return x; | |
41 } | |
42 -> expression:x, '-', term:t = x-=t; | |
43 | |
44 (Number) term | |
45 -> factor | |
46 -> term:t, '*', factor:f = t*=f; | |
47 -> term:t, '/', factor:f = t/=f; | |
48 | |
49 (Number) factor | |
50 -> name:n = value[n]; | |
51 -> real:x =Number(x); | |
52 -> '(', expression:x, ')' = x; | |
53 -> '-', factor:f = -f; | |
54 | |
55 // -- LEXICAL UNITS ------------------------------------ | |
56 digit = '0-9' | |
57 eof = -1 | |
58 | |
59 (void) white space | |
60 -> ' ' + '\t' + '\r' + '\f' + '\v' | |
61 -> "/*", ~eof?..., "*/" | |
62 | |
63 (int) name | |
64 -> 'a-z' + 'A-Z':c = c-'A'; | |
65 | |
66 (double) real | |
67 -> integer part:i, '.', fraction part:f = i+f; | |
68 -> integer part, '.'? | |
69 -> '.', fraction part:f = f; | |
70 | |
71 (double) integer part | |
72 -> digit:d = d-'0'; | |
73 -> integer part:x, digit:d = 10*x + d-'0'; | |
74 | |
75 (double) fraction part | |
76 -> digit:d =(d-'0')/10.; | |
77 -> digit:d, fraction part:f =(d-'0' + f)/10.; | |
78 | |
79 { /* -- EMBEDDED C ---------------------------------- */ | |
80 | |
81 #define SYNTAX_ERROR printf("%s, line %d, column %d\n", \ | |
82 (PCB).error_message, (PCB).line, (PCB).column) | |
83 | |
84 Number value[64]; /* registers */ | |
85 int main(void) { | |
86 ffcalc(); | |
87 return 0; | |
88 } | |
89 } /* -- END OF EMBEDDED C ----------------------------*/ |