Problem with the lookup in a Map to get the value of a stored variable

54 Views Asked by At

I am facing an issue when I try to do a lookup to get the value of a variable stored in an env configuration which is a Map (common pattern). Here is the extracted code why the syntax and the rewriting rule that create the issue:

syntax Exp
       ::= Id
     | Value
     | "read" "(" Exp ")"

syntax Value
       ::= ...
         | #loc(Int)

rule <k> read ( X:Id ) => read ( #loc( L )  ) ... </k>
     <env> ... X |-> L ... </env>

When I krun a little program, it become stuck in this configuration:

 <k>
    read ( x ) ~> #freezer_;_OSL-SYNTAX_Stmt_Exp0_ ( ) ~> .Stmts ~> .
 </k>
 <env>
    x |-> 0
    y |-> 2
 </env>

I expect that read(x) will be rewriting in read(#loc(0)), but the rule is not applied. If I comment the env configuration requirement in the rule and replace L by the constant 0, the rule can be apply:

rule <k> read ( X:Id ) => read ( #loc( 0 )  ) ... </k>
//     <env> ... X |-> L ... </env>

And I got a termination . (because other rule will handle the read(#loc(0)) after this one)

<k>
     .
</k>
<env>
     x |-> 0
     y |-> 2
</env>

I also tried to use this syntax from this documentation here

rule <k> read ( X:Id ) => read ( #loc( Env[X] )  ) ... </k>
     <env> Env:Map </env>

But I get a parsing error

[Error] Inner Parser: Parse error: unexpected token '['.
    Source(/home/alessio/Project/osl/model/./osl.k)
    Location(156,43,156,44)

Do you have an idea for debugging this?

0

There are 0 best solutions below