I'm working on lesson 10 of the K introduction. Can't figure out an error I'm getting. I have the file lesson-10.k with the following contents (simplified for now to demonstrate the error):
module LESSON-10
imports STRING
syntax String ::= nonsentence(String) [function]
rule nonsentence(S) => substrString(S, 0, 5)
rule nonsentence(_) => " ." [owise]
endmodule
When I try to compile it as follows:
kompile lesson-10.k
I get this error - compiler seems to be flagging the argument 0 to substrString as unexpected:
[Error] Inner Parser: Scanner error: unexpected character sequence '0'.
Source(/home/bhandalc/k/lesson-10/lesson-10.k)
Location(5,42,5,43)
[Error] Compiler: Had 1 parsing errors.
I'm working on WSL with Ubuntu focal.
...Ah I got it. I wasn't importing
INTso it didn't know what0was. Fixed code:I was initially still a little bit confused by this because I thought "Surely
STRINGneedsINTto define the substring function in the first place?"Then I saw this in the K User Manual:
And indeed, the
INTimport is private inSTRING-COMMON:...And
STRINGitself is built atopSTRING-COMMON:So importing
STRINGwon't just bring in theINTmodule for you. You need to do it yourself.