Skip to content

Instantly share code, notes, and snippets.

@askingalot
askingalot / exp_parser.erl
Created August 16, 2013 02:11
This is my attempt to solve the very first part of Exercise 3-8 from the O'reilly Erlang Programming book. This module *should* parse a simple mathematical expression into an erlang data structure. It does that (save unary negation) but it does so by wrapping each expression and sub expression in a tagged tuple. The trouble is, I can't seem to u…
-module(exp_parser).
-export([parse/1]).
% Parse simple math expressions.
% Currently works (for certain definitions of "works")
% for addition, subtraction and multiplication.
% Eventually it should handle a unary negation operator (~)
% The goal is to do the following:
% parse("(2 + 3)") => {plus, {num, 2}, {num, 3}}