Skip to Content.
Sympa Menu

k-user - Re: [K-user] file read/write

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] file read/write


Chronological Thread 
  • From: "Park, Daejun" <dpark69 AT illinois.edu>
  • To: "Adams, Michael" <adamsmd AT illinois.edu>
  • Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: Re: [K-user] file read/write
  • Date: Fri, 8 Nov 2013 16:44:28 +0000
  • Accept-language: en-US
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi Michael,

It seems that your K cannot open the "file". '#open("file")' should be evaluated to a file descriptor--an integer. I don't know why it happens. Maybe you need another person's help.

Anyway, this is my complete example: (nothing different..)

$ cat a.k
module A
 syntax Pgm ::= "run"
 configuration <k> $PGM:Pgm </k>

 rule <k> run => writeFile("file", "content\n") ... </k>

 syntax K ::= writeFile(String,String)
 rule writeFile(File:String, Content:String)
   => writeFD(#open(File), Content)

 syntax K ::= writeFD(Int,String)
 rule writeFD(FD:Int, Content:String)
   => #write(FD, Content) ~> #close(FD)
endmodule

$ cat 1.a
run

$ kompile a.k
$ krun 1.a
<k>
    .K
</k>
$ cat file
content

Thanks,
Daejun

On Nov 8, 2013, at 9:17 AM, Michael D. Adams <adamsmd AT illinois.edu> wrote:

What I try to do that, the configuration gets stuck with:

<k>
   #write ( (#open ( "file" )) , "content" ) ~> #close ( (#open ( "file" ))
     )
</k>

Have you gotten it to not get stuck?  Could you post a complete example (including commandlines)?

On 11/01/2013 09:03 PM, Park, Daejun wrote:
Hi Michael,

If you want to write something to a file at once,  you can go with  #open and  #write .

For example,

  rule <k> run => writeFile("file", "content") ... </k>

  syntax K ::= writeFile(String,String)
  rule writeFile(File:String, Content:String)
    => writeFD(#open(File), Content)

  syntax K ::= writeFD(Int,String)
  rule writeFD(FD:Int, Content:String)
    => #write(FD, Content) ~> #close(FD)

I'll get back to you after figuring out how to read from a file.

Daejun

On Nov 1, 2013, at 12:54 PM, Michael D. Adams <adamsmd AT illinois.edu> wrote:

If you figure out how to do this, let me know.  I need it in the AST generator.

For my use, it would be nice if we had some high-level functions like Haskell's readFile and writeFile that read or write the entire file in one go.

On 11/01/2013 12:52 PM, Park, Daejun wrote:
Thank you very much, Brandon!!

Daejun

On Nov 1, 2013, at 12:43 PM, "Moore, Brandon Michael" <bmmoore AT illinois.edu>
 wrote:

The first thing grep suggests is
tests/regression/java-rewrite-engine/io/test1
None of the tutorials or samples call #open.

Brandon
________________________________________
From: k-user-bounces AT cs.uiuc.edu [k-user-bounces AT cs.uiuc.edu] on behalf of Park, Daejun [dpark69 AT illinois.edu]
Sent: Friday, November 01, 2013 12:35 PM
To: k-user AT cs.uiuc.edu
Subject: [K-user] file read/write

Hi all,

Is there an easy way to read/write a file in K?
While dealing with stdin/stdout is very simple, how can I do such a thing for a file?
I'd appreciate it if you give a pointer to an example.

Thanks,
Daejun
_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user



_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user


_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user






Archive powered by MHonArc 2.6.16.

Top of Page