Skip to Content.
Sympa Menu

k-user - Re: [[K-user] ] How to create a cell to keep track of program counter?

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [[K-user] ] How to create a cell to keep track of program counter?


Chronological Thread 
  • From: Rikard Hjort <benparad AT hotmail.com>
  • To: Ayushi Rastogi <rastogiayushi98 AT gmail.com>, "k-user AT lists.cs.illinois.edu" <k-user AT lists.cs.illinois.edu>
  • Subject: Re: [[K-user] ] How to create a cell to keep track of program counter?
  • Date: Tue, 25 Jun 2019 13:32:36 +0000
  • Accept-language: sv-SE, en-US
  • Authentication-results: illinois.edu; spf=pass smtp.mailfrom=benparad AT hotmail.com; dkim=pass header.d=hotmail.com header.s=selector1; dmarc=pass header.from=hotmail.com

How about this?

File: string-inc.k

module STRING-INC
  imports DOMAINS

  configuration
    <k> $PGM:Stmts </k>
    <count> "" </count>

    syntax Stmts ::= List{Stmt, ""}
    syntax Stmt  ::= "add" String
 // -----------------------------
    rule .Stmts => .
    rule S:Stmt SS:Stmts => S ~> SS
    rule <k> add VARNAME => . ... </k>
         <count> S => S +String VARNAME </count>
endmodule

Example program:
File: string-inc-example

add "foo"
add "bar"

On the command line:

$ kompile string-inc.k
[Warning] Compiler: Could not find main syntax module with name
STRING-INC-SYNTAX in definition.  Use --syntax-module to specify one. Using
STRING-INC as default.
$ krun string-inc-example
<generatedTop>
  <k>
    .
  </k>
  <count>
    "foobar"
  </count>
</generatedTop>


On 6/25/19 6:17 AM, Ayushi Rastogi wrote:
> Respected Sir/Mam
>
> I am trying to define my own cell called program counter that keeps a value
> of
> string type and behaves similarly to a variable of string type that updates
> a
> value by concatenation of an identifier.
>
> Thank you
> Ayushi




Archive powered by MHonArc 2.6.19.

Top of Page