Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False error from KaSa: mod, tokens, <- #661

Open
hmedina opened this issue May 1, 2023 · 16 comments
Open

False error from KaSa: mod, tokens, <- #661

hmedina opened this issue May 1, 2023 · 16 comments
Assignees

Comments

@hmedina
Copy link
Collaborator

hmedina commented May 1, 2023

%agent: timer(s{tik, tok})		%init: 1 timer()
%token: io		%init: 0 io		%obs: 'io_o' |io|
%token: oi		%init: 0 oi		%obs: 'oi_o' |oi|

timer(s{tik/tok}) | 1 io @ 10
timer(s{tok/tik}) | 1 oi @ 10
%mod: [T] > 5 do io <- 0 ;
%mod: [T] > 10 do $STOP;

The UI static analyzer reports 1/1[model.ka] Incorrect beginning of sentence , with a red squiggly under the io in the first mod.

Ignoring this message and hitting play produces the expected model behavior.

This syntax was referred by #607
The verbose version of the syntax is tested in https://github.com/Kappa-Dev/KappaTools/blob/master/tests/integration/compiler/tokens/tokens.ka

@hmedina
Copy link
Collaborator Author

hmedina commented May 1, 2023

%mod: [T] > 5 do $SNAPSHOT ; io <- 0 ;

With compound perturbations, weird things occur. The snapshot is not present; and KaSim CLI will refuse to run the model...

@feret
Copy link
Contributor

feret commented May 2, 2023

Dear Hector,
The UI has never been adapted to KaSa error messages.
Most of them are badly reported without any relation with the alarm sent.
I will have to sort out and filter most of them out, while trying to understand how the UI is working.

@feret feret self-assigned this May 2, 2023
feret pushed a commit that referenced this issue May 7, 2023
@feret
Copy link
Contributor

feret commented May 7, 2023

%mod: [T] > 5 do io <- 0 ;
is rejected by KaSim, not KaSa.

@feret
Copy link
Contributor

feret commented May 7, 2023

This construction is not compliant with the klexer4/kparser4.
I have to update them accordingly.

@feret
Copy link
Contributor

feret commented May 8, 2023

I extended the lexer and the parser in a branch.
Then, the issue is that it created a shift/reduce conflict in the grammar.
I am not sure I know how to change it without changing the syntax.
Adding a keyword %foo would solve the issue.

Would it be OK with you @hmedina ?
If someone knows how to deal with the parser to remove the shift/reduce conflict, please feel free to contribute.

@hmedina
Copy link
Collaborator Author

hmedina commented May 9, 2023

It would be ok with my usage (assuming it's just adding some keywords to make the "update token Y to value X" statement less cryptic...)

To elaborate, since the UI rejected that syntax, none of my big models use tokens & perturbations, because I did not know what a valid syntax would be. I only stumbled into working syntax when building a comprehensive KaTIE test, so changing the syntax will only cost me the time to re-write tests here and there.

The maintainers for both Kappa manuals will need to update their respective works once the new syntax is defined.

@feret
Copy link
Contributor

feret commented May 10, 2023

I have solved the conflict by restricting a little bit the grammar.
Now
token <- alg
assignments are allowed if

a) the perturbation has a ending condition (repeat [ ])
as in %mod: [T] > 5 do io <- 0 repeat [true]

b) or if it is in a list of perturbations bounded by some parentheses.
as in %mod: [T] > 5 do (io <- 0)

Otherwise, it is not allowed.
For instance
%mod: [T] > 5 do io <- 0
is not OK.

@feret
Copy link
Contributor

feret commented May 10, 2023

Since, the suggestion is strictly more expressive than what is in the master branch I merge.

@pirbo
Copy link
Member

pirbo commented May 10, 2023

I'm not there anymore to do the maintenance so I don't have a voice but just to say:
You don't need any extra syntax to set a number of token to a given value in a %mod, you can simply $apply the rule that does that!

To remove all the io after 5 tu, you %mod: [T] > 5 do $APPLY 1 | -|io| io;

@feret
Copy link
Contributor

feret commented May 11, 2023

@pirbo, you will keep a voice on the development of KappaTools forever and we deeply respect your legacy.
Yet, I think that even if it can be encoded, a direct syntax is more understandable from a user perspectives.
Also it is important that the tools and the doc are coherent with respect to each other.

This is why I would prefer to add the new notation.
(Also the impact on the code is quite narrow, since it is replaced by your proposition in the yacc file).

@feret feret closed this as completed May 19, 2023
@hmedina
Copy link
Collaborator Author

hmedina commented May 19, 2023

This raises an issue with the repeat clause being optional & defaulting to false:

%mod: [T] > 5 do io <- 0 ;                  // rejected
%mod: [T] > 5 do ( io <- 0 ) ;              // rejected
%mod: [T] > 5 do io <- 0 ; repeat [false]   // accepted

The first statement is rejected; however I was under the impression it defaulted to the third statement. Should repeat clauses be always required? This would trigger issues like #643

@feret
Copy link
Contributor

feret commented May 25, 2023

Here what is accepted :
%mod: [T] > 5 do ( io <- 0 ) // rejected
%mod: [T] > 5 do io <- 0 ; repeat [false] // accepted

Shall I authorize / require a semicolon after (io <- 0) ?

@feret feret reopened this May 25, 2023
feret pushed a commit that referenced this issue May 25, 2023
@feret
Copy link
Contributor

feret commented May 25, 2023

%mod: [T] > 5 do io <- 0 ; // rejected
%mod: [T] > 5 do ( io <- 0 ) ; // accepted
%mod: [T] > 5 do ( io <- 0 ) // accepted
%mod: [T] > 5 do io <- 0 ; repeat [false] // accepted

@hmedina
Copy link
Collaborator Author

hmedina commented May 27, 2023

How should multi-pertubation statements be constructed?

In KaSimInBrowser (today's?), the following are rejected:

%mod: [T] > 5 do (io <- 0) ; (oi <- 0) ;
%mod: [T] > 5 do (io <- 0) ; (oi <- 0) ; repeat [false]
%mod: [T] > 5 do (io <- 0) (oi <- 0) ;
%mod: [T] > 5 do (io <- 0) (oi <- 0) ; repeat [false]

@feret
Copy link
Contributor

feret commented May 27, 2023

The way the grammar has been written, composite statements should be written as follows:
%mod: [T] > 5 do (io <- 0 ; oi <- 0) ;
%mod: [T] > 5 do (io <- 0 ; oi <- 0) ; repeat [false]

@hmedina
Copy link
Collaborator Author

hmedina commented May 29, 2023

Ok, so for documentation:

someone should update table 2.7 of the official Kappa manual

@plucky should update "Grammar 13: Intervention directives" in https://kappalanguage.org/sites/kappalanguage.org/files/inline-files/Kappa_Manual.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants