anchor.diff:  %% more/8 and done/6 handles scanning from I/O-server (Stream) or from String.
   %%
   
  -%% String
  -more(Cs, Stack, Toks, {Line, Col}, eos, Errors, _TabWidth, Fun) ->
  -    erlang:error(badstate,
  -		 [Cs, Stack, Toks, {Line, Col}, eos, Errors, Fun]);
  -% %% Debug clause for chopping string into 1-char segments
  -% more(Cs, Stack, Toks, Pos, [H|T], Errors, Fun) ->
  -%     Fun(Cs++[H], Stack, Toks, Pos, T, Errors);
  -more(Cs, Stack, Toks, {Line, Col}, [], Errors, TabWidth, Fun) ->
  -    Fun(Cs ++ eof, Stack, Toks, {Line, Col}, eos, Errors, TabWidth);
  -%% Stream
  -more(Cs, Stack, Toks, {Line, Col}, eof, Errors, TabWidth, Fun) ->
  -    erlang:error(badstate,
  -		 [Cs, Stack, Toks, {Line, Col}, eof, Errors, TabWidth, Fun]);
  -more(Cs, Stack, Toks, {Line, Col}, io, Errors, TabWidth, Fun) ->
  -    {more, {Cs, Stack, Toks, {Line, Col}, io, Errors, TabWidth, Fun}}.
  -
  -%% String
  -done(eof, [], Toks, {Line, Col}, eos, _TabWidth) ->
  -    {ok, reverse(Toks), {Line, Col}};
  -done(eof, Errors, _Toks, {Line, Col}, eos, _TabWidth) ->
  -    {Error, ErrorPos} = lists:last(Errors),
  -    {error, {ErrorPos, ?MODULE, Error}, {Line, Col}};
  -done(Cs, Errors, Toks, {Line, Col}, eos, TabWidth) ->
  -    scan(Cs, [], Toks, {Line, Col}, eos, Errors, TabWidth);
  -% %% Debug clause for chopping string into 1-char segments
  -% done(Cs, Errors, Toks, Pos, [H|T]) ->
  -%    scan(Cs++[H], [], Toks, Pos, T, Errors);
  -done(Cs, Errors, Toks, {Line, Col}, [], TabWidth) ->
  -    scan(Cs ++ eof, [], Toks, {Line, Col}, eos, Errors, TabWidth);
  -%% Stream
  -done(Cs, [], [{dot, _} | _] = Toks, {Line, Col}, io, _TabWidth) ->
  -    {done, {ok, reverse(Toks), {Line, Col}}, Cs};
  -done(Cs, [], [_ | _], {Line, Col}, io, _TabWidth) ->
  -    {done,
  -     {error, {{Line, Col}, ?MODULE, scan}, {Line, Col}}, Cs};
  -done(Cs, [], [], {Line, Col}, eof, _TabWidth) ->
  -    {done, {eof, {Line, Col}}, Cs};
  -done(Cs, [], [{dot, _} | _] = Toks, {Line, Col}, eof, _TabWidth) ->
  -    {done, {ok, reverse(Toks), {Line, Col}}, Cs};
  -done(Cs, [], _Toks, {Line, Col}, eof, _TabWidth) ->
  -    {done,
  -     {error, {{Line, Col}, ?MODULE, scan}, {Line, Col}}, Cs};
  -done(Cs, Errors, _Toks, {Line, Col}, io, _TabWidth) ->
  -    {Error, ErrorPos} = lists:last(Errors),
  -    {done, {error, {ErrorPos, ?MODULE, Error}, {Line, Col}},
  -     Cs};
  -done(Cs, Errors, _Toks, {Line, Col}, eof, _TabWidth) ->
  -    {Error, ErrorPos} = lists:last(Errors),
  -    {done, {error, {ErrorPos, ?MODULE, Error}, {Line, Col}},
  -     Cs}.
  -
  -%% The actual scan loop
  -%% Stack is assumed to be [].
  -
  -scan([$\r | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->      % CR
  -    case Cs of 
  -	[$\n|Cs1] -> 
  -	    scan(Cs1, Stack, [{whitespace, {Line, Col}, '\r\n'}|Toks], {Line + 1, 1}, State, Errors, TabWidth);  
  +scan([$\r | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth, FileFormat) ->    
  +    case FileFormat of 
  +	mac -> 
  +	    scan(Cs, Stack, [{whitespace, {Line, Col}, '\r'}|Toks], {Line + 1, 1}, State, Errors, TabWidth, FileFormat);  
   	_ ->
  -	    scan(Cs, Stack, [{whitespace, {Line, Col}, '\r'}|Toks], {Line + 1, 1}, State, Errors, TabWidth)
  +	    scan(Cs, Stack, [{whitespace, {Line, Col}, '\r'}|Toks], {Line , Col+1}, State, Errors, TabWidth, FileFormat)
       end;
  -scan([$\n | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->      % Newline - skip
  -    scan(Cs, Stack, [{whitespace, {Line, Col}, '\n'}|Toks], {Line + 1, 1}, State, Errors, TabWidth);  
  -
  -%%Begin of Adding by Huiqing
  -scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C == $\t
  -	  ->                          
  -    scan(Cs, Stack, [{whitespace, {Line, Col}, '\t'}|Toks], {Line, Col + TabWidth}, State, Errors, TabWidth);
  -%% End of adding by Huiqing
  -
  -scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $\000,
  -	 C =< $\s ->                          % Control chars - skip
  -    scan(Cs, Stack, [{whitespace, {Line,Col}, '\s'}|Toks], {Line, Col + 1}, State, Errors, TabWidth);
  -
  -scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $\200,
  -	 C =< $\240 ->                        % Control chars -skip
  -    scan(Cs, Stack, [{whitespace, {Line,Col}, '\s'}|Toks], {Line, Col + 1}, State, Errors, TabWidth);
  -scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $a,
  -	 C =< $z ->                              % Atoms
  -    sub_scan_name(Cs, [C, fun scan_atom/7], Toks,
  -		  {Line, Col}, State, Errors, TabWidth);
  -scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  +scan([$\n | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth, FileFormat) ->    
  +    scan(Cs, Stack, [{whitespace, {Line, Col}, '\n'}|Toks], {Line + 1, 1}, State, Errors, TabWidth,FileFormat);  
  +
  +scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C == $\t  ->                          
  +    scan(Cs, Stack, [{whitespace, {Line, Col}, '\t'}|Toks], {Line, Col + TabWidth}, State, Errors, TabWidth,FileFormat);
  +
  +scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $\000, C =< $\s ->                          % Control chars - skip
  +    scan(Cs, Stack, [{whitespace, {Line,Col}, '\s'}|Toks], {Line, Col + 1}, State, Errors, TabWidth,FileFormat);
  +
  +scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $\200, C =< $\240 ->                        % Control chars -skip
  +    scan(Cs, Stack, [{whitespace, {Line,Col}, '\s'}|Toks], {Line, Col + 1}, State, Errors, TabWidth,FileFormat);
  +scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $a, C =< $z ->                              % Atoms
  +    sub_scan_name(Cs, [C, fun scan_atom/8], Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
       when C >= $, C =< $,
   	 C /= $ ->                     % Atoms
  -    sub_scan_name(Cs, [C, fun scan_atom/7], Toks,
  -		  {Line, Col}, State, Errors, TabWidth);
  -scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $A,
  -	 C =< $Z ->                              % Variables
  -    sub_scan_name(Cs, [C, fun scan_variable/7], Toks,
  -		  {Line, Col}, State, Errors, TabWidth);
  -scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $, C =< $,
  -	 C /= $ ->                     % Variables
  -    sub_scan_name(Cs, [C, fun scan_variable/7], Toks,
  -		  {Line, Col}, State, Errors, TabWidth);
  -scan([$_ | Cs], _Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->      % _Variables
  -    sub_scan_name(Cs, [$_, fun scan_variable/7], Toks,
  -		  {Line, Col}, State, Errors, TabWidth);
  -scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth)
  -    when C >= $0,
  -	 C =< $9 ->                            % Numbers
  -    scan_number(Cs, [C], Toks, {Line, Col}, State, Errors, TabWidth);
  -scan([$$ | Cs], Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->        % Character constant
  -    scan_char(Cs, Stack, Toks, {Line, Col+2}, State, Errors, TabWidth);
  -scan([$' | Cs], _Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->      % Quoted atom
  -    scan_qatom(Cs, [$', {Line, Col}], Toks, {Line, Col+1},
  -	       State, Errors, TabWidth);
  -scan([$" | Cs], _Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->      % String
  -    scan_string(Cs, [$", {Line, Col}], Toks, {Line, Col+1},
  -		State, Errors, TabWidth);
  -scan([$% | Cs], _Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->       % Comment
  -    scan_comment(Cs, [$%, {Line, Col}], Toks, {Line, Col+1}, State,
  -		 Errors, TabWidth);
  +    sub_scan_name(Cs, [C, fun scan_atom/8], Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $A, C =< $Z ->                              % Variables
  +    sub_scan_name(Cs, [C, fun scan_variable/8], Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $, C =< $, C /= $ ->                     % Variables
  +    sub_scan_name(Cs, [C, fun scan_variable/8], Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([$_ | Cs], _Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->      % _Variables
  +    sub_scan_name(Cs, [$_, fun scan_variable/8], Toks,  {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([C | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
  +    when C >= $0, C =< $9 ->                            % Numbers
  +    scan_number(Cs, [C], Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
  +scan([$$ | Cs], Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->        % Character constant
  +    scan_char(Cs, Stack, Toks, {Line, Col+2}, State, Errors, TabWidth,FileFormat);
  +scan([$' | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->      % Quoted atom
  +    scan_qatom(Cs, [$', {Line, Col}], Toks, {Line, Col+1}, State, Errors, TabWidth,FileFormat);
  +scan([$" | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->      % String
  +    scan_string(Cs, [$", {Line, Col}], Toks, {Line, Col+1}, State, Errors, TabWidth,FileFormat);
  +scan([$% | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->       % Comment
  +    scan_comment(Cs, [$%, {Line, Col}], Toks, {Line, Col+1}, State, Errors, TabWidth,FileFormat);
   %% Punctuation characters and operators, first recognise multiples.
   %% Clauses are rouped by first character (a short with the same head has
   %% to come after a longer).
   %%
   %% << <- <=
  -scan("<<" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'<<', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("<-" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'<-', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("<=" ++ Cs, Stack, Toks, {Line, Col}, State,TabWidth,
  -     Errors) ->
  -    scan(Cs, Stack, [{'<=', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("<" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  -	 fun scan/7);
  +scan("<<" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'<<', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("<-" ++ Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'<-', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("<=" ++ Cs, Stack, Toks, {Line, Col}, State,Errors, TabWidth, FileFormat) ->
  +    scan(Cs, Stack, [{'<=', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth, FileFormat);
  +scan("<" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat, fun scan/8);
   %% >> >=
  -scan(">>" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'>>', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan(">=" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'>=', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan(">" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  +scan(">>" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth, FileFormat) ->
  +    scan(Cs, Stack, [{'>>', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth, FileFormat);
  +scan(">=" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'>=', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan(">" = Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
   %% -> --
  -scan("->" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'->', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("--" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'--', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("-" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  +scan("->" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'->', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth, FileFormat);
  +scan("--" ++ Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth, FileFormat) ->
  +    scan(Cs, Stack, [{'--', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("-" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
   %% ++
  -scan("++" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'++', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("+" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  +scan("++" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'++', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("+" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
   %% =:= =/= =< ==
  -scan("=:=" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'=:=', {Line, Col}} | Toks],
  -	 {Line, Col + 3}, State, Errors, TabWidth);
  -scan("=:" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  -scan("=/=" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'=/=', {Line, Col}} | Toks],
  -	 {Line, Col + 3}, State, Errors, TabWidth);
  -scan("=/" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  -	 fun scan/7);
  -scan("=<" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'=<', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("==" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'==', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("=" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, 
  -	 fun scan/7);
  +scan("=:=" ++ Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'=:=', {Line, Col}} | Toks], {Line, Col + 3}, State, Errors, TabWidth,FileFormat);
  +scan("=:" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
  +scan("=/=" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'=/=', {Line, Col}} | Toks], {Line, Col + 3}, State, Errors, TabWidth,FileFormat);
  +scan("=/" = Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth, FileFormat,fun scan/8);
  +scan("=<" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'=<', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("==" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'==', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("=" = Cs, Stack, Toks, {Line, Col}, State,  Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
   %% /=
  -scan("/=" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'/=', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("/" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  +scan("/=" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'/=', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("/" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,FileFormat, fun scan/8);
   %% ||
  -scan("||" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'||', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  -scan("|" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  -	 fun scan/7);
  +scan("||" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'||', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
  +scan("|" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth, FileFormat, fun scan/8);
   %% :-
  -scan(":-" ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack, [{':-', {Line, Col}} | Toks],
  -	 {Line, Col + 2}, State, Errors, TabWidth);
  +scan(":-" ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{':-', {Line, Col}} | Toks], {Line, Col + 2}, State, Errors, TabWidth,FileFormat);
   %% :: for typed records
  -scan("::"++Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
  -    scan(Cs, Stack, [{'::',{Line, Col}}|Toks], {Line, Col+2}, State, Errors, TabWidth);
  -
  -scan(":" = Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  -	 fun scan/7);
  +scan("::"++Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{'::',{Line, Col}}|Toks], {Line, Col+2}, State, Errors, TabWidth,FileFormat);
  +
  +scan(":" = Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat, fun scan/8);
   %% Full stop and plain '.'
  -scan("." ++ Cs, Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan_dot(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth);
  +scan("." ++ Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan_dot(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat);
   %% All single-char punctuation characters and operators (except '.')
  -scan([C | Cs], Stack, Toks, {Line, Col}, State,
  -     Errors, TabWidth) ->
  -    scan(Cs, Stack,
  -	 [{list_to_atom([C]), {Line, Col}} | Toks],
  -	 {Line, Col + 1}, State, Errors, TabWidth);
  -%%
  -scan([], Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
  -    more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  -	 fun scan/7);
  -scan(Eof, _Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
  -    done(Eof, Errors, Toks, {Line, Col}, State, TabWidth).
  -
  -scan_atom(Cs, Name, Toks, {Line, Col}, State, Errors, TabWidth) ->
  +scan([C | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    scan(Cs, Stack, [{list_to_atom([C]), {Line, Col}} | Toks],
  +	 {Line, Col + 1}, State, Errors, TabWidth,FileFormat);
  +%%
  +scan([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat, fun scan/8);
  +scan(Eof, _Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
  +    done(Eof, Errors, Toks, {Line, Col}, State, TabWidth,FileFormat).
  +
  +scan_atom(Cs, Name, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
       case catch list_to_atom(Name) of
         Atom when is_atom(Atom) ->
   	  case reserved_word(Atom) of
   	    true ->
  -		scan(Cs, [], [{Atom, {Line, Col}} | Toks],
  -		     {Line, Col + length(Name)}, State, Errors, TabWidth);
  +		  scan(Cs, [], [{Atom, {Line, Col}} | Toks],
  +		     {Line, Col + length(Name)}, State, Errors, TabWidth,FileFormat);
   	    false ->
  -		scan(Cs, [], [{atom, {Line, Col}, Atom} | Toks],
  -		     {Line, Col + length(Name)}, State, Errors, TabWidth)
  +		  scan(Cs, [], [{atom, {Line, Col}, Atom} | Toks],
  +		     {Line, Col + length(Name)}, State, Errors, TabWidth,FileFormat)
   	  end;
         _ ->
   	  scan(Cs, [], Toks, {Line, Col}, State,
  -	       [{{illegal, atom}, {Line, Col}} | Errors], TabWidth)
  +	       [{{illegal, atom}, {Line, Col}} | Errors],TabWidth,FileFormat)
       end.
   
   scan_variable(Cs, Name, Toks, {Line, Col}, State,
  -	      Errors, TabWidth) ->
  +	      Errors, TabWidth,FileFormat) ->
       case catch list_to_atom(Name) of
         A when is_atom(A) ->
   	  scan(Cs, [], [{var, {Line, Col}, A} | Toks],
  -	       {Line, Col + length(Name)}, State, Errors, TabWidth);
  +	       {Line, Col + length(Name)}, State, Errors, TabWidth,FileFormat);
         _ ->
   	  scan(Cs, [], Toks, {Line, Col}, State,
  -	       [{{illegal, var}, {Line, Col}} | Errors], TabWidth)
  +	       [{{illegal, var}, {Line, Col}} | Errors], TabWidth,FileFormat)
       end.
   
   %% Scan for a name - unqouted atom or variable, after the first character.
  
positive.code: %%
  %% \<1-3> octal digits
  sub_scan_escape([O1, O2, O3 | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth)
      when O1 >= $0, O1 =< $7, O2 >= $0, O2 =< $7, O3 >= $0,
  	 O3 =< $7 ->
      Val = (O1 * 8 + O2) * 8 + O3 - 73 * $0,
      Fun([Val | Cs], Stack, Toks, {Line, Col}, State,
  	Errors, TabWidth);
  sub_scan_escape([O1, O2] = Cs, Stack, Toks, {Line, Col},
  		State, Errors, TabWidth)
      when O1 >= $0, O1 =< $7, O2 >= $0, O2 =< $7 ->
      more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun sub_scan_escape/7);
  sub_scan_escape([O1, O2 | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth)
      when O1 >= $0, O1 =< $7, O2 >= $0, O2 =< $7 ->
      Val = O1 * 8 + O2 - 9 * $0,
      Fun([Val | Cs], Stack, Toks, {Line, Col}, State,
  	Errors, TabWidth);
  sub_scan_escape([O1] = Cs, Stack, Toks, {Line, Col},
  		State, Errors, TabWidth)
      when O1 >= $0, O1 =< $7 ->
      more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun sub_scan_escape/7);
  sub_scan_escape([O1 | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth)
      when O1 >= $0, O1 =< $7 ->
      Val = O1 - $0,
      Fun([Val | Cs], Stack, Toks, {Line, Col}, State,
  	Errors, TabWidth);
  %% \^X -> CTL-X
  sub_scan_escape([$^, C | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth) ->
      Val = C band 31,
      Fun([Val | Cs], Stack, Toks, {Line, Col}, State,
  	Errors, TabWidth);
  sub_scan_escape([$^] = Cs, Stack, Toks, {Line, Col},
  		State, Errors, TabWidth) ->
      more(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun sub_scan_escape/7);
  sub_scan_escape([$^ | Eof], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth) ->
      Fun(Eof, Stack, Toks, {Line, Col}, State, Errors, TabWidth);
  %% \NL (backslash newline)
  sub_scan_escape([$\n | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth) ->
      Fun([nl | Cs], Stack, Toks, {Line, Col}, State, Errors, TabWidth);
  %% \X - familiar escape sequences
  sub_scan_escape([C | Cs], [Fun | Stack], Toks,
  		{Line, Col}, State, Errors, TabWidth) ->
      Val = escape_char(C),
      Fun([Val | Cs], Stack, Toks, {Line, Col}, State,
  	Errors, TabWidth);
  %%
  sub_scan_escape([], Stack, Toks, {Line, Col}, State,
  		Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun sub_scan_escape/7);
  sub_scan_escape(Eof, [Fun | Stack], Toks, {Line, Col},
  		State, Errors, TabWidth) ->
      Fun(Eof, Stack, Toks, {Line, Col}, State, Errors, TabWidth).
  
  escape_char($n) -> $\n;                         %\n = LF
  escape_char($r) -> $\r;                         %\r = CR
  escape_char($t) ->
      $\t;                         %\t = TAB
  escape_char($v) -> $\v;                         %\v = VT
  escape_char($b) -> $\b;                         %\b = BS
  escape_char($f) -> $\f;                         %\f = FF
  escape_char($e) ->
      $\e;                         %\e = ESC
  escape_char($s) ->
      $\s;                         %\s = SPC
  escape_char($d) ->
      $\d;                         %\d = DEL
  escape_char(C) -> C.
  
  scan_number([$., C | Cs], Stack, Toks, {Line, Col},
  	    State, Errors, TabWidth)
      when C >= $0, C =< $9 ->
      scan_fraction(Cs, [C, $. | Stack], Toks, {Line, Col},
  		  State, Errors, TabWidth);
  scan_number([$.] = Cs, Stack, Toks, {Line, Col}, State,
  	    Errors, TabWidth) ->
      more(Cs, Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_number/7);
  scan_number([C | Cs], Stack, Toks, {Line, Col}, State,
  	    Errors, TabWidth)
      when C >= $0, C =< $9 ->
      scan_number(Cs, [C | Stack], Toks, {Line, Col}, State,
  		Errors, TabWidth);
  scan_number([$# | Cs], Stack, Toks, {Line, Col}, State,
  	    Errors, TabWidth) ->
      case catch list_to_integer(reverse(Stack)) of
        B when is_integer(B), B >= 2, B =< 1 + $Z - $A + 10 ->
  	  scan_based_int(Cs, [B], Toks, {Line, Col}, State,
  			 Errors, TabWidth);
        B ->
  	  scan(Cs, [], Toks, {Line, Col}, State,
  	       [{{base, B}, {Line, Col}} | Errors], TabWidth)
      end;
  scan_number([], Stack, Toks, {Line, Col}, State,
  	    Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_number/7);
  scan_number(Cs, Stack, Toks, {Line, Col}, State,
  	    Errors, TabWidth) ->
      case catch list_to_integer(reverse(Stack)) of
        N when is_integer(N) ->
  	  scan(Cs, [], [{integer, {Line, Col}, N} | Toks],
  	       {Line, Col + length(Stack)}, State, Errors, TabWidth);
        _ ->
  	  scan(Cs, [], Toks, {Line, Col}, State,
  	       [{{illegal, integer}, {Line, Col}} | Errors], TabWidth)
      end.
  
  scan_based_int([C | Cs], [B | Stack], Toks, {Line, Col},
  	       State, Errors, TabWidth)
      when C >= $0, C =< $9, C < $0 + B ->
      scan_based_int(Cs, [B, C | Stack], Toks, {Line, Col},
  		   State, Errors, TabWidth);
  scan_based_int([C | Cs], [B | Stack], Toks, {Line, Col},
  	       State, Errors, TabWidth)
      when C >= $A, B > 10, C < $A + B - 10 ->
      scan_based_int(Cs, [B, C | Stack], Toks, {Line, Col},
  		   State, Errors, TabWidth);
  scan_based_int([C | Cs], [B | Stack], Toks, {Line, Col},
  	       State, Errors, TabWidth)
      when C >= $a, B > 10, C < $a + B - 10 ->
      scan_based_int(Cs, [B, C | Stack], Toks, {Line, Col},
  		   State, Errors, TabWidth);
  scan_based_int([], Stack, Toks, {Line, Col}, State,
  	       Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun scan_based_int/7);
  scan_based_int(Cs, [B | Stack], Toks, {Line, Col},
  	       State, Errors, TabWidth) ->
      case catch erlang:list_to_integer(reverse(Stack), B) of
  	N when is_integer(N) ->
  	    scan(Cs, [], [{integer, {Line, Col}, 
  			   integer_to_list(B)++[$#| reverse(Stack)]} | Toks],   %% "replaced 'N' with 'reverse(Stack)'";
  		 {Line, Col + length(Stack)}, State, Errors, TabWidth);
  	_ ->
  	  scan(Cs, [], Toks, {Line, Col}, State,
  	       [{{illegal, integer}, {Line, Col}} | Errors], TabWidth)
      end.
  
  scan_fraction([C | Cs], Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth)
      when C >= $0, C =< $9 ->
      scan_fraction(Cs, [C | Stack], Toks, {Line, Col}, State,
  		  Errors, TabWidth);
  scan_fraction([$e | Cs], Stack, Toks, {Line, Col},
  	      State, Errors, TabWidth) ->
      scan_exponent_sign(Cs, [$E | Stack], Toks, {Line, Col},
  		       State, Errors,TabWidth);
  scan_fraction([$E | Cs], Stack, Toks, {Line, Col},
  	      State, Errors, TabWidth ) ->
      scan_exponent_sign(Cs, [$E | Stack], Toks, {Line, Col},
  		       State, Errors, TabWidth);
  scan_fraction([], Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_fraction/7);
  scan_fraction(Cs, Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth) ->
      case catch list_to_float(reverse(Stack)) of
        F when is_float(F) ->
  	  scan(Cs, [], [{float, {Line, Col}, F} | Toks],
  	       {Line, Col + length(Stack)}, State, Errors, TabWidth);
        _ ->
  	  scan(Cs, [], Toks, {Line, Col}, State,
  	       [{{illegal, float}, {Line, Col}} | Errors], TabWidth)
      end.
  
  scan_exponent_sign([$+ | Cs], Stack, Toks, {Line, Col},
  		   State, Errors, TabWidth) ->
      scan_exponent(Cs, [$+ | Stack], Toks, {Line, Col},
  		  State, Errors, TabWidth);
  scan_exponent_sign([$- | Cs], Stack, Toks, {Line, Col},
  		   State, Errors, TabWidth) ->
      scan_exponent(Cs, [$- | Stack], Toks, {Line, Col},
  		  State, Errors, TabWidth);
  scan_exponent_sign([], Stack, Toks, {Line, Col}, State,
  		   Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,
  	 fun scan_exponent_sign/7);
  scan_exponent_sign(Cs, Stack, Toks, {Line, Col}, State,
  		   Errors, TabWidth) ->
      scan_exponent(Cs, Stack, Toks, {Line, Col}, State,
  		  Errors, TabWidth).
  
  scan_exponent([C | Cs], Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth)
      when C >= $0, C =< $9 ->
      scan_exponent(Cs, [C | Stack], Toks, {Line, Col}, State,
  		  Errors, TabWidth);
  scan_exponent([], Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_exponent/7);
  scan_exponent(Cs, Stack, Toks, {Line, Col}, State,
  	      Errors, TabWidth) ->
      case catch list_to_float(reverse(Stack)) of
        F when is_float(F) ->
  	  scan(Cs, [], [{float, {Line, Col}, F} | Toks],
  	       {Line, Col + length(Stack)}, State, Errors, TabWidth);
        _ ->
  	  scan(Cs, [], Toks, {Line, Col}, State,
  	       [{{illegal, float}, {Line, Col}} | Errors], TabWidth)
      end.
  
  scan_comment([$\n | Cs], Stack, Toks, {Line, _Col},
  	     State, Errors, TabWidth) ->
      [StartPos|S] = reverse([$\n|Stack]),
      scan(Cs, [], [{comment, StartPos, S}|Toks], {Line + 1, 1}, State, Errors, TabWidth);
  scan_comment([C | Cs], Stack, Toks, {Line, Col}, State,
  	     Errors, TabWidth) ->
      scan_comment(Cs, [C|Stack], Toks, {Line, Col + 1}, State,
  		 Errors, TabWidth);
  scan_comment([], Stack, Toks, {Line, Col}, State,
  	     Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_comment/7);
  scan_comment(Eof, Stack, Toks, {Line, Col}, State,
  	     Errors, TabWidth) ->
      [StartPos|S] = reverse(Stack),
      done(Eof, Errors, [{comment, StartPos, S}|Toks], {Line, Col}, State, TabWidth).
  
  scan_dot([$% | _] = Cs, _Stack, Toks, {Line, Col},
  	 State, Errors, TabWidth) ->
      done(Cs, Errors, [{dot, {Line, Col}} | Toks],
  	 {Line, Col + 1}, State, TabWidth);
  
  scan_dot([$\r | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
      case Cs of 
  	[$\n|Cs1] ->
  	    done(Cs1, Errors, [{whitespace, {Line, Col+1}, '\r\n'}, {dot, {Line, Col}} | Toks],
  		 {Line + 1, 1}, State, TabWidth);
  	_ ->
  	    done(Cs, Errors, [{whitespace, {Line, Col+1}, '\r'}, {dot, {Line, Col}} | Toks],
  		 {Line + 1, 1}, State, TabWidth)
      end;
  scan_dot([$\n | Cs], _Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
      done(Cs, Errors, [{whitespace, {Line, Col+1}, '\n'}, {dot, {Line, Col}} | Toks],
  	 {Line + 1, 1}, State, TabWidth);
  scan_dot([C | Cs], _Stack, Toks, {Line, Col}, State,
  	 Errors, TabWidth)
      when C >= $\000, C =< $\s ->
      done(Cs, Errors, [{whitespace, {Line,Col+1}, '\s'}, {dot, {Line, Col}} | Toks],
  	 {Line, Col + 2}, State, TabWidth);
  scan_dot([C | Cs], _Stack, Toks, {Line, Col}, State,
  	 Errors, TabWidth)
      when C >= $\200, C =< $\240 ->
      done(Cs, Errors, [{whitespace, {Line,Col+1}, C}, {dot, {Line, Col}} | Toks],
  	 {Line, Col + 2}, State, TabWidth);
  scan_dot([], Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
      more([], Stack, Toks, {Line, Col}, State, Errors,TabWidth,
  	 fun scan_dot/7);
  scan_dot(eof, _Stack, Toks, {Line, Col}, State,
  	 Errors, TabWidth) ->
      done(eof, Errors, [{dot, {Line, Col}} | Toks],
  	 {Line, Col}, State, TabWidth);
  scan_dot(Cs, Stack, Toks, {Line, Col}, State, Errors, TabWidth) ->
      scan(Cs, Stack, [{'.', {Line, Col}} | Toks],
  	 {Line, Col + 1}, State, Errors, TabWidth).
  
  %% reserved_word(Atom) -> Bool
  %%   return 'true' if Atom is an Erlang reserved word, else 'false'.
  
  reserved_word('after') -> true;
  reserved_word('begin') -> true;
  reserved_word('case') -> true;
  reserved_word('try') ->
      Opts = get_compiler_options(),
      not member(disable_try, Opts);
  reserved_word('cond') ->
      Opts = get_compiler_options(),
      not member(disable_cond, Opts);
  reserved_word('catch') -> true;
  reserved_word('andalso') -> true;
  reserved_word('orelse') -> true;
  reserved_word('end') -> true;
  reserved_word('fun') -> true;
  reserved_word('if') -> true;
  reserved_word('let') -> true;
  reserved_word('of') -> true;
  reserved_word('query') -> true;
  reserved_word('receive') -> true;
  reserved_word('when') -> true;
  reserved_word('bnot') -> true;
  reserved_word('not') -> true;
  reserved_word('div') -> true;
  reserved_word('rem') -> true;
  reserved_word('band') -> true;
  reserved_word('and') -> true;
  reserved_word('bor') -> true;
  reserved_word('bxor') -> true;
  reserved_word('bsl') -> true;
  reserved_word('bsr') -> true;
  reserved_word('or') -> true;
  reserved_word('xor') -> true;
  reserved_word('spec') -> true;
  reserved_word(_) -> false.
  
  get_compiler_options() ->
      %% Who said that Erlang has no global variables?
      case get(compiler_options) of
        undefined ->
  	  Opts = case catch ets:lookup(compiler__tab,
  				       compiler_options)
  		     of
  		   [{compiler_options, O}] -> O;
  		   _ -> []
  		 end,
  	  put(compiler_options, Opts),
  	  Opts;
        Opts -> Opts
      end.
  
  
negative.code: %% Stack argument: return fun.
  %% Returns the scanned name on the stack, unreversed.
  %%
  sub_scan_name([C | Cs] = Css, Stack, Toks, {Line, Col},State, Errors,TabWidth,FileFormat) ->
      case name_char(C) of
        true ->
  	  sub_scan_name(Cs, [C | Stack], Toks, {Line, Col}, State,Errors, TabWidth,FileFormat);
        false ->
  	  [Fun | Name] = reverse(Stack),
  	  Fun(Css, Name, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat)
      end;
  sub_scan_name([], Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
      more([], Stack, Toks, {Line, Col}, State, Errors, TabWidth, FileFormat, fun sub_scan_name/8);
  sub_scan_name(Eof, Stack, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat) ->
      [Fun | Name] = reverse(Stack),
      Fun(Eof, Name, Toks, {Line, Col}, State, Errors, TabWidth,FileFormat).
  
  name_char(C) when C >= $a, C =< $z -> true;
  name_char(C) when C >= $, C =< $, C /= $ -> true;
  