k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: "Guth, Dwight" <dguth2 AT illinois.edu>
- To: Daniele Filaretti <dfilaretti AT gmail.com>
- Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>, Daniele Filaretti <daniele.filaretti AT gmail.com>
- Subject: Re: [K-user] 'include' statement
- Date: Wed, 22 May 2013 20:43:15 +0000
- Accept-language: en-US
- List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
- List-id: <k-user.cs.uiuc.edu>
Can you please run "kompile -version" and paste the output here? It sounds
like you have an outdated version of the framework, so I would like to know
for sure what version you have before I try to debug why that is happening
even though you think you have the latest. If you could also tell me exactly
what steps you took to obtain the release you are using, that would be great.
________________________________________
From: Daniele Filaretti
[dfilaretti AT gmail.com]
Sent: Wednesday, May 22, 2013 3:31 PM
To: Guth, Dwight
Cc: Daniele Filaretti;
k-user AT cs.uiuc.edu
Subject: Re: [K-user] 'include' statement
On 22 May 2013, at 20:38, "Guth, Dwight"
<dguth2 AT illinois.edu>
wrote:
> The #parse command makes use of whatever parser you pass as a flag with
> --parser. It also sets the sort information provided as its second argument
> on the command line as the envirionment variable "KRUN_SORT". So if I say:
>
> krun programName --parser "parserName"
>
> and programName contains a require statement that calls #parse, it will
> call parserName with the string you passed to #parse and set the KRUN_SORT
> variable with the sort you passed to #parse. So it should work, and if you
> want to read that environment variable in your external parser and parse
> differently based on its value, you can.
>
> There is one caveat here though. If your external parser takes the name of
> a file on the command line and outputs the AST on stdout, you will need to
> make a slight adjustment to it in order for this to work. There is in
> general no great way of deciding whether or not a particular external
> parser takes the name of a file or the contents of a program itself (since
> the two are, from the perspective of krun, indistinguishable). So it's the
> job of the external parser to be able to handle the program itself being
> passed on the command line if necessary, because the #parse command calls
> the external parser with exactly one argument, which is the string of the
> text to be parsed. This is done by means of another environment variable,
> KRUN_IS_NOT_FILE, which is set to the string "true". You will need to
> modify your external parser to check the value of this environment
> variable, and if it is present with the value "true", treat the argument
> passed to the parser as text to be parsed, rather than as a filename.
What version of K are you using? The latest stable I guess? I'm using the
latest build and it doesn't work. In particular it seems that '#fReadBytes'
doesn't exists (I inspected k/include/modules/uris.k), while with '#parse()'
I got an 'unexpected end of rule' error (even if '#parse' seems to exists).
Thanks for the info and explanation, it's very useful - I'll work more on it
when I'll have some time.
Daniele
> ________________________________________
> From: Daniele Filaretti
> [dfilaretti AT gmail.com]
> Sent: Wednesday, May 22, 2013 2:21 PM
> To: Guth, Dwight
> Cc: Daniele Filaretti;
> k-user AT cs.uiuc.edu
> Subject: Re: [K-user] 'include' statement
>
> Nice, thanks!
>
> But I actually forgot to mention an important detail: I'm using an external
> parser? Will it work? I haven't tried yet.
>
> Daniele
>
> On 22 May 2013, at 19:59, "Guth, Dwight"
> <dguth2 AT illinois.edu>
> wrote:
>
>> 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
- [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
- Re: [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
- Re: [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
- Re: [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
- Re: [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
- Re: [K-user] 'include' statement, Daniele Filaretti, 05/22/2013
- Re: [K-user] 'include' statement, Guth, Dwight, 05/22/2013
Archive powered by MHonArc 2.6.16.