[erlang-questions] Binaries in records syntax error

Dave Vandervies <>
Sat Jul 31 15:53:24 CEST 2010


Somebody claiming to be Robert Virding wrote:
> It's not just setting binaries in records, you always need a space
> between an '=' and the << otherwise the parser groups them
> incorrectly.

This is a general principle that applies to other operators and
other languages as well.
In a typical two-stage lex-and-parse language implementation it
happens in the lexer, before the parser sees it; the lexer will
identify the longest prefix of the input that forms a legal token
and convert that into the next token it gives the parser (the
"maximal munch" rule).


> There is nothing really which can be done about this as you scan from
> left-to-right.

This kind of surprise is why starting with the second language I
learned I got in the habit of putting spaces around all the operators.

It might be an interesting experiment to try building a parser that
can recognize problems of this sort and ask the lexer to rescan
with a non-maximal munch, but I suspect getting something like that
to behave predictably would be harder than just forcing programmers
to use whitespace to help the lexer.


dave

-- 
Dave Vandervies
 / 

Plan your future!  Make God laugh!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20100731/c6105342/attachment.bin>


More information about the erlang-questions mailing list