aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-11 11:30:23 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-11 11:30:23 +0200
commit8780ceda0c192a0a0c79d716a3064a7cc2406ae5 (patch)
tree08f6834cef0f56ea6ac6beffa7e1374ec0aa2602
downloaderlang-8780ceda0c192a0a0c79d716a3064a7cc2406ae5.tar.gz
erlang-8780ceda0c192a0a0c79d716a3064a7cc2406ae5.tar.xz
erlang-8780ceda0c192a0a0c79d716a3064a7cc2406ae5.zip
first tries with erlang
-rw-r--r--.gitignore2
-rw-r--r--calc.erl30
2 files changed, 32 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5f61fbd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.beam
+folien.pdf
diff --git a/calc.erl b/calc.erl
new file mode 100644
index 0000000..4bf5967
--- /dev/null
+++ b/calc.erl
@@ -0,0 +1,30 @@
+-module(calc).
+-export([eval/1]).
+
+eval(Formular) ->
+ eval(Formular,[]).
+
+eval([C | Formular], T) when integer(C) ->
+ eval(Formular, parseDigit(T, C));
+
+eval([C | Formular], T) when C == "." ->
+ eval(Formular, parseDigit(T, C));
+
+eval([C | Formular], T) when C == "+" ->
+ eval(Formular, [{plus, C}] ++ T);
+eval([C |Formular], T) when C == "-" ->
+ eval(Formular, [{minus, C}] ++ T);
+eval([C |Formular], T) when C == "*" ->
+ eval(Formular, [{mal, C}] ++ T);
+eval([C |Formular], T) when C == "/" ->
+ eval(Formular, [{durch, C}] ++ T);
+
+eval([], P) ->
+ P.
+
+parseDigit([{digit, Last} | Tail], Current) when list(Last) ->
+ [{digit, Last ++ Current} | Tail];
+parseDigit([{digit, Last} | Tail], Current) ->
+ [{digit, [Last] ++ Current} | Tail];
+parseDigit(Tail, Current) ->
+ [{digit, Current} | Tail].