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