[erlang-questions] problem making my first parser

Roelof Wobben <>
Sat Sep 26 09:01:30 CEST 2015


Hello,

I try to make a very easy parser to practice to make a json parser in 
the future.
As first I try to make a parser which can calculate some basic things.

So far I have this :

-module(number_parser).

-export([scan/1]).

scan(String) ->
     scan(String, []).

scan([], List) ->
     List;

scan([Head | Rest], List_parse) when Head >= $0, Head =< $9 ->
      scan(Rest, [(Head - 48) | List_parse]);

scan([Head | Rest], List_parse) when Head =:= "+" ->
    scan(Rest, [Head | List_parse] ).


but when I try this code on scan("1+1") I see this error message :

** exception error: no function clause matching 
number_parser:scan("+1",[1]) (number_parser.erl, line 8)

Which does not make sense. +1 makes as far as I know [+, 1] so I have a 
head and tail so the last clause schould work.


Why do I then see this error message ?

Roelof



More information about the erlang-questions mailing list