Promela: Errors with parameters in proctypes, and using 'end' label - promela

I'm new to Promela, and I'm not sure what the issue with my code is:
proctype frogJump(int frogNum, int frogDirection)
{
printf("FROG%d STARTS AT %d", frogNum, frogs[frogNum]);
int temp;
end: do
:: lock(mutex) ->
if
::(frog[0] == frogs[frogNum]+frogDirection || frog[0] == frogs[frogNum]+frogDirection+frogDirection]) ->
temp = frog[frogNum];
frog[frogNum] = frog[0];
frog[0] = temp;
printCurrentLayout();
printf("FROG%d FROM %d TO %d", frogNum, temp, frog[frogNum]);
:: else -> unlock(mutex);
fi;
:: skip;
od
}
Getting the following errors:
spin: frogs.pml:25, Error: syntax error saw 'data typename' near 'int'
spin: frogs.pml:30, Error: syntax error saw 'an identifier' near 'end'
With line 25 being
proctype frogJump(int frogNum, int frogDirection)
and line 30 being
end: do
As far as I understand, I'm supposed to use the 'end' label to signal to SPIN that the frog proctype can be considered ended without having to be at the end of it's code. But I'm having the issue that I can't seem to use 'do' beside the 'end' label. I also don't know what the issue with the parameter 'int' is.

This error
spin: frogs.pml:25, Error: syntax error saw 'data typename' near 'int'
is caused by the fact that the argument list separator for a proctype declaration is ; and not ,.
You can make the error go away by changing
proctype frogJump(int frogNum, int frogDirection)
into this
proctype frogJump(int frogNum; int frogDirection)
In the case of inline functions, the correct argument list separator is indeed ,, e.g.
inline recv(cur_msg, cur_ack, lst_msg, lst_ack)
{
do
:: receiver?cur_msg ->
sender!cur_ack; break /* accept */
:: receiver?lst_msg ->
sender!lst_ack
od;
}
The second error message
spin: frogs.pml:30, Error: syntax error saw 'an identifier' near 'end'
is probably just a side effect of the incorrect parsing tree resulting from the first syntax error, and should fade away accordingly when fixing it.

Related

How do I print a message if a ValueError occurs?

while answers_right < 3:
ran_number_1 = random.randint(10, 99)
ran_number_2 = random.randint(10, 99)
solution = ran_number_1 + ran_number_2
print(f"What is {ran_number_1} + {ran_number_2}?")
user_answer = int(input("Your answer: "))
if user_answer == solution:
answers_right += 1
print(f"Correct. You've gotten {answers_right} correct in a row.")
elif user_answer != solution:
answers_right = 0
print(f"Incorrect. The expected answer is {solution}.")
if answers_right == 3:
print("Congratulations! You've mastered addition.")
I want to add an additional if statement in case someone types string and return a message that says "Invalid Response" instead of the Traceback Error.
Use of Exception handling in python may be solve your Problem and you can also generate your own error class for particular condition.
if x < 3:
raise Exception("Sorry, no numbers below 3")
Use of throw and raise keyword you can generate your own error.
for more referencelink here
The correct way to solve this problem is to look at the error type in your traceback, and use a try/except block. It will say something like TypeError: error stuff here or ValueError: error stuff also here.
The way you do a try/except is to:
try:
some_code()
that_might()
produce_an_error()
except some_error_type:
do_stuff()
except_some_other_error_type:
do_other_stuff()
So, to catch a ValueError and a TypeError, you might do:
try:
buggy_code()
except ValueError:
print("Woah, you did something you shouldn't have")
except TypeError:
print("Woah, you did something ELSE you shouldn't have")
If you then want the traceback, you can add in a lone "raise" statement below the excepts. For example:
try:
buggy_code()
except ValueError:
print("Woah, you did something you shouldn't have")
raise
except TypeError:
print("Woah, you did something ELSE you shouldn't have")
raise
Errors have evolved to be a lot more useful in modern times. They don't break the entire system anymore, and there are ways of handling them. Try/Except blocks like the above give you the tools to have code that only executes when a specific error or set of errors is raised.

