Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

"end of list" token ambiguity #2386

Open
incud opened this issue Dec 18, 2017 · 1 comment
Open

"end of list" token ambiguity #2386

incud opened this issue Dec 18, 2017 · 1 comment

Comments

@incud
Copy link

incud commented Dec 18, 2017

Consider the language which parses a list of integer followed by a list of strings. Here the code (lists.k)

module LISTS-SYNTAX
	syntax ListA ::= List{Int, ","} [strict]
	syntax ListB ::= List{String, ","} [strict]
	syntax Program ::= ListA ListB
endmodule

module LISTS
	imports LISTS-SYNTAX
	configuration 
	<T>
		<k> $PGM:Program </k>
	</T>
	rule A:ListA B:ListB => A ~> B [structural]
	rule <k> ( N:Int, A:ListA => A ) ... </k>
	rule <k> ( .ListA => .K ) ... </k>
	rule <k> ( S:String, B:ListB => B ) ... </k>
	rule <k> ( .ListB => .K ) </k>
endmodule

and the following example file (example.lists)

1, 2, 3, 4
"b", "c", "d"

The code compiles correctly with kompile lists.k. When executing it with krun example.lists --debugger you can see this state

$ kompile lists.k
$ krun example.lists --debugger
KDebug> p
initTCell ( .Map $STDIN |-> "
" $IO |-> "off" $PGM |-> ( ( 1 , ( 2 , ( 3 , ( 4 , .ListA ) ) ) ) ( "b" , ( "c" , ( "d" , .ListA ) ) ) ) )
KDebug> 

While the .ListA after number 4 is correct, the .ListA after "d" is not. It should be .ListB. Obviously they will also match different rules. Here the code: lists.tar.gz

@radumereuta
Copy link
Member

Try adding klabels to your lists. The automatic klabel generation doesn't look for collisions and in this case krun gets confused.

syntax ListA ::= List{Int, ","} [strict, klabel(IntList)]
syntax ListB ::= List{String, ","} [strict, klabel(StringList)]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants