k-legacy icon indicating copy to clipboard operation
k-legacy copied to clipboard

How can I get a kompilable kast for a program?

Open dlucanu opened this issue 10 years ago • 2 comments

The following was sent on k-list. Since I didn't receive an answer yet, I include it here for recording.

I would like to write a rule of the form

rule funs =>

I used the "kast" program to get the kast of a particular program:

$ ~/k-3.6/bin/kast -e "two() { return 2; }" --parser "program"

'_(_){_}(#token("two", "Id"),'.List{"'_,_"}(.::KList),'return_;(#token("2", "#Int")))

Then I included in my definition the following rule:

rule funs

   =>

   `'_(_){_}`(#token("two", "Id"),`'.List{"'_,_"}`(.::KList),`'return_;`(#token("2", "#Int"))) 

and I got the following kompilation error:

$ ~/k-3.6/bin/kompile alk.k

[Error] Critical: Parse error: Syntax error near unexpected character '`'

Source(./../packages/compgeom.k)

Location(9,8,9,8)

The line 9 is the line including the rhs of the above rule.

So, the question is: "Having a definition in K, how can I obtain the kast of a given program s.t. I can copy-paste it in another K definition?"

This is useful, e.g., for loading libraries of programs.

For teaching purposes I still using K 3.6.

dlucanu avatar Mar 14 '16 09:03 dlucanu

The KAST seems to be using the backtick syntax. That was introduced in K 3.6 but we decided against it in K 4.0. As far as I know, we never got to a point where we had a working roundtrip, printing a definition and being able to parse it back in K 3.6. This would likely work better in K 4.0, as we highly encourage you to use it if at all possible -- Elsa Gunter is also using it for teaching the Programming Language Design course at UIUC this semester.

My best advice right now would be to try to fix each case manually. @radumereuta, do you have any idea why the above doesn't work?

cos avatar Mar 14 '16 13:03 cos

I expected that the kast generated with 3.6 can be compiled with K 3.6, but it seems that it doesn't. When I started the teaching, K 4.0 was not released and therefore I preferred the last stable released version. The definition I use for teaching is quite complex and needs a significant effort to switch to K 4.0 and I have no time now. I will do it for the next year. Now I need a simple and stable solution that can be used by several hundreds of bachelor students in the first year.

dlucanu avatar Mar 14 '16 14:03 dlucanu