k-legacy icon indicating copy to clipboard operation
k-legacy copied to clipboard

`roundFloat` causing parsing ambiguity warning on K4.0

Open omarzd opened this issue 8 years ago • 5 comments

I'm defining many math functions in my language by rewriting them directly to K-builtin ones like so:

rule Ceil(V:Float) => ceilFloat(V)
rule Round(V:Float, I1:Int, I2:Int) => roundFloat(V,I1,I2) 

Only roundFloat causes the following parsing ambiguity warning on K4.0:

[Warning] Inner Parser: Parsing ambiguity. Arbitrarily choosing the first.
1: syntax KList ::= KList "," KList
[Location(#token("39",Int),#token("20",Int),#token("39",Int),#token("126",Int))
Source(#token("C:\\k\\lib\\java\\..\\..\\include\\builtin\\kast.k",KString))
assoc(#token("",AttributeValue))
hook(#token("org.kframework.kore.KList",AttributeValue))
klabel(#token("#KList",AttributeValue)) klabel(#token("#KList",KString))
left(#token("",AttributeValue)) prefer(#token("",AttributeValue))
unit(#token("#EmptyKList",AttributeValue))]

#KList(#SemanticCastToFloat(#token(#KVariable,"V")),amb(_,_(#SemanticCastToInt(#
token(#KVariable,"I1")),#SemanticCastToInt(#token(#KVariable,"I2"))),_,_(#Semant
icCastToInt(#token(#KVariable,"I1")),#SemanticCastToInt(#token(#KVariable,"I2"))
)))
2: syntax KList ::= KList "," KList
[Location(#token("39",Int),#token("20",Int),#token("39",Int),#token("126",Int))
Source(#token("C:\\k\\lib\\java\\..\\..\\include\\builtin\\kast.k",KString))
assoc(#token("",AttributeValue))
hook(#token("org.kframework.kore.KList",AttributeValue))
klabel(#token("#KList",AttributeValue)) klabel(#token("#KList",KString))
left(#token("",AttributeValue)) prefer(#token("",AttributeValue))
unit(#token("#EmptyKList",AttributeValue))]

#KList(#KList(#SemanticCastToFloat(#token(#KVariable,"V")),#SemanticCastToInt(#t
oken(#KVariable,"I1"))),#SemanticCastToInt(#token(#KVariable,"I2")))

omarzd avatar May 09 '16 12:05 omarzd

We decided in K4 to change the syntax of labels a bit. So I think there you have an issue because roundFloat can be also parsed as a KLabel. If you give me a small example where I can reproduce this issue, I can give you more details.

radumereuta avatar May 09 '16 13:05 radumereuta

OK. Give me a few minutes.

omarzd avatar May 09 '16 13:05 omarzd

Here:

module TEST
  imports TEST-SYNTAX
    syntax MathFunction ::= "Round"
    rule Round(V:Float, I1:Int, I2:Int) => roundFloat(V,I1,I2)
endmodule

module TEST-SYNTAX
  syntax Pgm ::= MathFunction "(" Vals ")" [strict(2)]
    syntax MathFunction
  syntax Vals    ::= List{Val, ","}
  syntax Val ::= Int | Float
    syntax KResult ::= Val
endmodule

I can make it even smaller but then it won't make sense.

omarzd avatar May 09 '16 13:05 omarzd

Look at this. It's simpler.

module TEST
  syntax Pgm ::= MathFunction "(" Vals ")"
    syntax MathFunction ::= "Round" | "Root"
    rule Round(F:Float, I1:Int, I2:Int) => roundFloat(F,I1,I2)
    rule Root(F:Float, I:Int) => rootFloat(F,I)
  syntax Vals    ::= List{Val, ","}
  syntax Val ::= Int | Float
endmodule

rootFloat will not cause the warning but roundFloat will.

omarzd avatar May 09 '16 13:05 omarzd

OK. Avoiding the custom list Vals will solve the problem:

module TEST
  syntax Pgm ::= MathFunction "(" Float "," Int "," Int ")"
    syntax MathFunction ::= "Round"
    rule Round(F:Float, I1:Int, I2:Int) => roundFloat(F,I1,I2)
endmodule

omarzd avatar May 09 '16 13:05 omarzd