I mistyped a word constant and was a bit surprised by the error message.
rda]- poly Poly/ML 5.5.2 Release
0xw9;
Error-malformed integer constant: 0w Static Errors
Contrast this with SML/NJ:
rda]- sml Standard ML of New Jersey v110.76 [built: Mon Mar 3 16:26:20 2014] - 0xw9; stdIn:3.2-3.5 Error: unbound variable or constructor: xw9 stdIn:3.1-3.5 Error: operator is not a function [literal] operator: int in expression: 0 <errorvar>
With the following contrived example:
fun f x y = print "Boo!" val xw9 = "xw9"; f 0xw9;
Poly/ML reports a syntax error while SML/NJ and mlton both print Boo!
I am not sure who is right about this.
Regards,
Rob.
{{{ An integer constant (in decimal notation) is an optional negation symbol (~) followed by a non-empty sequence of decimal digits 0,.., 9. An integer constant (in hexadecimal notation) is an optional negation symbol followed by 0x followed by a non-empty sequence of hexadecimal digits 0,.., 9 and a,.., f. (A,..,F may be used as alternatives for a,.., f.) A word constant (in decimal notation) is 0w followed by a non-empty sequence of decimal digits. A word constant (in hexadecimal notation) is 0wx followed by a non-empty sequence of hexadecimal digits. }}} Source: Milner R., et al. "The Definition of Standard ML. Revised." MIT (1997) Thus "0xw9" is invalid.
On 23.02.15 14:37, Rob Arthan wrote:
I mistyped a word constant and was a bit surprised by the error message.
rda]- poly Poly/ML 5.5.2 Release
0xw9;
Error-malformed integer constant: 0w Static Errors
Contrast this with SML/NJ:
rda]- sml Standard ML of New Jersey v110.76 [built: Mon Mar 3 16:26:20 2014]
- 0xw9;
stdIn:3.2-3.5 Error: unbound variable or constructor: xw9 stdIn:3.1-3.5 Error: operator is not a function [literal] operator: int in expression: 0 <errorvar>
With the following contrived example:
fun f x y = print "Boo!" val xw9 = "xw9"; f 0xw9;
Poly/ML reports a syntax error while SML/NJ and mlton both print Boo!
I am not sure who is right about this.
Regards,
Rob.
polyml mailing list polyml at inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
On 23 Feb 2015, at 14:37, me at beroal.in.ua wrote:
{{{ An integer constant (in decimal notation) is an optional negation symbol (~) followed by a non-empty sequence of decimal digits 0,.., 9. An integer constant (in hexadecimal notation) is an optional negation symbol followed by 0x followed by a non-empty sequence of hexadecimal digits 0,.., 9 and a,.., f. (A,..,F may be used as alternatives for a,.., f.) A word constant (in decimal notation) is 0w followed by a non-empty sequence of decimal digits. A word constant (in hexadecimal notation) is 0wx followed by a non-empty sequence of hexadecimal digits. }}} Source: Milner R., et al. "The Definition of Standard ML. Revised." MIT (1997) Thus "0xw9" is invalid.
Your quotation makes it clear that ?0xw9? isn?t a valid word constant. But your quotation does not forbid it being lexed as two lexemes: the integer constant 0 followed by the identifier xw9. See Matthew Fluet?s post.
Regards,
Rob.
Thanks for the nice "teachable moment" to bring to the attention of my Compiler Construction class!
I think that a (very) strict reading of the Definition would find in favor of SML/NJ and MLton (and, also, HaMLet), since it requires that lexical analysis take "the longest next item". This is the behavior you generally get with lexer generator tools that use longest match and rule priority. Since "0xw9" is not a valid word hex constant, it is not a longest match, leading to the integer dec constant "0" being the longest match and leaving "xw9" as a variable identifier as the subsequent longest match.
Of course, Poly/ML's behavior is probably nicer to the programmer. Indeed, Andreas Rossberg suggested supporting more flexible word constants that allow the "w" and "x" modifiers to come in any order (http://www.mpi-sws.org/~rossberg/hamlet/hamlet-succ-1.3.1S5.pdf). I doubt that one could find any instances of "0xw" in SML sources where the intention were not to have a word hex constant.
On Mon, Feb 23, 2015 at 7:37 AM, Rob Arthan <rda at lemma-one.com> wrote:
I mistyped a word constant and was a bit surprised by the error message.
rda]- poly Poly/ML 5.5.2 Release
0xw9;
Error-malformed integer constant: 0w Static Errors
Contrast this with SML/NJ:
rda]- sml Standard ML of New Jersey v110.76 [built: Mon Mar 3 16:26:20 2014]
- 0xw9;
stdIn:3.2-3.5 Error: unbound variable or constructor: xw9 stdIn:3.1-3.5 Error: operator is not a function [literal] operator: int in expression: 0 <errorvar>
With the following contrived example:
fun f x y = print "Boo!" val xw9 = "xw9"; f 0xw9;
Poly/ML reports a syntax error while SML/NJ and mlton both print Boo!
I am not sure who is right about this.
Regards,
Rob.
polyml mailing list polyml at inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
This was an interesting one! I've committed a fix for it. My regression test is
fun test 0 _ = () | test _ _ = raise Fail "wrong";
val () = let val xz = 1 in test 0xz end; val () = let val wxz = 1 in test 0wxz end; val () = let val xw9 = 1 in test 0xw9 end; val () = let val x = 1 in test 0x; () end;
which I think covers the various cases.
Looking back, I found there was actually a fix for a very similar bug with real numbers where val e = (1, 2); #1e; was failing because it was trying to parse this as a real constant.
The rules for when spaces are needed are a bit inconsistent. I often get caught out with the equals sign. {x=nil} but not {x=#"a"}
Thanks for reporting it. David
On 23/02/2015 12:37, Rob Arthan wrote:
I mistyped a word constant and was a bit surprised by the error message.
rda]- poly Poly/ML 5.5.2 Release
0xw9;
Error-malformed integer constant: 0w Static Errors
Contrast this with SML/NJ:
rda]- sml Standard ML of New Jersey v110.76 [built: Mon Mar 3 16:26:20 2014]
- 0xw9;
stdIn:3.2-3.5 Error: unbound variable or constructor: xw9 stdIn:3.1-3.5 Error: operator is not a function [literal] operator: int in expression: 0 <errorvar>
With the following contrived example:
fun f x y = print "Boo!" val xw9 = "xw9"; f 0xw9;
Poly/ML reports a syntax error while SML/NJ and mlton both print Boo!
I am not sure who is right about this.
Regards,
Rob.
polyml mailing list polyml at inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml