Skip to Content.
Sympa Menu

k-user - Re: [K-user] Reading tuples in K

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] Reading tuples in K


Chronological Thread 
  • From: Traian Florin Şerbănuţă <traian.serbanuta AT gmail.com>
  • To: "Rosu, Grigore" <grosu AT illinois.edu>
  • Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>, Nick Vrvilo <Nick.Vrvilo AT rice.edu>
  • Subject: Re: [K-user] Reading tuples in K
  • Date: Wed, 21 Nov 2012 21:03:33 +0200
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi Nick,

as it currently stands, if asked to read a string, K would indeed read a token, that is every character until the first space, tab, or newline.
If that doesn't work for you, you can try reading the input character by character, and parsing it yourself, maybe using the implemented functionality of the parse functions

For example, this would be the rule for reading a single character
<k> readchar => C ...</k>  <in> C:Char => . ...</in>
note that this rule would actually read whitespace, too.
I agree that doing it this way is not much better than writing the parser in C, but there wasn't much need for this until now.

Now, there also is an work-in-progress project which would allow you to parse the input according to the defined syntax of the language, (by calling the parser on the input) which would probably be the nicest way to obtain what you want, but I never seem to have enough time to finish it.

best wishes,
- traian


2012/11/21 Rosu, Grigore <grosu AT illinois.edu>
Hi Nick,

Thanks for your message and for playing out with K.  It is definitely better to ask this sort of questions on the k-user list, because many others may have run into the same issue and they would give you better answers than I can give you.

You may try out the examples/simple language, and particularly the program matrix.simple, as that uses a lot of I/O.  It basically reads a matrix row by row.

As far as I know, if nobody added support for it in K (there are about 8 people actively writing code for the K tool, I lost track of it), you can only match integer values in the input stream.  But I'm not sure, so that's why it is always better to ask such questions on the k-user list.  Also, when you feel like something is a bug, or a missing feature, feel free to use the Issues tab and add a new issue.

Thanks,
Grigore
 
 

From: Nick Vrvilo [Nick.Vrvilo AT rice.edu]
Sent: Wednesday, November 21, 2012 12:36 PM
To: info AT k-framework.org
Subject: Reading tuples in K

My name is Nick Vrvilo. I'm a grad student in the PhD program of the CS department at Rice University. I've recently been trying to use the K Framework to model the semantics of a runtime system related to my masters thesis research, but I've run into a bit of a roadblock.

The tutorial for IMP++ shows how to read a number into your program from stdin, but I haven't been able to get the same thing to work for an integer tuple. Basically, I'd like to be able to read a term like "(1, 2, 3)"—but an arbitrary n-tuple, not necessarily a 3-tuple. The issue is that the [read] command seems to only read in the first token, which in this case seems to be "(1," or something like that.

It looks like there are some #parse functions in the K implementation—and I think that using something like that might be the right answer. If I were to put each tuple on its own line in the input, then I could just use something like readline to get a string and then pass that string to one of these parsing functions to get my tuple—but I have no idea how I would do that. It's also very possible that I'm approaching this completely wrong, and I'm very open to your suggestions here.

Please let me know if you think this would be better if submitted to the user list instead.

Thank you!

Nick Vrvilo



  • Re: [K-user] Reading tuples in K, Traian Florin Şerbănuţă, 11/21/2012

Archive powered by MHonArc 2.6.16.

Top of Page