aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/elixir_math_parser.ex7
-rw-r--r--lib/main.ex14
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/elixir_math_parser.ex b/lib/elixir_math_parser.ex
index 8d5bcc9..4da4271 100644
--- a/lib/elixir_math_parser.ex
+++ b/lib/elixir_math_parser.ex
@@ -49,6 +49,13 @@ defmodule ElixirMathParser do
end
end
+ defp evaluate_tree([{:eval, expr} | tail], state) do
+ with {:ok, expr} <- reduce_to_value(expr, state) do
+ IO.puts(expr)
+ evaluate_tree(tail, state)
+ end
+ end
+
defp evaluate_tree([], state) do
{:ok, state}
end
diff --git a/lib/main.ex b/lib/main.ex
index f1f0a20..ad657ca 100644
--- a/lib/main.ex
+++ b/lib/main.ex
@@ -7,9 +7,10 @@ defmodule ElixirMathParser.Main do
def process_parse({:ok, tree}) do
IO.puts("\nParse tree")
IO.inspect(tree, pretty: true)
- state = ElixirMathParser.process_tree(tree)
- IO.puts("\nFinal state")
- IO.inspect(state, pretty: true)
+ case ElixirMathParser.process_tree(tree) do
+ {:ok, _} -> :ok
+ {:error, reason} -> reason
+ end
end
def main(args) do
@@ -20,9 +21,10 @@ defmodule ElixirMathParser.Main do
{:ok, tokens, line} = :elixir_math_parser_lexer.string(String.to_charlist(text))
IO.puts("Parsed #{filename}, stopped at line #{line}")
- IO.puts("\nTokens:")
- IO.inspect(tokens, pretty: true)
- process_parse(:elixir_math_parser.parse(tokens))
+ res = process_parse(:elixir_math_parser.parse(tokens))
+ if res != :ok do
+ IO.puts(res)
+ end
end
end