Skip to Content.
Sympa Menu

k-user - Re: [[K-user] ] Match “_” in K

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [[K-user] ] Match “_” in K


Chronological Thread 
  • From: Radu Mereuta <headness13 AT gmail.com>
  • To: wang_feng_bro AT 163.com
  • Cc: k-user AT lists.cs.illinois.edu
  • Subject: Re: [[K-user] ] Match “_” in K
  • Date: Sat, 28 Jul 2018 22:34:14 +0300
  • Authentication-results: illinois.edu; spf=pass smtp.mailfrom=headness13 AT gmail.com; dkim=pass header.d=gmail.com header.s=20161025; dmarc=pass header.from=gmail.com

Hi,

"_" in K is viewed as an anonymous variable, and it can't be renamed.
It is fine to use it in your programs, but not in rules, so you need to separate them.

What you could do, is to split your modules: COMMON -> RUST-SYNTAX, RUST
Put most of the syntax in the common module, and only the stuff that looks like variables in the syntax module. (usually Ids and nullable productions).
Then in your semantics module, you can work with the labeled form.
If you really need to match on such an identifier, you can use the labeled form: #token("_", "Id"). (really not sure about the format here, it changed from version to version).

Radu



On Sat, Jul 28, 2018 at 6:47 PM, <wang_feng_bro AT 163.com> wrote:
Hi all,

I am working on Rust now. In Rust, we have “_” ( like default in C++ ) in match. For instance, 

let x = 1;
match x {
   1 => println!(“one”),
   2 => println!(“two”),
   _ => (),
}

In my implementation, "_ "will be recognized as type of Id in K I think and K will try to evaluate it. However,I already defined a rule:

 rule <k> X:Id => V ...</k> 
        <env>... X |-> L ...</env> 
        <store>... L |-> V ...</store> 

So, “_” can not be evaluated. I tried to defined “_” as a special token, but it didn’t work because many rules use “_”. Anyway, there are always conflicts. 

Any ideas ?

Jerry





Archive powered by MHonArc 2.6.19.

Top of Page