Skip to Content.
Sympa Menu

k-user - [[K-user] ] CellBags & Functions minimal example

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

[[K-user] ] CellBags & Functions minimal example


Chronological Thread 
  • From: <isaacdefrain AT gmail.com>
  • To: k-user AT lists.cs.illinois.edu
  • Subject: [[K-user] ] CellBags & Functions minimal example
  • Date: Tue, 22 Oct 2019 09:42:18 -0500

Hello again,

I recently asked about cellbags and functions and have since produced a
minimal example which demonstrates the idea I'm hoping to capture and gives
rise to the same error as before.

Basically, I would like to define a function which directly uses the contents
of a CellBag as input, but I always get a compilier error.

Here's the example:

// CellBag Function minimal example
require "domains.k"

module CELLBAG-SYNTAX
import DOMAINS

syntax Term ::= Int
| "[" Terms "]"
| "SumBeta" [token]
syntax Terms ::= Term
> Term "," Terms [right]

syntax KItem ::= Int

endmodule

module CELLBAG
import CELLBAG-SYNTAX

configuration
<T>
<k> $PGM:Term </k>
<alpha>
<beta multiplicity="*">
.K
</beta>
</alpha>
</T>

syntax KResult ::= Int

syntax BetaCell
syntax BetaCellBag

// add Term list contents to <beta/> cells
rule <k> [I:Int , T:Terms] => [T] ...</k>
(.Bag => <beta> I </beta>)
// call SumBeta at the end
rule <k> [I:Int] => SumBeta ...</k>
(.Bag => <beta> I </beta>)

// sum contents of <beta/> cells
rule <k> SumBeta => sum(B) </k>
<alpha> B => .Bag </alpha>

// sum contents of <beta/> cells
syntax Int ::= "sum(" BetaCellBag ")" [function]
rule sum( .BetaCellBag ) => 0
rule sum( <beta> I:Int </beta> B:BetaCellBag ) => I +Int sum(B)

endmodule

Kompiling results in the error:
[Error] Compiler: Had 1 parsing errors.
[Error] Inner Parser: Parse error: unexpected token 'B'.
Source(path/to/cellbag.k)
Location(50,34,50,35)

This error is due to the second rule for the "sum" function (i.e. `rule
sum( <beta> I:Int </beta> B:BetaCellBag ) => I +Int sum(B)`). If instead, this
rule is changed to `rule sum( <beta> I:Int </beta> ) => I`, there is no
compilation error and programs execute as expected.

I am using the Java backend to kompile and RV-K version 1.0-SNAPSHOT
Git revision: 1e310cd
Git branch: UNKNOWN
Build date: Thu Jan 31 03:38:17 EST 2019

I would greatly appreciate any insights you may have! Thank you.

Best,

Isaac


  • [[K-user] ] CellBags & Functions minimal example, isaacdefrain, 10/22/2019

Archive powered by MHonArc 2.6.19.

Top of Page