Implement eval.
diff --git a/py/builtin.h b/py/builtin.h
index cb8836c..7d00134 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -8,6 +8,7 @@
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj);
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
+MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj);
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);
 MP_DECLARE_CONST_FUN_OBJ(mp_builtin_issubclass_obj);
diff --git a/py/builtineval.c b/py/builtineval.c
new file mode 100644
index 0000000..a8a7a47
--- /dev/null
+++ b/py/builtineval.c
@@ -0,0 +1,50 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+
+#include "nlr.h"
+#include "misc.h"
+#include "mpconfig.h"
+#include "lexer.h"
+#include "lexerunix.h"
+#include "parse.h"
+#include "obj.h"
+#include "compile.h"
+#include "runtime0.h"
+#include "runtime.h"
+#include "map.h"
+#include "builtin.h"
+
+static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
+    const char *str = qstr_str(mp_obj_get_qstr(o_in));
+
+    // create the lexer
+    mp_lexer_t *lex = mp_lexer_new_from_str_len("<string>", str, strlen(str), 0);
+
+    // parse the string
+    qstr parse_exc_id;
+    const char *parse_exc_msg;
+    mp_parse_node_t pn = mp_parse(lex, MP_PARSE_EVAL_INPUT, &parse_exc_id, &parse_exc_msg);
+    mp_lexer_free(lex);
+
+    if (pn == MP_PARSE_NODE_NULL) {
+        // parse error; raise exception
+        nlr_jump(mp_obj_new_exception_msg(parse_exc_id, parse_exc_msg));
+    }
+
+    // compile the string
+    mp_obj_t module_fun = mp_compile(pn, false);
+
+    if (module_fun == mp_const_none) {
+        // TODO handle compile error correctly
+        return mp_const_none;
+    }
+
+    // complied successfully, execute it
+    return rt_call_function_0(module_fun);
+}
+
+MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_eval_obj, mp_builtin_eval);
diff --git a/py/compile.c b/py/compile.c
index b948f7a..b24e94a 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2708,7 +2708,12 @@
 #endif
 
     // compile
-    if (scope->kind == SCOPE_MODULE) {
+    if (MP_PARSE_NODE_IS_STRUCT_KIND(scope->pn, PN_eval_input)) {
+        assert(scope->kind == SCOPE_MODULE);
+        mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)scope->pn;
+        compile_node(comp, pns->nodes[0]); // compile the expression
+        EMIT(return_value);
+    } else if (scope->kind == SCOPE_MODULE) {
         if (!comp->is_repl) {
             check_for_doc_string(comp, scope->pn);
         }
@@ -2833,7 +2838,6 @@
     }
 
     EMIT(end_pass);
-
 }
 
 void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
diff --git a/py/grammar.h b/py/grammar.h
index 4d53bd3..32be6c6 100644
--- a/py/grammar.h
+++ b/py/grammar.h
@@ -15,6 +15,8 @@
 DEF_RULE(file_input, nc, and(1), opt_rule(file_input_2))
 DEF_RULE(file_input_2, c(generic_all_nodes), one_or_more, rule(file_input_3))
 DEF_RULE(file_input_3, nc, or(2), tok(NEWLINE), rule(stmt))
+DEF_RULE(eval_input, nc, and(2), rule(testlist), opt_rule(eval_input_2))
+DEF_RULE(eval_input_2, nc, and(1), tok(NEWLINE))
 
 // decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
 // decorators: decorator+
diff --git a/py/mpqstrraw.h b/py/mpqstrraw.h
index 3ee569a..06f83dd 100644
--- a/py/mpqstrraw.h
+++ b/py/mpqstrraw.h
@@ -42,6 +42,7 @@
 Q(complex)
 Q(dict)
 Q(divmod)
+Q(eval)
 Q(float)
 Q(hash)
 Q(int)
diff --git a/py/parse.c b/py/parse.c
index e26e235..49b42e5 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -284,7 +284,7 @@
     int top_level_rule;
     switch (input_kind) {
         case MP_PARSE_SINGLE_INPUT: top_level_rule = RULE_single_input; break;
-        //case MP_PARSE_EVAL_INPUT: top_level_rule = RULE_eval_input; break;
+        case MP_PARSE_EVAL_INPUT: top_level_rule = RULE_eval_input; break;
         default: top_level_rule = RULE_file_input;
     }
     push_rule(parser, rules[top_level_rule], 0);
diff --git a/py/py.mk b/py/py.mk
index 95f9c07..16e0640 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -94,6 +94,7 @@
 	stream.o \
 	builtin.o \
 	builtinimport.o \
+	builtineval.o \
 	vm.o \
 	showbc.o \
 	repl.o \
diff --git a/py/runtime.c b/py/runtime.c
index cbdee01..594f79d 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -122,6 +122,7 @@
     mp_map_add_qstr(&map_builtins, MP_QSTR_callable, (mp_obj_t)&mp_builtin_callable_obj);
     mp_map_add_qstr(&map_builtins, MP_QSTR_chr, (mp_obj_t)&mp_builtin_chr_obj);
     mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
+    mp_map_add_qstr(&map_builtins, MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj);
     mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
     mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
     mp_map_add_qstr(&map_builtins, MP_QSTR_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
diff --git a/tests/basics/tests/eval1.py b/tests/basics/tests/eval1.py
new file mode 100644
index 0000000..8b9d02e
--- /dev/null
+++ b/tests/basics/tests/eval1.py
@@ -0,0 +1,13 @@
+# builtin eval
+
+eval('1 + 2')
+eval('1 + 2\n')
+eval('1 + 2\n\n#comment\n')
+
+x = 4
+eval('x')
+
+eval('lambda x: x + 10')(-5)
+
+y = 6
+eval('lambda: y * 2')()