{"id":2912,"date":"2013-08-20T15:36:23","date_gmt":"2013-08-20T06:36:23","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2912"},"modified":"2013-08-20T15:36:23","modified_gmt":"2013-08-20T06:36:23","slug":"2-6-%e6%ae%8b%e3%82%8a%e3%81%ae%e6%a7%8b%e6%96%87%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2912","title":{"rendered":"2.6. \u6b8b\u308a\u306e\u69cb\u6587\u89e3\u6790"},"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#parsing-the-rest\" target=\"_blank\">\u7b2c6\u7bc0 \u6b8b\u308a\u306e\u69cb\u6587\u89e3\u6790<\/a><\/p>\n<p>\u307e\u3060\u3084\u3063\u3066\u306a\u3044\u306e\u306f\u3001\u95a2\u6570\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u51e6\u7406\u3067\u3042\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u3067\u306f\u3001\u95a2\u6570\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u3068\u540c\u3058\u3088\u3046\u306b&#8221;extern&#8221;\u95a2\u6570\u306e\u5b9a\u7fa9\u306b\u3082\u4f7f\u7528\u3055\u308c\u308b\u3002<br \/>\n\u3053\u308c\u3092\u884c\u3046\u30b3\u30fc\u30c9\u306f\u3001\u307e\u3041\u99ac\u9e7f\u6b63\u76f4\u3067\u9762\u767d\u3044\u3068\u3053\u308d\u306f\u3042\u307e\u308a\u306a\u3044\u3002\uff08\u5f0f\u306e\u51e6\u7406\u306b\u3064\u3044\u3066\u7406\u89e3\u3057\u3066\u305f\u3089\u3060\u3051\u3069\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ \u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\r\n\/\/\/   ::= id '(' id* ')'\r\nstatic PrototypeAST *ParsePrototype() {\r\n  if (CurTok != tok_identifier)\r\n    return ErrorP(&quot;Expected function name in prototype&quot;);\r\n\r\n  std::string FnName = IdentifierStr;\r\n  getNextToken();\r\n\r\n  if (CurTok != '(')\r\n    return ErrorP(&quot;Expected '(' in prototype&quot;);\r\n\r\n  \/\/ \u5f15\u6570\u306e\u540d\u524d\u306e\u30ea\u30b9\u30c8\u3092\u8aad\u307f\u53d6\u308b\u3002\r\n  std::vector&lt;std::string&gt; ArgNames;\r\n  while (getNextToken() == tok_identifier)\r\n    ArgNames.push_back(IdentifierStr);\r\n  if (CurTok != ')')\r\n    return ErrorP(&quot;Expected ')' in prototype&quot;);\r\n\r\n  \/\/ \u6210\u529f\u3002\r\n  getNextToken();  \/\/ ')'\u3092\u6d88\u8cbb\u3002\r\n\r\n  return new PrototypeAST(FnName, ArgNames);\r\n}<\/pre>\n<p>\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u95a2\u6570\u5b9a\u7fa9\u306f\u3068\u3066\u3082\u7c21\u5358\u306b\u306a\u308b\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u3001\u95a2\u6570\u672c\u4f53\u3092\u5b9f\u88c5\u3059\u308b\u305f\u3081\u306e\u5f0f\u3092\u30d7\u30e9\u30b9\u3059\u308b\u3060\u3051\u3067\u3088\u3044\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ definition ::= 'def' prototype expression\r\nstatic FunctionAST *ParseDefinition() {\r\n  getNextToken();  \/\/ &quot;def&quot;\u3092\u6d88\u8cbb\u3002\r\n  PrototypeAST *Proto = ParsePrototype();\r\n  if (Proto == 0) return 0;\r\n\r\n  if (ExprAST *E = ParseExpression())\r\n    return new FunctionAST(Proto, E);\r\n  return 0;\r\n}<\/pre>\n<p>\u3055\u3089\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u95a2\u6570\u306e\u524d\u65b9\u5ba3\u8a00\u3068\u540c\u3058\u3088\u3046\u306b&#8221;sin&#8221;\u3084\u201dcos&#8221;\u306a\u3069\u306e\u95a2\u6570\u306e&#8221;extern&#8221;\u5ba3\u8a00\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3002<br \/>\n&#8220;extern&#8221;\u306f\u3001\u95a2\u6570\u672c\u4f53\u304c\u306a\u3044\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u305d\u306e\u3082\u306e\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ external ::= 'extern' prototype\r\nstatic PrototypeAST *ParseExtern() {\r\n  getNextToken();  \/\/ &quot;extern&quot;\u3092\u6d88\u8cbb\u3002\r\n  return ParsePrototype();\r\n}<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u66f8\u3044\u305f\u4efb\u610f\u306e\u30c8\u30c3\u30d7\u30ec\u30d9\u30eb\u306e\u5f0f\u3092\u305d\u306e\u307e\u307e\u8a55\u4fa1\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u3053\u308c\u3092\u3001\u7121\u540d\u3067\u5f15\u6570\u304c\u7121\u3044\u95a2\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u4e8b\u306b\u3088\u3063\u3066\u51e6\u7406\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ toplevelexpr ::= expression\r\nstatic FunctionAST *ParseTopLevelExpr() {\r\n  if (ExprAST *E = ParseExpression()) {\r\n    \/\/ \u7121\u540d\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u6210\u3059\u308b\u3002\r\n    PrototypeAST *Proto = new PrototypeAST(&quot;&quot;, std::vector&lt;std::string&gt;());\r\n    return new FunctionAST(Proto, E);\r\n  }\r\n  return 0;\r\n}<\/pre>\n<p>\u3055\u3066\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u5168\u3066\u306e\u30d1\u30fc\u30c4\u306f\u305d\u308d\u3063\u305f\u3002<br \/>\n\u6b21\u306f\u3001\u3053\u308c\u307e\u3067\u6211\u3005\u304c\u66f8\u3044\u3066\u304d\u305f\u30b3\u30fc\u30c9\u3092\u5b9f\u969b\u306b\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u3001\u5c0f\u3055\u306a\u30c9\u30e9\u30a4\u30d0\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3088\u3046\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#parsing-the-rest\" target=\"_blank\">\u7b2c6\u7bc0 \u6b8b\u308a\u306e\u69cb\u6587\u89e3\u6790<\/a><\/p>\n<p>\u307e\u3060\u3084\u3063\u3066\u306a\u3044\u306e\u306f\u3001\u95a2\u6570\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306e\u51e6\u7406\u3067\u3042\u308b\u3002<br \/>\n\u4e07\u83ef\u93e1\u3067\u306f\u3001\u95a2\u6570\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306f\u3001\u95a2\u6570\u672c\u4f53\u306e\u5b9a\u7fa9\u3068\u540c\u3058\u3088\u3046\u306b&#8221;extern&#8221;\u95a2\u6570\u306e\u5b9a\u7fa9\u306b\u3082\u4f7f\u7528\u3055\u308c\u308b\u3002<br \/>\n\u3053\u308c\u3092\u884c\u3046\u30b3\u30fc\u30c9\u306f\u3001\u307e\u3041\u99ac\u9e7f\u6b63\u76f4\u3067\u9762\u767d\u3044\u3068\u3053\u308d\u306f\u3042\u307e\u308a\u306a\u3044\u3002\uff08\u5f0f\u306e\u51e6\u7406\u306b\u3064\u3044\u3066\u7406\u89e3\u3057\u3066\u305f\u3089\u3060\u3051\u3069\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ \u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\r\n\/\/\/   ::= id '(' id* ')'\r\nstatic PrototypeAST *ParsePrototype() {\r\n  if (CurTok != tok_identifier)\r\n    return ErrorP(&quot;Expected function name in prototype&quot;);\r\n\r\n  std::string FnName = IdentifierStr;\r\n  getNextToken();\r\n\r\n  if (CurTok != '(')\r\n    return ErrorP(&quot;Expected '(' in prototype&quot;);\r\n\r\n  \/\/ \u5f15\u6570\u306e\u540d\u524d\u306e\u30ea\u30b9\u30c8\u3092\u8aad\u307f\u53d6\u308b\u3002\r\n  std::vector&lt;std::string&gt; ArgNames;\r\n  while (getNextToken() == tok_identifier)\r\n    ArgNames.push_back(IdentifierStr);\r\n  if (CurTok != ')')\r\n    return ErrorP(&quot;Expected ')' in prototype&quot;);\r\n\r\n  \/\/ \u6210\u529f\u3002\r\n  getNextToken();  \/\/ ')'\u3092\u6d88\u8cbb\u3002\r\n\r\n  return new PrototypeAST(FnName, ArgNames);\r\n}<\/pre>\n<p>\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u95a2\u6570\u5b9a\u7fa9\u306f\u3068\u3066\u3082\u7c21\u5358\u306b\u306a\u308b\u3002<br \/>\n\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u306b\u3001\u95a2\u6570\u672c\u4f53\u3092\u5b9f\u88c5\u3059\u308b\u305f\u3081\u306e\u5f0f\u3092\u30d7\u30e9\u30b9\u3059\u308b\u3060\u3051\u3067\u3088\u3044\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ definition ::= 'def' prototype expression\r\nstatic FunctionAST *ParseDefinition() {\r\n  getNextToken();  \/\/ &quot;def&quot;\u3092\u6d88\u8cbb\u3002\r\n  PrototypeAST *Proto = ParsePrototype();\r\n  if (Proto == 0) return 0;\r\n\r\n  if (ExprAST *E = ParseExpression())\r\n    return new FunctionAST(Proto, E);\r\n  return 0;\r\n}<\/pre>\n<p>\u3055\u3089\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u95a2\u6570\u306e\u524d\u65b9\u5ba3\u8a00\u3068\u540c\u3058\u3088\u3046\u306b&#8221;sin&#8221;\u3084\u201dcos&#8221;\u306a\u3069\u306e\u95a2\u6570\u306e&#8221;extern&#8221;\u5ba3\u8a00\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3002<br \/>\n&#8220;extern&#8221;\u306f\u3001\u95a2\u6570\u672c\u4f53\u304c\u306a\u3044\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u305d\u306e\u3082\u306e\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ external ::= 'extern' prototype\r\nstatic PrototypeAST *ParseExtern() {\r\n  getNextToken();  \/\/ &quot;extern&quot;\u3092\u6d88\u8cbb\u3002\r\n  return ParsePrototype();\r\n}<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u66f8\u3044\u305f\u4efb\u610f\u306e\u30c8\u30c3\u30d7\u30ec\u30d9\u30eb\u306e\u5f0f\u3092\u305d\u306e\u307e\u307e\u8a55\u4fa1\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u3053\u308c\u3092\u3001\u7121\u540d\u3067\u5f15\u6570\u304c\u7121\u3044\u95a2\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3059\u308b\u4e8b\u306b\u3088\u3063\u3066\u51e6\u7406\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/\/ toplevelexpr ::= expression\r\nstatic FunctionAST *ParseTopLevelExpr() {\r\n  if (ExprAST *E = ParseExpression()) {\r\n    \/\/ \u7121\u540d\u306e\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7\u3092\u4f5c\u6210\u3059\u308b\u3002\r\n    PrototypeAST *Proto = new PrototypeAST(&quot;&quot;, std::vector&lt;std::string&gt;());\r\n    return new FunctionAST(Proto, E);\r\n  }\r\n  return 0;\r\n}<\/pre>\n<p>\u3055\u3066\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u5168\u3066\u306e\u30d1\u30fc\u30c4\u306f\u305d\u308d\u3063\u305f\u3002<br \/>\n\u6b21\u306f\u3001\u3053\u308c\u307e\u3067\u6211\u3005\u304c\u66f8\u3044\u3066\u304d\u305f\u30b3\u30fc\u30c9\u3092\u5b9f\u969b\u306b\u5b9f\u884c\u3059\u308b\u305f\u3081\u306b\u3001\u5c0f\u3055\u306a\u30c9\u30e9\u30a4\u30d0\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3088\u3046\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-2912","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\/2912","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=2912"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2912\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}