Skip to Content.
Sympa Menu

k-user - Re: [K-user] Unsupported sort of fresh variable

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] Unsupported sort of fresh variable


Chronological Thread 
  • From: Omar Duhaiby <3omarz AT gmail.com>
  • To: Andrei Stefanescu <andreistef AT gmail.com>
  • Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>, "Musab A. AlTurki" <musab AT kfupm.edu.sa>
  • Subject: Re: [K-user] Unsupported sort of fresh variable
  • Date: Tue, 18 Nov 2014 13:08:14 +0300
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

I did exactly like k-distribution/include/builtins/id.k and I created a module for my lower case Identifier, called it LCId:


    syntax LCId ::= Token{[a-z][\_a-zA-Z0-9]*}       [notInRules]
    syntax String ::= "LCId2String" "(" LCId ")"         [function, hook(#CONVERSION:token2string), klabel(LCId2String)]
    syntax LCId ::= "String2LCId" "(" String ")"         [function, hook(#CONVERSION:string2id), klabel(String2LCId)]
    rule LCId2String(X:LCId) => #tokenToString(X)
    rule String2LCId(S:String) => #parseToken("LCId", S)
    syntax LCId ::= freshLCId(Int)    [freshGenerator, function]
    rule freshLCId(I:Int) => String2LCId("var_" +String Int2String(I))

And it's working.
Thank you

On Mon, Nov 17, 2014 at 11:55 PM, Andrei Stefanescu <andreistef AT gmail.com> wrote:
You should use !NewVar:LowerCaseId as you initially did, you should not call the function directly. The framework will call the function for you, with an appropriate value for the integer argument.

As for the function itself, you can use #parseToken to create a LowerCaseId from a String:
rule freshLowerCaseId(I:Int) => #parseToken("LowerCaseId", "_" +String Int2String(I))

You can take a look in k-distribution/include/builtins/id.k to see exactly how it is done for Id.

Andrei

On Mon, Nov 17, 2014 at 2:37 PM, Omar Duhaiby <3omarz AT gmail.com> wrote:
OK, I can make my own, but when I call it, I have to provide an Int. And using String2Id will always return a type Id. The compiler complains about that. The only way to do it that I can see is to keep a global Int that increments with each run of the rule.

On Mon, Nov 17, 2014 at 8:40 PM, Andrei Stefanescu <andreistef AT gmail.com> wrote:
Hi Omar,

The !X notation is syntactic sugar for a function that generates a "fresh" element given an integer argument. This is the function for Id (from builtins/id.k):
  syntax Id ::= freshId(Int)    [freshGenerator, function]
  rule freshId(I:Int) => String2Id("_" +String Int2String(I))
You can add you own for LowerCaseId in a similar way.

Let me know if I can help you further,

Andrei


On Sat, Nov 15, 2014 at 11:56 AM, Omar Duhaiby <3omarz AT gmail.com> wrote:
Hello,

I'm doing this:
rule E:Exp (0) => E -> !NewVar:LowerCaseId        [macro]

However, the compiler says "Only sorts [Id, Int] admit fresh variables". But I don't want to use Id because it can start with an upper case. My LowerCaseId starts only with a lower case. What should I do?

_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user








Archive powered by MHonArc 2.6.16.

Top of Page