/[ascend]/trunk/models/z-iflogic.a4c
ViewVC logotype

Contents of /trunk/models/z-iflogic.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Fri Oct 29 20:54:12 2004 UTC (19 years, 7 months ago) by aw0a
File MIME type: text/x-ascend
File size: 3921 byte(s)
Setting up web subdirectory in repository
1 REQUIRE "measures.a4l";
2 (* => measures.a4l *)
3 PROVIDE "z-iflogic.a4c";
4 (*
5 * This file is part of the ASCEND Modeling Library and is released
6 * under the GNU Public License as described at the end of this file.
7 *)
8
9 MODEL testif;
10 i IS_A integer;
11 j IS_A symbol_constant;
12 k IS_A boolean;
13 l IS_A real;
14 eval[1..4] IS_A boolean; (* all elements should --> FALSE *)
15 pass[1..4] IS_A boolean; (* all elements should --> TRUE *)
16 if[1..6] IS_A boolean; (* all elements should --> TRUE *)
17 nif[1..6] IS_A boolean; (* all elements should --> FALSE *)
18 j :== 'no';
19 METHODS
20 METHOD test;
21 i :=1;
22 k := FALSE;
23 l := 1 {m/s};
24 eval[1] := i=2;
25 eval[2] := j='yes';
26 eval[3] := k = TRUE;
27 eval[4] := l = 1.0;
28 pass[1] := i=1;
29 pass[2] := j='no';
30 pass[3] := k = FALSE;
31 pass[4] := l = 1.0 {m/s};
32
33 (* TRUE *)
34 IF i <> 0 AND i = 1 THEN
35 (* we don't promote int to bool. test for 0 explicitly *)
36 if[1] := TRUE;
37 ELSE
38 if[1] := FALSE;
39 END IF;
40
41 IF TRUE AND i = 1 THEN (* and? *)
42 if[2] := TRUE;
43 ELSE
44 if[2] := FALSE;
45 END IF;
46
47 IF i = 2 OR i = 1 THEN (* or? *)
48 if[3] := TRUE;
49 ELSE
50 if[3] := FALSE;
51 END IF;
52
53 IF j = j THEN (* strcmp? *)
54 if[4] := TRUE;
55 ELSE
56 if[4] := FALSE;
57 END IF;
58
59 IF NOT k THEN (* not of bool? *)
60 if[5] := TRUE;
61 ELSE
62 if[5] := FALSE;
63 END IF;
64
65 IF l > 0.5{?} THEN
66 if[6] := TRUE;
67 ELSE
68 if[6] := FALSE;
69 END IF;
70
71 (* FALSE *)
72 IF (i != 0) AND (i = 2) THEN
73 (* i AND i = 2 --> error because we don't promote i to bool *)
74 (* i != 0 AND i = 2 --> error because precedence is incorrect *)
75 nif[1] := TRUE;
76 ELSE
77 nif[1] := FALSE;
78 END IF;
79
80 IF NOT TRUE AND i = 1 THEN (* not precedence *)
81 nif[2] := TRUE;
82 ELSE
83 nif[2] := FALSE;
84 END IF;
85
86 IF i = 2 OR i = 5 THEN (* or *)
87 nif[3] := TRUE;
88 ELSE
89 nif[3] := FALSE;
90 END IF;
91
92 IF j = 'y' THEN (* strcmp *)
93 nif[4] := TRUE;
94 ELSE
95 nif[4] := FALSE;
96 END IF;
97
98 IF k THEN (* bool *)
99 nif[5] := TRUE;
100 ELSE
101 nif[5] := FALSE;
102 END IF;
103
104 IF l > 0.5{s} THEN
105 (* dimensionality not correctly enforced in inequalities.
106 * dimen conflict should --> UNDEFINED error.
107 *)
108 nif[6] := TRUE;
109 ELSE
110 nif[6] := FALSE;
111 END IF;
112
113 END test;
114 END testif;
115
116
117 (*
118 * IF statement (mis)interpretation tests.
119 * By Benjamin Allan
120 * Part of the ASCEND Library
121 * $Date: 1998/06/17 19:39:36 $
122 * $Revision: 1.2 $
123 * $Author: mthomas $
124 * $Source: /afs/cs.cmu.edu/project/ascend/Repository/models/z-iflogic.a4c,v $
125 *
126 * This file is part of the ASCEND Modeling Library.
127 *
128 * Copyright (C) 1997 Carnegie Mellon University
129 *
130 * The ASCEND Modeling Library is free software; you can redistribute
131 * it and/or modify it under the terms of the GNU General Public
132 * License as published by the Free Software Foundation; either
133 * version 2 of the License, or (at your option) any later version.
134 *
135 * The ASCEND Modeling Library is distributed in hope that it
136 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
137 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
138 * See the GNU General Public License for more details.
139 *
140 * You should have received a copy of the GNU General Public License
141 * along with the program; if not, write to the Free Software
142 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA.
143 *)

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22