Skip to Content.
Sympa Menu

k-user - Re: [K-user] Ambiguity & context rules

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] Ambiguity & context rules


Chronological Thread 
  • From: Radu Mereuta <headness13 AT gmail.com>
  • To: Ulrich Kühne <ulrichk AT informatik.uni-bremen.de>
  • Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: Re: [K-user] Ambiguity & context rules
  • Date: Sat, 1 Jun 2013 11:23:07 +0300
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi Ulrich,

Regarding the parsing issue. You could try using the prefer/avoid attributes like this:
"return" Exp [prefer, strict]

Precedences disallows for one production to be the direct child of another. They are mostly designed for binary operators, but in this case the ambiguities are at the top between unrelated productions.

Regarding the context question. Have you looked at the tutorials? http://k-framework.org/index.php/K_Tutorial
If you still don't find the right answer, please tell us. We would like to know if something is not clear.

Radu
K developer.



On Wed, May 29, 2013 at 5:51 PM, Ulrich Kühne <ulrichk AT informatik.uni-bremen.de> wrote:
Hi,

I have a (badly designed) imperative language, where statements are not separated by semicolons, which gives me plenty of ambiguous parsings. One example is return, since there is a plain "return" for void functions and "return Exp". Since Exp needs to be included as a valid statement, the parser cannot decide whether "return Exp" is one or two statements. How can I get rid of this behavior, i.e. I always want to have the "return Exp" (the maximum match) alternative? I tried using precedences, but I failed. Here is a small example:

module AMBIG-SYNTAX
  syntax Exp ::= Int | Int "+" Int [strict,left]

  syntax Stmt ::=
          "var" Id
        | Id "=" Exp [strict(2)]
        | "return" Exp [strict]
        > "return"
        > Exp
        > Stmt Stmt [right]
endmodule

module AMBIG imports AMBIG-SYNTAX
  syntax Val ::= Int | "nothing"
  syntax KResult ::= Val

  rule <k>return X:Int =>X ...</k>
  rule <k>return => nothing ...</k>
endmodule

resulting in the following warning (using K 3.0):

[Warning] Parser: Parsing ambiguity between: "return" Exp (Stmt1436Syn), Stmt Stmt (Stmt1438Syn)    Arbitrarily choosing the first. in the following AST:
amb(
    return X:Int,
    return X
)
    File: /home/.../ambig.k
    Location: (17,11,17,23)
    Compilation Phase: Ambiguity filter

My second question: can somebody please explain to me how context rules work? I already used some of them, mostly copied from the k-framework examples, but still I don't get the real meaning and how to use them properly.

Thanks!
Ulrich

_______________________________________________
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