Trying to match to a typedef value in a receive statement causes "bad node type 44" error message

When I try to match a message in a receive statement I get a "bad node type 44" error message. This happens when the message's type is a typedef. The error message is rather cryptic and doesn't give much insight.
typedef t {
int i
}
init {
chan c = [1] of {t}
t x;
!(c ?? [eval(x)]) // <--- ERROR
}
Note: This may, or may not, be a bug in Spin: apparently, the grammar allows using a structure variable as an argument for eval(), but it does not look like this situation is handled correctly (within the extent of my limited understanding). I would encourage you to contact the maintainers of Promela/Spin and submit your model.
Nevertheless, there is a work-around for the issue you reported (see below).
Contrary to what is reported here:
NAME
eval - predefined unary function to turn an expression into a constant.
SYNTAX
eval( any_expr )
The actual promela grammar for EVAL looks a bit different:
receive : varref '?' recv_args /* normal receive */
| varref '?' '?' recv_args /* random receive */
| varref '?' '<' recv_args '>' /* poll with side-effect */
| varref '?' '?' '<' recv_args '>' /* ditto */
recv_args: recv_arg [ ',' recv_arg ] * | recv_arg '(' recv_args ')'
recv_arg : varref | EVAL '(' varref ')' | [ '-' ] const
varref : name [ '[' any_expr ']' ] [ '.' varref ]
Take-aways:
apparently, eval is allowed to take as argument a structure (because name may be the identifier of a typedef structure [?])
eval can also take as argument a structure field
when one aims to apply message filtering to an entire structure, it can expand the relevant fields of the structure itself
Example:
typedef Message {
int _filter;
int _value;
}
chan inout = [10] of { Message }
active proctype Producer()
{
Message msg;
byte cc = 0;
for (cc: 1 .. 10) {
int id;
select(id: 0..1);
msg._filter = id;
msg._value = cc;
atomic {
printf("Sending: [%d|%d]\n", msg._filter, msg._value);
inout!msg;
}
}
printf("Sender Stops.\n");
}
active proctype Consumer()
{
Message msg;
msg._filter = 0;
bool ignored;
do
:: atomic {
inout??[eval(msg._filter)] ->
inout??eval(msg._filter), msg._value;
printf("Received: [%d|%d]\n", msg._filter, msg._value);
}
:: timeout -> break;
od;
printf("Consumer Stops.\n");
}
simulation output:
~$ spin test.pml
Sending: [1|1]
Sending: [0|2]
Received: [0|2]
Sending: [0|3]
Received: [0|3]
Sending: [0|4]
Received: [0|4]
Sending: [0|5]
Received: [0|5]
Sending: [1|6]
Sending: [0|7]
Received: [0|7]
Sending: [0|8]
Received: [0|8]
Sending: [1|9]
Sending: [1|10]
Sender Stops.
timeout
Consumer Stops.
2 processes created
Generating a verifier does not result in a compilation error:
~$ spin -a test.pml
~$ gcc -o run pan.c
Note: when using both message filtering and message polling (like in your model sample), the fields of the structure that are subject to message filtering should be placed at the beginning of it.
Apparently it's a bug, link to github issue: https://github.com/nimble-code/Spin/issues/17
Update: Bug is now fixed.
Update 2: Bug was actually partially fixed, there are still some edge cases where it's behaving weirdly.
Update 3: As far as I can tell bug looks fixed now. The only downside is that it seems that now there is a strict restriction on what you put in the receive args. They have to match exactly the types declared in the channel. No more partial matches or unrolling struct fields.
My guess is that this error is related to the restrictions that structured types have. One restriction is that they can't be handled as a unit, to assign or compare them one must do it one field at a time.
For example, if one writes: x == y, where x and y are variables of a typedef type, the following error is shown: Error: incomplete structure ref 'x' saw 'operator: =='
Under the hood, when trying to compare the channel's queue to match the eval something is triggered that indicates that the comparison can't be done and then raises the "bad node type" message.

iOS JavascriptCore exception detailed stacktrace info

