k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: "Rosu, Grigore" <grosu AT illinois.edu>
- To: "Guth, Dwight" <dguth2 AT illinois.edu>, Daniele Filaretti <dfilaretti AT gmail.com>, "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
- Subject: Re: [K-user] resolving variable names inside double quoted strings (as in PHP)
- Date: Fri, 1 Feb 2013 14:00:30 +0000
- Accept-language: en-US
- List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
- List-id: <k-user.cs.uiuc.edu>
Thanks Dwight, but let's face it: we cannot prolong this for too long
anymore, we need to provide full lexing support in the tool. SDF already
does it, so it is only a matter of wrapping it up. Radu, we can use the
syntax that we discussed a couple of months ago, something like this if I
remember correctly:
syntax MyID ::= Token("[A-Za-z$#][0-9A-Za-Z]*")
This should not be too hard to support, although I let Radu speak for that,
because there are several parsers that need to be convinced to work.
Grigore
________________________________________
From:
k-user-bounces AT cs.uiuc.edu
[k-user-bounces AT cs.uiuc.edu]
on behalf of Guth, Dwight
[dguth2 AT illinois.edu]
Sent: Friday, February 01, 2013 7:41 AM
To: Daniele Filaretti;
k-user AT cs.uiuc.edu
Subject: Re: [K-user] resolving variable names inside double quoted strings
(as in PHP)
I actually just implemented a very similar feature in my python semantics
concerning str.format. As part of that I implemented some custom string
processing functions that you may find useful. It allowed me to very cleanly
iterate through the string, pause at each escape character, and write a rule
that customizes the behavior for each one. You are welcome to take a look at
it as soon as I push my commit upstream later today to
http://code.google.com/p/k-python-semantics/source/browse/python-semantics-strings.k
If you like the solution you're free to use as much or as little of my code
as you want. You're free to ask me any questions you have about the code too.
Daniele Filaretti
<dfilaretti AT gmail.com>
wrote:
Hi all,
In PHP (the language I'm trying to define in K) when a variable name occurs
in a string (variable names always start with $) the value of that variable
is found in the environment and printed into the string. For example:
> $x = "Daniele";
> echo "Hello $x!"
>
> out>> "Hello Daniele!"
Until now I ignored this in my definition - i.e., I'm using builtin strings
that K offer, and I can achieve the same with (that is also legal in PHP):
> $x = "Daniele";
> echo "Hello " . $x . "!"
>
> out>> "Hello Daniele!"
However, I noticed that the feature is heavily used (of course, as it's a
very handy shortcut), so I decided to add it.
I'm currently having a look at the C definition by Chucky Ellison, as I think
something similar has to be done for C's 'printf". However, it seems that
their solution is very low level (scanning a string character by character
and defining some kind of state machine I guess), and perhaps I don't need
that level of detail.
Ideally, all I need is just something like a string tokenizer.
For example if my string is
> "Hello $x!"
I would like to obtain a list (containing strings and variables) :
> ["Hello", $x, "!"]
with this list I could easily print the elements that are already strings,
and evaluate the variable names before printing them as well (using my
already defined printing function for strings -- sending to it the elements
of my list one by one).
Any ideas? Comments? Suggestions?
Thanks a lot to everyone!
Cheers,
Daniele
_______________________________________________
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] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Guth, Dwight, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Rosu, Grigore, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Radu Mereuta, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Radu Mereuta, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Rosu, Grigore, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Mark Hills, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Guth, Dwight, 02/01/2013
Archive powered by MHonArc 2.6.16.