k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: Radu Mereuta <headness13 AT gmail.com>
- To: Daniele Filaretti <dfilaretti AT gmail.com>
- Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
- Subject: Re: [K-user] parsing error?
- Date: Thu, 7 Feb 2013 18:27:15 +0200
- List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
- List-id: <k-user.cs.uiuc.edu>
Regarding that escaping thing... that's a bit tricky. We are still thinking how to do that.
You could try a trick for now. You can declare two productions and say that they have the same label. In the backend they will overlap and provide the same functionality. So you can do something like this:
module TEST-SYNTAX
syntax Exp ::= Exp "=>" Exp [onlyLabel, klabel('rewrite)] // onlyLabel says that this production will only be used in programs
endmodule
module TEST
syntax Exp ::= Exp "==>" Exp [klabel('rewrite)] // synchronized with the one above
rule A ==> B => A + B // in rule you use the production above
endmodule
The parser for programs will use only what is defined in TEST-SYNTAX (and included modules). This way you can create a clean parser for your language. But because it will produce ambiguities in the definition, you can rename the operation for the rule parser by redeclaring it in the TEST module.
This is what we currently use, and we are passively looking for improvements.
Radu
On Thu, Feb 7, 2013 at 12:09 PM, Daniele Filaretti <dfilaretti AT gmail.com> wrote:
On 6 Feb 2013, at 19:11, Radu Mereuta <headness13 AT gmail.com> wrote:Now an explanation for Daniele:You are right, you don't need a relation between 'fcall' and 'array' because they cannot cause ambiguities. Problems start to appear when you have combinations with binary operators. Example:
syntax Exp ::= Exp "+" Exp | Exp "[" Exp "]"An input of the form: "a + b [ c ]" is ambiguous because it can be parsed in two ways: (a + b) [ c ] and a + (b [ c ])A priority filter in SDF (we implemented a similar system in SDF) is a simple function that traverses the parse forest and rejects erroneous branches. For the example above we will have:
amb( _[_](_+_(a, b), c),_+_(a, _[_](b, c)))To solve this you can add in K a relation like this:syntax priorities _[_] > _+_ // or 'syntax priorities array > plus' if you tag your productions with array and plus.The filter will look at that relation and whenever finds plus as a parent of array, will reject that branch.
What was happening in your example was that you had a relation between two productions that would reject the tree that you actually wanted.In your example you could use the verbose way of specifying precedences using tags. Remember though that the priority relation is transitively closed.
Radu, thanks for your explanation, I think I got the point.Actually, I find quite hard to manage all of the precedences. For example, I initially just added the obvious ones like multi > add etc, using thesyntax…| stuff| mult> add| sub| stuff….and then I started adding new productions (e.g. the ones for array etc.), some at the top, some at the bottom… That's how I eventually discovered to have unwanted precedences.I'll try to do as you said (using "syntax priorities …"), it should be better.I agree. The tutorial and the examples are an excellent resource for learning K, but eventually experienced users would benefit more from a proper user manual, so that they can just look for a particular information or command.Also we have some problems with the documentation. I think you would have had a much better time if we would have explained in details the way the parser works. We are also working on a manual.
Well, this is not related to the previous question: any idea on how to escape sequences in K? More in particular, any idea on how to escape "=>"?Meanwhile feel free to ask us anything you don't find clear. We take users feedback very serious. Many of the tools features have been requested and shaped by users feedback.It is used in my language (PHP) to define arrays (that are really kind of dictionaries, not arrays in the traditional sense):$x = ["foo" => 1,4 => 0]I'm currently using "==>" instead of "=>" but would be nice to fix it.Anyway, thanks as usually for the quick and helpful answers! :)DanieleOn Wed, Feb 6, 2013 at 8:38 PM, Rosu, Grigore <grosu AT illinois.edu> wrote:
Don't worry, Daniele, parsing confuses us all.
However, your example raises an interesting point: we should probably use the filters only when we have ambiguities, not all the times. I think Radu is just using SDF out-of-the-box, so if SDF applies the filters all the time then so does K. Radu, would it be posssible to change the way we apply the ambiguity filters?
Grigore
From: k-user-bounces AT cs.uiuc.edu [k-user-bounces AT cs.uiuc.edu] on behalf of Daniele Filaretti [dfilaretti AT gmail.com]
Sent: Wednesday, February 06, 2013 12:34 PM
To: Radu Mereuta
Cc: k-user AT cs.uiuc.edu
Subject: Re: [K-user] parsing error?
On 6 Feb 2013, at 18:19, Radu Mereuta <headness13 AT gmail.com> wrote:
Are you sure you don't have a priority relation between fcall and array? That might reject the correct parsing tree, and would explain why it works with [bracket].
Oh, well, in fact I had a precedence (I forgot to mention in my question).It wasExp[Exp] > Id (Exps)
And yes, if I remove the precedence it works.To be honest I don't understand why, parsing issues always confuse me :)(I mean, my _expression_ -- foo()[0] is an Exp[Exp]. And Exp[Exp] has the precedence. So there should not be any ambiguity I guess?)
Anyway, thanks a lot!
Cheers,Daniele
On Wed, Feb 6, 2013 at 8:06 PM, Daniele Filaretti <dfilaretti AT gmail.com> wrote:
Hi all,
here is another question for you K hackers!
Let say my grammar contains something that looks like
> syntax Exp ::=
> …
> | Id "(" Exps ")" // function call
> | Exp "[" Exp "]" [seqstrict] // reading a field from an array (the first Exp must evaluate to an array value, the second to a key value)
> …
and suppose I write a function, "foo()" that returns an array. Now, if in my program I write something like
> foo()[0];
I get a parsing error:
> [Error] Critical: Parse error: Syntax error near unexpected character ';'
> File: test.php
> Location: (5,9,5,9)
As an experiment, I tried to add
> syntax Exp ::= "(" Exp ")" [bracket]
and then, if I evaluate
> (foo())[0]:
it works!
Am I missing something or is a parsing problem?
Thanks a lot!
Cheers,
Daniele
_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user
- [K-user] parsing error?, Daniele Filaretti, 02/06/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/06/2013
- Re: [K-user] parsing error?, Daniele Filaretti, 02/06/2013
- Re: [K-user] parsing error?, Rosu, Grigore, 02/06/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/06/2013
- Re: [K-user] parsing error?, Daniele Filaretti, 02/07/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/07/2013
- Re: [K-user] parsing error?, Daniele Filaretti, 02/08/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/07/2013
- Re: [K-user] parsing error?, Daniele Filaretti, 02/07/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/06/2013
- Re: [K-user] parsing error?, Rosu, Grigore, 02/06/2013
- Re: [K-user] parsing error?, Daniele Filaretti, 02/06/2013
- Re: [K-user] parsing error?, Radu Mereuta, 02/06/2013
Archive powered by MHonArc 2.6.16.