{"id":57490,"date":"2018-02-28T08:17:32","date_gmt":"2018-02-27T23:17:32","guid":{"rendered":"http:\/\/www.softantenna.com\/wp\/?p=57490"},"modified":"2018-02-28T08:17:32","modified_gmt":"2018-02-27T23:17:32","slug":"tiny-interepter-and-compiler","status":"publish","type":"post","link":"https:\/\/softantenna.com\/blog\/tiny-interepter-and-compiler\/","title":{"rendered":"Tiny Interepter and Compiler - \u308f\u305a\u304b25\u884c\u306e\u30b3\u30fc\u30c9\u3067\u69cb\u6210\u3055\u308c\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e"},"content":{"rendered":"<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2018\/02\/Is_20180226_115303.jpg\" alt=\"S 20180226 115303\" title=\"s_20180226_115303.jpg\" border=\"0\" width=\"960\" height=\"612\" \/><\/p>\n<p>\u81ea\u5206\u306e\u601d\u3046\u304c\u307e\u307e\u306b\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u3092\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u300c\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u300d\u3002\u4e16\u754c\u4e2d\u306b\u306f\u3059\u3067\u306b\u591a\u304f\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u6bce\u5e74\u65b0\u3057\u3044\u8a00\u8a9e\u304c\u767b\u5834\u3057\u7d9a\u3051\u3066\u3044\u3066\u3001\u81ea\u5206\u81ea\u8eab\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u4f5c\u6210\u3057\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u308b\u958b\u767a\u8005\u306e\u65b9\u3082\u591a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u672c\u65e5\u7d39\u4ecb\u3059\u308b\u300c<a href=\"https:\/\/github.com\/mgechev\/tiny-compiler\">Tiny Interepter and Compiler<\/a>\u300d\u306f\u3001\u305d\u306e\u53d6\u308a\u304b\u304b\u308a\u3068\u306a\u308b\u3079\u304f\u958b\u767a\u3055\u308c\u305f\u3001\u5c0f\u3055\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u3059\u3002<\/p>\n<p>Angular\u30e2\u30d0\u30a4\u30eb\u30c1\u30fc\u30e0\u306e\u958b\u767a\u8005\u306e\u4e00\u4eba\u3067\u3042\u3063\u305fRhyme.com\u306eCTO\u3001Minko Gechev\u6c0f\u306b\u3088\u3063\u3066\u4f5c\u6210\u3055\u308c\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u3001JavaScript\u3092\u5229\u7528\u3057\u3066\u5c0f\u3055\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u657025\u884c\u3001\u30b3\u30e1\u30f3\u30c8\u3092\u5165\u308c\u308b\u3068140\u884c\u307b\u3069\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3001\u30ec\u30ad\u30b5\u3084\u30d1\u30fc\u30b5\u3001Abstract Syntax Tree(\u62bd\u8c61\u69cb\u6587\u6728)\u3001\u30b3\u30fc\u30c9\u306e\u5b9f\u884c\u65b9\u6cd5\u306a\u3069\u3001\u4f1d\u7d71\u7684\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u958b\u767a\u624b\u6cd5\u3092\u5b66\u3076\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<h2>Tiny Interepter and Compiler\u306e\u5229\u7528\u65b9\u6cd5<\/h2>\n<p>\u5b9f\u969b\u306b\u81ea\u5206\u3067\u52d5\u304b\u3057\u3066\u307f\u308b\u305f\u3081\u306b\u306f\u3001Git\u30ea\u30dd\u30b8\u30c8\u30ea\u3092clone\u3057\u307e\u3059\u3002<\/p>\n<pre>git clone https:\/\/github.com\/mgechev\/tiny-compiler.git\n<\/pre>\n<p>\u4e2d\u306b\u542b\u307e\u308c\u308btiny.js\u3092\u5b9f\u884c\u3059\u308b\u30682\u884c\u306e\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre>$ cd tiny-compiler\n$node tiny.js\n-18\n(3 * (2 - (1 + 3 + 4)))\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u6700\u5f8c\u306b\u306f\u3001\u3053\u306e\u5c0f\u3055\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u89e3\u91c8\u3055\u308c\u308b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u300cmul 3 sub 2 sum 1 3 4\u300d\u304c\u57cb\u3081\u8fbc\u307e\u308c\u3066\u3044\u3066\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u300c\u89e3\u91c8\u300d\u304a\u3088\u3073\u300c\u7ffb\u8a33\u300d\u3057\u305f\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3059\u3002<\/p>\n<pre>\n\nconst program = 'mul 3 sub 2 sum 1 3 4';\n\n\/*\n  # Interpreter\n  In order to interpret the input stream we feed the parser with the input\n  from the lexer and the evaluator with the output of the parser.\n*\/\nconsole.log(evaluate(parse(lex(program))));\n\n\/*\n  # Compiler\n  In order to compile the expression to JavaScript, the only change we need to make\n  is to update the outermost `evaluate` invocation to `compile`.\n*\/\nconsole.log(compile(parse(lex(program))));\n<\/pre>\n<p>program\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u6587\u5b57\u5217\u3092\u5909\u66f4\u3059\u308b\u3068\u3001\u5b9f\u884c\u7d50\u679c\u304c\u3069\u306e\u3088\u3046\u306b\u5909\u308f\u308b\u304b\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2018\/02\/Is_20180226_115326.jpg\" alt=\"S 20180226 115326\" title=\"s_20180226_115326.jpg\" border=\"0\" width=\"927\" height=\"312\" \/><\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p><img decoding=\"async\" style=\"display:block; margin-left:auto; margin-right:auto;\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2018\/02\/Iast.jpg\" alt=\"Ast\" title=\"ast.jpg\" border=\"0\" width=\"800\" height=\"588\" \/><\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u306b\u95a2\u3057\u3066\u306f\u3001\u540c\u4f5c\u8005\u306b\u3088\u308b\u30d6\u30ed\u30b0\u8a18\u4e8b\u300c<a href=\"http:\/\/blog.mgechev.com\/2017\/09\/16\/developing-simple-interpreter-transpiler-compiler-tutorial\/\">Implementing a Simple Compiler on 25 Lines of JavaScript<\/a>\u300d\u306b\u3066\u8a73\u3057\u304f\u89e3\u8aac\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u65b9\u6cd5\u3092\u5b66\u3073\u30b9\u30ad\u30eb\u30a2\u30c3\u30d7\u3057\u305f\u3044\u958b\u767a\u8005\u306e\u65b9\u306f\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u81ea\u5206\u306e\u601d\u3046\u304c\u307e\u307e\u306b\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u3092\u52d5\u4f5c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u300c\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u300d\u3002\u4e16\u754c\u4e2d\u306b\u306f\u3059\u3067\u306b\u591a\u304f\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304c\u5b58\u5728\u3057\u307e\u3059\u304c\u3001\u305d\u308c\u3067\u3082\u6bce\u5e74\u65b0\u3057\u3044\u8a00\u8a9e\u304c\u767b\u5834\u3057\u7d9a\u3051\u3066\u3044\u3066\u3001\u81ea\u5206\u81ea\u8eab\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u4f5c\u6210\u3057\u305f\u3044\u3068 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":57528,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[3459],"tags":[2808,4094],"class_list":["post-57490","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-review","tag-compiler","tag-interpreter"],"_links":{"self":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/57490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/comments?post=57490"}],"version-history":[{"count":0,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/57490\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media\/57528"}],"wp:attachment":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media?parent=57490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/categories?post=57490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/tags?post=57490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}