Mercurial > ~dholland > hg > ag > index.cgi
comparison examples/fc/fc4a.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 AnaGram Programming Examples | |
3 FC4A: Multiple Fahrenheit-Celsius conversion with signed numbers, | |
4 floating point arithmetic, optional white space, and Kelvin | |
5 temperature input. | |
6 | |
7 This grammar resolves the conflicts found in FC4. | |
8 | |
9 | |
10 Copyright 1993 Parsifal Software. All Rights Reserved. | |
11 | |
12 This software is provided 'as-is', without any express or implied | |
13 warranty. In no event will the authors be held liable for any damages | |
14 arising from the use of this software. | |
15 | |
16 Permission is granted to anyone to use this software for any purpose, | |
17 including commercial applications, and to alter it and redistribute it | |
18 freely, subject to the following restrictions: | |
19 | |
20 1. The origin of this software must not be misrepresented; you must not | |
21 claim that you wrote the original software. If you use this software | |
22 in a product, an acknowledgment in the product documentation would be | |
23 appreciated but is not required. | |
24 2. Altered source versions must be plainly marked as such, and must not be | |
25 misrepresented as being the original software. | |
26 3. This notice may not be removed or altered from any source distribution. | |
27 */ | |
28 | |
29 [ | |
30 test file mask = "*.fc4" // C1 | |
31 traditional engine /* turn this off for production use */ // C2 | |
32 default token type = double // C3 | |
33 disregard white space // C4 | |
34 lexeme {unsigned number, end of line} // C5 | |
35 ] | |
36 | |
37 eof = -1 | |
38 | |
39 (void) grammar | |
40 -> [temperature?, end of line]..., eof // P1 | |
41 | |
42 (void) temperature | |
43 -> number:c, 'c' + 'C' ={ /* P2 */ | |
44 double f = 9*c/5 + 32; | |
45 printf("%.6g\370F = %.6g\370C = %.6g\370K\n",f,c,c+273.16); | |
46 } | |
47 -> number:f, 'f' + 'F' = { /* P3 */ | |
48 double c = 5*(f-32)/9; | |
49 printf("%.6g\370F = %.6g\370C = %.6g\370K\n",f,c,c+273.16); | |
50 } | |
51 -> unsigned number:k, 'k' + 'K' ={ /* P3a */ | |
52 double c = k - 273.16; | |
53 double f = 9*c/5 + 32; | |
54 printf("%.6g\370F = %.6g\370C = %.6g\370K\n", f, c, k); | |
55 } | |
56 -> error // P4 | |
57 | |
58 number | |
59 -> '-', unsigned number:n =-n; // P5 | |
60 -> '+', unsigned number:n =n; // P6x | |
61 -> unsigned number:n =n; // P6y | |
62 | |
63 unsigned number | |
64 -> integer, '.'? // P6a | |
65 -> integer:i, '.', fraction:f =i+f; // P6b | |
66 -> '.', fraction:f =f; // P6c | |
67 | |
68 integer | |
69 -> '0-9':d =d-'0'; // P7 | |
70 -> integer:n, '0-9':d =10*n+d-'0'; // P8 | |
71 | |
72 fraction | |
73 -> '0-9':d =(d-'0')/10.; // P9 | |
74 -> '0-9':d, fraction:f =(d-'0' + f)/10.; // P10 | |
75 | |
76 white space | |
77 -> ' ' + '\t' // P11 | |
78 -> "/*", ~eof?..., "*/" // P12 | |
79 | |
80 end of line | |
81 -> ["//", ~(eof + '\n')?...], '\n' // P13 |