{"id":2894,"date":"2013-08-17T13:01:50","date_gmt":"2013-08-17T04:01:50","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2894"},"modified":"2013-08-17T13:01:50","modified_gmt":"2013-08-17T04:01:50","slug":"2-3-%e6%a7%8b%e6%96%87%e8%a7%a3%e6%9e%90%e5%99%a8%e3%81%ae%e5%9f%ba%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2894","title":{"rendered":"2.3. \u69cb\u6587\u89e3\u6790\u5668\u306e\u57fa\u672c"},"content":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c2\u7ae0 \u4e07\u83ef\u93e1: \u69cb\u6587\u89e3\u6790\u5668\u3068AST\u306e\u5b9f\u88c5<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl02.html#parser-basics\" target=\"_blank\">\u7b2c3\u7bc0 \u69cb\u6587\u89e3\u6790\u5668\u306e\u57fa\u672c<\/a><\/p>\n<p>\u3055\u3066\u3001AST\u3092\u69cb\u7bc9\u3059\u308b\u6e96\u5099\u304c\u3067\u304d\u305f\u306e\u3067\u3001\u6b21\u306f\u305d\u306e\u305f\u3081\u306e\u69cb\u6587\u89e3\u6790\u5668\u306e\u30b3\u30fc\u30c9\u3092\u5b9a\u7fa9\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u4f8b\u3048\u3070&#8221;x+y&#8221;\uff08\u5b57\u53e5\u89e3\u6790\u5668\u304b\u30893\u3064\u306e\u30c8\u30fc\u30af\u30f3\u3068\u3057\u3066\u8fd4\u3055\u308c\u308b\uff09\u3092\u69cb\u6587\u89e3\u6790\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067AST\u3092\u751f\u6210\u3057\u305f\u3044\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">ExprAST *X = new VariableExprAST(&quot;x&quot;);\r\nExprAST *Y = new VariableExprAST(&quot;y&quot;);\r\nExprAST *Result = new BinaryExprAST('+', X, Y);<\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306b\u3001\u5e7e\u3064\u304b\u306e\u57fa\u672c\u7684\u306a\u30d8\u30eb\u30d1\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304b\u3089\u306f\u3058\u3081\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/\/ CurTok\/getNextToken - \u30b7\u30f3\u30d7\u30eb\u306a\u30c8\u30fc\u30af\u30f3\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u63d0\u4f9b\u3059\u308b\u3002\r\n\/\/\/ CurTok\u306f\u69cb\u6587\u89e3\u6790\u5668\u304c\u73fe\u5728\u51e6\u7406\u4e2d\u306e\u30c8\u30fc\u30af\u30f3\u3067\u3042\u308b\u3002\r\n\/\/\/ getNextToken\u306f\u5b57\u53e5\u89e3\u6790\u5668\u304b\u3089\u5225\u306e\u30c8\u30fc\u30af\u30f3\u3092\u8aad\u307f\u53d6\u308a\u3001\u305d\u306e\u7d50\u679c\u3067CurTok\u3092\u66f4\u65b0\u3059\u308b\u3002\r\nstatic int CurTok;\r\nstatic int getNextToken() {\r\n  return CurTok = gettok();\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u3001\u5b57\u53e5\u89e3\u6790\u5668\u306b\u30c8\u30fc\u30af\u30f3\u7528\u306e\u7c21\u6613\u7684\u306a\u30d0\u30c3\u30d5\u30a1\u304c\u7528\u610f\u3055\u308c\u305f\u3053\u3068\u306b\u306a\u308b\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u5b57\u53e5\u89e3\u6790\u5668\u304c\u8fd4\u3057\u305f\u30c8\u30fc\u30af\u30f3\u306b\u3064\u3044\u3066\u8abf\u3079\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\n\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u306e\u5404\u95a2\u6570\u306f\u3001\u89e3\u6790\u3055\u308c\u308b\u3079\u304d\u73fe\u5728\u306e\u30c8\u30fc\u30af\u30f3\u304cCurTok\u306b\u5165\u3063\u3066\u308b\u3068\u4eee\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ Error* - \u3053\u308c\u3089\u306f\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u305f\u3081\u306e\u5c0f\u3055\u306a\u95a2\u6570\u7fa4\u3067\u3042\u308b\u3002\r\nExprAST *Error(const char *Str) { fprintf(stderr, &quot;Error: %s\\n&quot;, Str);return 0;}\r\nPrototypeAST *ErrorP(const char *Str) { Error(Str); return 0; }\r\nFunctionAST *ErrorF(const char *Str) { Error(Str); return 0; }<\/pre>\n<p>Error\u95a2\u6570\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3067\u3001\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u304c\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u4f7f\u3046\u3002<br \/>\n\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u306b\u304a\u3051\u308b\u30a8\u30e9\u30fc\u306e\u56de\u5fa9\u306f\u3001\u30d9\u30b9\u30c8\u3067\u306f\u306a\u3044\u3057\u7d30\u304b\u3044\u3068\u3053\u308d\u3067\u30e6\u30fc\u30b6\u30fc\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u3067\u3082\u306a\u3044\u3002<br \/>\n\u3057\u304b\u3057\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u305d\u308c\u3067\u5341\u5206\u3067\u3042\u308b\u3002<br \/>\n\u3053\u308c\u3089\u306e\u95a2\u6570\u306f\u3001\u623b\u308a\u5024\u306e\u578b\u304c\u9055\u3046\u69d8\u3005\u306a\u95a2\u6570\u306b\u304a\u3051\u308b\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u7c21\u5358\u306b\u3059\u308b\u3002\uff08\u3053\u308c\u3089\u306f\u5e38\u306bnull\u3092\u8fd4\u3059\u3002\uff09<br \/>\n\u4ee5\u4e0a\u306e\u57fa\u672c\u7684\u306a\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u306b\u3088\u3063\u3066\u3001\u6211\u3005\u306e\u6587\u6cd5\u306e\u6700\u521d\u306e\u3072\u3068\u3064\u3001\u6570\u5024\u30ea\u30c6\u30e9\u30eb\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u3063\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c2\u7ae0 \u4e07\u83ef\u93e1: \u69cb\u6587\u89e3\u6790\u5668\u3068AST\u306e\u5b9f\u88c5<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl02.html#parser-basics\" target=\"_blank\">\u7b2c3\u7bc0 \u69cb\u6587\u89e3\u6790\u5668\u306e\u57fa\u672c<\/a><\/p>\n<p>\u3055\u3066\u3001AST\u3092\u69cb\u7bc9\u3059\u308b\u6e96\u5099\u304c\u3067\u304d\u305f\u306e\u3067\u3001\u6b21\u306f\u305d\u306e\u305f\u3081\u306e\u69cb\u6587\u89e3\u6790\u5668\u306e\u30b3\u30fc\u30c9\u3092\u5b9a\u7fa9\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<br \/>\n\u4f8b\u3048\u3070&#8221;x+y&#8221;\uff08\u5b57\u53e5\u89e3\u6790\u5668\u304b\u30893\u3064\u306e\u30c8\u30fc\u30af\u30f3\u3068\u3057\u3066\u8fd4\u3055\u308c\u308b\uff09\u3092\u69cb\u6587\u89e3\u6790\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067AST\u3092\u751f\u6210\u3057\u305f\u3044\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">ExprAST *X = new VariableExprAST(&quot;x&quot;);\r\nExprAST *Y = new VariableExprAST(&quot;y&quot;);\r\nExprAST *Result = new BinaryExprAST('+', X, Y);<\/pre>\n<p>\u3053\u308c\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306b\u3001\u5e7e\u3064\u304b\u306e\u57fa\u672c\u7684\u306a\u30d8\u30eb\u30d1\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304b\u3089\u306f\u3058\u3081\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/\/ CurTok\/getNextToken - \u30b7\u30f3\u30d7\u30eb\u306a\u30c8\u30fc\u30af\u30f3\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u63d0\u4f9b\u3059\u308b\u3002\r\n\/\/\/ CurTok\u306f\u69cb\u6587\u89e3\u6790\u5668\u304c\u73fe\u5728\u51e6\u7406\u4e2d\u306e\u30c8\u30fc\u30af\u30f3\u3067\u3042\u308b\u3002\r\n\/\/\/ getNextToken\u306f\u5b57\u53e5\u89e3\u6790\u5668\u304b\u3089\u5225\u306e\u30c8\u30fc\u30af\u30f3\u3092\u8aad\u307f\u53d6\u308a\u3001\u305d\u306e\u7d50\u679c\u3067CurTok\u3092\u66f4\u65b0\u3059\u308b\u3002\r\nstatic int CurTok;\r\nstatic int getNextToken() {\r\n  return CurTok = gettok();\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u3001\u5b57\u53e5\u89e3\u6790\u5668\u306b\u30c8\u30fc\u30af\u30f3\u7528\u306e\u7c21\u6613\u7684\u306a\u30d0\u30c3\u30d5\u30a1\u304c\u7528\u610f\u3055\u308c\u305f\u3053\u3068\u306b\u306a\u308b\u3002<br \/>\n\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u5b57\u53e5\u89e3\u6790\u5668\u304c\u8fd4\u3057\u305f\u30c8\u30fc\u30af\u30f3\u306b\u3064\u3044\u3066\u8abf\u3079\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\n\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u306e\u5404\u95a2\u6570\u306f\u3001\u89e3\u6790\u3055\u308c\u308b\u3079\u304d\u73fe\u5728\u306e\u30c8\u30fc\u30af\u30f3\u304cCurTok\u306b\u5165\u3063\u3066\u308b\u3068\u4eee\u5b9a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ Error* - \u3053\u308c\u3089\u306f\u30a8\u30e9\u30fc\u51e6\u7406\u306e\u305f\u3081\u306e\u5c0f\u3055\u306a\u95a2\u6570\u7fa4\u3067\u3042\u308b\u3002\r\nExprAST *Error(const char *Str) { fprintf(stderr, &quot;Error: %s\\n&quot;, Str);return 0;}\r\nPrototypeAST *ErrorP(const char *Str) { Error(Str); return 0; }\r\nFunctionAST *ErrorF(const char *Str) { Error(Str); return 0; }<\/pre>\n<p>Error\u95a2\u6570\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3067\u3001\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u304c\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u4f7f\u3046\u3002<br \/>\n\u6211\u3005\u306e\u69cb\u6587\u89e3\u6790\u5668\u306b\u304a\u3051\u308b\u30a8\u30e9\u30fc\u306e\u56de\u5fa9\u306f\u3001\u30d9\u30b9\u30c8\u3067\u306f\u306a\u3044\u3057\u7d30\u304b\u3044\u3068\u3053\u308d\u3067\u30e6\u30fc\u30b6\u30fc\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u3067\u3082\u306a\u3044\u3002<br \/>\n\u3057\u304b\u3057\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u305d\u308c\u3067\u5341\u5206\u3067\u3042\u308b\u3002<br \/>\n\u3053\u308c\u3089\u306e\u95a2\u6570\u306f\u3001\u623b\u308a\u5024\u306e\u578b\u304c\u9055\u3046\u69d8\u3005\u306a\u95a2\u6570\u306b\u304a\u3051\u308b\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u7c21\u5358\u306b\u3059\u308b\u3002\uff08\u3053\u308c\u3089\u306f\u5e38\u306bnull\u3092\u8fd4\u3059\u3002\uff09<br \/>\n\u4ee5\u4e0a\u306e\u57fa\u672c\u7684\u306a\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u306b\u3088\u3063\u3066\u3001\u6211\u3005\u306e\u6587\u6cd5\u306e\u6700\u521d\u306e\u3072\u3068\u3064\u3001\u6570\u5024\u30ea\u30c6\u30e9\u30eb\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3068\u306a\u3063\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[466,467],"class_list":["post-2894","post","type-post","status-publish","format-standard","hentry","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=2894"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2894\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}