[erlang-questions] problem making my first parser
Sat Sep 26 09:08:35 CEST 2015
On Saturday 26 September 2015 09:01:30 Roelof Wobben wrote:
> 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 :
> scan(String) ->
> scan(String, ).
> scan(, 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",) (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 ?
What happens if you try ` >= $0,  =< $9.`?
How about ` =:= "+".` ?
What are you actually comparing here?
Do you care about plus signs as strings, or do you care about plus as a symbol that represents an operation?
More information about the erlang-questions