It seems the exception stacktrace in iOS only contains the method name or there is a bug. Below is my code of handling exceptions in JSContext.
context.exceptionHandler = { (ctx: JSContext!, value: JSValue!) in
// type of String
let stacktrace = value.objectForKeyedSubscript("stack").toString()
// type of Number
let lineNumber = value.objectForKeyedSubscript("line")
// type of Number
let column = value.objectForKeyedSubscript("column")
let moreInfo = "in method \(stacktrace)Line number in file: \(lineNumber), column: \(column)"
Logger.error("JS ERROR: \(value) \(moreInfo)")
}
And I got logs like below
ERROR : JSContextRenderer.swift:308 : setupContext : JS ERROR: Error in method clearBackground
Line number in file: 162, column: 12"
Note there is a new line right after the "clearBackground" name, I think there probably more information there.
Can anybody having similar experience confirm? Any help is appreciated. Thanks.
Looks like it does show more information in the stack. Here is one of the log information I got:
JS ERROR: TypeError: undefined is not a function (evaluating 'msg.__assert__()') in method assert
syncShots
updateSync
initSync
setState
onLogicStateChanged
onLogicStateChanged
[native code]
updateMove
sendMove
shoot
onTouchUp
[native code]
_handleEvent
_dispatchEvent
. Line number in file: 183, column: 20
Long ago, #igrek asked where the keys in value come from. They're part of the Error object that was thrown by the JavaScript engine, and that now appears as value in the native error handler callback. What exactly Error includes depends on the implementation, but typically includes message, fileName, and lineNumber. It appears that stack is also supported. More details on the MDN page for Error .

Errors in my code

Alright, I have a couple error messages and I am stuck. Just seeing if anybody could help me out here, it would be greatly appreciated.
Here is the error message:
bibleajax.cpp: In function Ă¢int main():
bibleajax.cpp:92: error: no matching function for call to Bible::lookup(Verse&, LookupResult&)
Bible.h:32: note: candidates are: const Verse Bible::lookup(Ref, LookupResult&)
make: * [bibleajax.o] Error 1
Here is line 92:
Ref nRef;
Verse nVerse;
for (int t = 0; t < num; t++){
do {
nRef = kjv.lookup(nVerse, result);
nVerse = kjv.lookup(nRef, result);
}
while (result != ch && result != no_chapter);
It would appear that your Verse class does not have a member function called getRef(). You also appear to be trying to call the lookup function by passing it a Verse object instead of a Ref object... but that piece of code doesn't seem to be included in what you've posted here.
Note that the relevant line numbers for the code are posted in the error messages. So check lines 79 and 92 for the issues I mentioned here.

CKEDITOR - Set Caret to end

I'm working a lot with positioning within CKEDITOR.
But i still can't figure out why the following code
sometimes doesn't work?
var range = new CKEDITOR.dom.range(editor.document);
range.moveToElementEditablePosition(element, setToEnd);
editor.getSelection().selectRanges([range]);
I think that it has something to do with the element input that i'm giving.
But i'm not sure.
Does anybody know what are the requirements for the moveToElementEditbalePosition to work?
The last time that i checked my input was a SPAN Element.
http://docs.ckeditor.com/#!/api/CKEDITOR.dom.range-method-moveToElementEditablePosition
Or is there a more secure(cross-browser) solution?
==== edit ====
I found an error, And it's coming from the new CKEDITOR.dom.range
TypeError: b is undefined
This means that editor.document is empty, but when i look in the editor.document it's filled?
When i'm trying to set the range a second time after the error also it shows the following error: uncaught exception: DOMException: INVALID_STATE_ERR
Try this HTML:
<p><span id="test">Text</span></p>
And this JS:
var e = CKEDITOR.instances.editor1;
var span = e.document.getById( 'test' );
var range = e.createRange();
range.moveToElementEditablePosition( span, 1 );
range.select();
e.insertText( 'FOO' );
range.moveToElementEditablePosition( span );
range.select();
e.insertText( 'BAR' );
The result seems to be correct:
<p><span>BARTextFOO</span></p>
Do you have any other cases?