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