Skip to Content.
Sympa Menu

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

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

[K-user] Ambiguity & context rules


Chronological Thread 
  • From: Ulrich Kühne <ulrichk AT informatik.uni-bremen.de>
  • To: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: [K-user] Ambiguity & context rules
  • Date: Wed, 29 May 2013 16:51:08 +0200
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

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] Ambiguity & context rules, Ulrich Kühne, 05/29/2013

Archive powered by MHonArc 2.6.16.

Top of Page