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