forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.mlc
More file actions
245 lines (178 loc) · 7.62 KB
/
logic.mlc
File metadata and controls
245 lines (178 loc) · 7.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/*
This library consists of the logical operations included in the standard library of LiveCode Builder.
*/
module com.livecode.logic
use com.livecode.foreign
//foreign handler MCLogicEvalAnd(in Left as CBool, in Right as CBool, out Value as CBool) returns nothing binds to "<builtin>"
//foreign handler MCLogicEvalOr(in Left as CBool, in Right as CBool, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCLogicEvalNot(in Operand as CBool, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCLogicEvalIsEqualTo(in Left as CBool, in Right as CBool, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCLogicEvalIsNotEqualTo(in Left as CBool, in Right as CBool, out Value as CBool) returns nothing binds to "<builtin>"
public foreign handler MCLogicEvalBoolFormattedAsString(in Target as CBool, out Value as String) returns nothing binds to "<builtin>"
public foreign handler MCLogicEvalStringParsedAsBool(in Target as String, out Value as optional Boolean) returns nothing binds to "<builtin>"
public foreign handler MCLogicExecFormatBoolAsString(in Target as CBool) returns String binds to "<builtin>"
public foreign handler MCLogicExecParseStringAsBool(in Target as String) returns optional Boolean binds to "<builtin>"
--
/*
Summary: Returns the boolean-logical value of the expression '<Left> and <Right>'
Left: An expression that evaluates to a boolean value
Right: An expression that evaluates to a boolean value
Returns: If the left hand expression evaluates to false, the value of the expression is false.
Otherwise, the operator evaluates to the value of the right hand expression.
Note that the right hand expression is only evaluated if the left hand expression is true.
*/
//syntax LogicOr is left binary operator of precedence 4
// <Left: Expression> "or" <Right: Expression>
//begin
// EvalOr(Left, Right, output)
//end syntax
/*
Summary: Returns the boolean-logical value of the expression '<Left> or <Right>'
Left: An expression that evaluates to a boolean value
Right: An expression that evaluates to a boolean value
Returns: If the left hand expression evaluates to true, the value of the expression is true.
Otherwise, the operator evaluates to the value of the right hand expression.
Note that the right hand expression is only evaluated if the left hand expression is false.
*/
//syntax LogicAnd is left binary operator of precedence 3
// <Left: Expression> "and" <Right: Expression>
//begin
// EvalAnd(Left, Right, output)
//end syntax
/*
Summary: Returns the boolean-logical value of the expression 'not <Operand>'
Operand: An expression that evaluates to a boolean value
Returns: If the operand expression evaluates to true, the value of the expression is false.
Otherwise, the value of the expression is true.
Example:
variable tBool is bool
put not not not not true into tBool is true
Tags: Logic
*/
syntax LogicNot is prefix operator with precedence 6
"not" <Operand: Expression>
begin
MCLogicEvalNot(Operand, output)
end syntax
--
/*
Summary: Determines whether <Left> and <Right> are equal or not.
Left: An expression which evaluates to a boolean value.
Right: An expression which evaluates to a boolean value.
Returns: Returns true if <Left> evaluates to the same value as <Right>.
Example:
variable tBool is bool
put true is true into tBool -- tBool is true
Tags: Logic
*/
syntax BooleanIsEqualToBoolean is neutral binary operator with precedence 7
<Left: Expression> "is" <Right: Expression>
begin
MCLogicEvalIsEqualTo(Left, Right, output)
end syntax
/*
Summary: Determines whether <Left> and <Right> are equal or not.
Left: An expression which evaluates to a boolean value.
Right: An expression which evaluates to a boolean value.
Returns: Returns true if <Left> evaluates to the opposite boolean value as <Right>.
Example:
variable tBool is bool
put true is not false into tBool -- tBool is true
Tags: Logic
*/
syntax BooleanIsNotEqualToBoolean is neutral binary operator with precedence 7
<Left: Expression> "is not" <Right: Expression>
begin
MCLogicEvalIsNotEqualTo(Left, Right, output)
end syntax
/*
Summary: Formats a boolean value as a string
Operand: An expression that evaluates to a boolean value.
Returns: "true" or "false"
Example:
variable tString as String
variable tBool as boolean
put (false is not not true) is false into tBool
put tBool formatted as string into tString -- tString contains "true"
Description:
Use <BooleanFormattedAsString> when you want to manipulate a boolean value as text.
*/
syntax BooleanFormattedAsString is postfix operator with precedence 1
<Operand: Expression> "formatted" "as" "string"
begin
MCLogicEvalBoolFormattedAsString(Operand, output)
end syntax
/*
Summary: Formats a boolean value as a string
Operand: An expression that evaluates to a boolean value.
The result: "true" or "false"
Example:
variable tVar as String
parse 1 = 0 as String
put the result into tVar
put "e" into char 3 of tVar -- tVar is "tree"
Description:
Use <FormatBooleanAsString> when you want to manipulate a boolean value as text.
*/
syntax FormatBooleanAsString is statement
"format" <Operand: Expression> "as" "string"
begin
MCLogicExecFormatBoolAsString(Operand)
end syntax
/*
Summary: Parses a string as a boolean value
Operand: An expression that evaluates to a string.
Returns: true or false
Example:
variable tString as String
variable tBool as optional Boolean
put "false" into tString
put tString parsed as boolean into tBool -- tBool contains false
Example:
variable tBool as optional Boolean
put "flase" parsed as boolean into tBool -- tBool is not defined
Description:
Use <StringParsedAsBoolean> when you want to determine if a string contains "true" or "false"
>*Note:* Only the strings "true" and "false" will parse to give a boolean value. Any other input will cause an error to be thrown.
*/
syntax StringParsedAsBoolean is postfix operator with precedence 1
<Operand: Expression> "parsed" "as" "boolean"
begin
MCLogicEvalStringParsedAsBool(Operand, output)
end syntax
/*
Summary: Parses a string as a boolean value
Operand: An expression that evaluates to a string.
Returns: true or false
Example:
variable tString as String
variable tBool as optional Boolean
combine ["f", "a", "l", "s" "e"] with "" into tString
put tString parsed as boolean into tBool -- tBool contains false
Example:
variable tResult as String
parse "sdfsdf" as Boolean
if the result is not defined then
put "not a valid boolean" into tResult
end if
Description:
Use <StringParsedAsBoolean> when you want to determine if a string contains "true" or "false"
>*Note:* Only the strings "true" and "false" will parse to give a boolean value. Any other input will cause an error to be thrown.
*/
syntax ParseStringAsBoolean is statement
"parse" <Operand: Expression> "as" "boolean"
begin
MCLogicExecParseStringAsBool(Operand)
end syntax
end module