Skip to Content.
Sympa Menu

k-user - Re: [K-user] 'include' statement

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] 'include' statement


Chronological Thread 
  • From: "Guth, Dwight" <dguth2 AT illinois.edu>
  • To: Daniele Filaretti <daniele.filaretti AT gmail.com>, "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: Re: [K-user] 'include' statement
  • Date: Wed, 22 May 2013 18:59:21 +0000
  • Accept-language: en-US
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi, please consider the following code. It might not do exactly what you
want, but it captures the general idea and should illustrate to you the
features you will need to use to implement this:

syntax Stmt ::= "require" String
rule require S:String => #parse(readFile(#open(S)), "Stmt")

syntax String ::= readFile(Int) [function]
syntax Int ::= "BUFFER_SIZE"
rule BUFFER_SIZE => 1000 [macro]
rule readFile(Fd:Int) => readFile(#fReadBytes(Fd, BUFFER_SIZE), Fd)
syntax String ::= readFile(K, Int) [function]
rule readFile(S:String, Fd) => S +String readFile(Fd)
rule readFile(#EOF, Fd) => closeFile(#close(Fd))
syntax String ::= closeFile(K) [function]
rule closeFile(.K) => ""

Everything except the first two lines of this code fragment consists of code
designed to read a file given a file descriptor, close the file, and return a
String of its contents. The first rule then opens the file given a path,
calls the readFile function to get a string back, and then tells the K
framework to parse it as a term of sort Stmt and return it as a term. The
term will then be at the top of the K cell and get evaluated according to
your semantics. If you need to do something different with the term, you can
equally well put #parse inside another piece of syntax and provide whatever
semantics to that syntax you choose.
________________________________________
From:
k-user-bounces AT cs.uiuc.edu

[k-user-bounces AT cs.uiuc.edu]
on behalf of Daniele Filaretti
[daniele.filaretti AT gmail.com]
Sent: Wednesday, May 22, 2013 1:44 PM
To:
k-user AT cs.uiuc.edu
Subject: [K-user] 'include' statement

Hi all,
is there a builtin function that make it possible to simulate 'include' or
'require' functionalities in a language? (i.e. something that takes a
filename, parse the content and put the result into the current file)

I'm sure there is (at least in the C semantics, and in Java --- I'm having a
look at the code but I cannot find where the import in done :/)

Thanks a lot,

Daniele
_______________________________________________
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