解析表現文法とSchemeマクロ展開器を用いたJavaScript向けHygienic構文マクロシステムの実装

書誌事項

タイトル別名
  • An Implementation of a Hygienic Syntactic Macro System for JavaScript Using Parsing Expression Grammar and a Scheme Macro Expander

この論文をさがす

抄録

本稿は,JavaScriptの構文拡張を可能にするHygienic構文マクロシステムの実装技法を提案する.Hygienic構文マクロシステムは,マクロ展開の前後で変数の束縛や参照関係を破壊しない安全な構文マクロシステムである.このHygienic構文マクロシステムを利用することによって,プログラミング言語の構文の自由な拡張が可能になる.しかし,Hygienic構文マクロシステムは,S式という一貫した構文構造を持つSchemeには標準で組み込まれているものの,その他の一般的なプログラミング言語に実装された例はほとんどない.本稿では,まず,汎用的なプログラミング言語におけるHygienic構文マクロシステムの実装の難しさを示し,次に,本研究が提案するJavaScript向けHygienic構文マクロシステムの実装技法について述べる.提案する実装技法では,マクロ構文の追加によって拡張されるJavaScript構文を解析するための拡張可能なパーザの実現に解析表現文法を用い,マクロ展開は既存のSchemeマクロ展開器に委ねる.マクロ展開においては,マクロを含むJavaScriptコードをそれと等価なS式へと変換し,Schemeマクロ展開器で展開を行った後に,JavaScriptコードに逆変換するという言語間相互変換を行う.これらの工夫によりわずか2,000行弱のコンパクトな実装によってJavaScriptに対する記述力が高いHygienic構文マクロシステムを実現できた.

The article introduces an implementation scheme for a hygienic syntactic macro system that adds syntactic extensibility to JavaScript. A hygienic syntactic macro system guarantees certain level of semantic soundness by ensuring variable binding and referencing semantics to be maintained before and after macro expansion. Although a hygienic macro system is a powerful tool for extending programming language syntax, its implementation is found only in Scheme and few other programming languages. The article identifies technical difficulty for adding a hygienic macro feature to programming languages other than LISP and then describes a simple implementation scheme, where the extensible parser is built by dynamic generation of parsing expression grammar descriptions, and macro expansion is performed by delegating the task to Scheme. Our macro expander firstly translates the macro-enhanced JavaScript code to equivalent S-expression, lets the macro expander of Scheme expand the S-expression, and finally translates the macro-free S-expression back to macro-free JavaScript source program. This smart implementation scheme allows us to implement an expressive hygienic macro system with less than 2,000 lines of code.

収録刊行物

関連プロジェクト

もっと見る

詳細情報 詳細情報について

  • CRID
    1050845762833422464
  • NII論文ID
    110009602861
  • NII書誌ID
    AA11464814
  • ISSN
    18827802
  • Web Site
    http://id.nii.ac.jp/1001/00094924/
  • 本文言語コード
    ja
  • 資料種別
    article
  • データソース種別
    • IRDB
    • CiNii Articles
    • KAKEN

問題の指摘

ページトップへ