Nonterminals list.
Terminals element.
Rootsymbol list.

list -> element : {single, '$1'}.
list -> list element : {pair, '$1', '$2'}.

Erlang code.

-export([bug/0, scan/1]).

scan(Lexer) ->
    Lexer ! {scan, self()},
    receive
	{ok, Lexer, [Token], Position} ->
	    {ok, [Token], Position};
	{eof, Lexer, Position} ->
	    {eof, Position}
    end.

make_scanner(L) ->
    spawn_link(fun() ->
		       loop(L)
	       end).

loop([]) ->
    receive
	{scan, Pid} ->
	    Pid ! {eof, self(), 1000}
    end;

loop([Token = {_, P}|T]) ->
    receive
	{scan, Pid} ->
	    Pid ! {ok, self(), [Token], P},
	    loop(T)
    end.

bug() ->
    L = [{element, 1},
	 {element, 2},
	 {element, 3}],
    case parse_and_scan({bug, scan, [make_scanner(L)]}) of
	{ok, Result} ->
	    io:format("Parse successful: ~p~n", [Result]);
	{error, {Line_number, Module, Message}} ->
	    M = apply(Module, format_error, [Message]),
	    io:format("Parse failed: ~s~n", [M])
    end.
