Sweeten your JavaScript: hygienic macros for ES5

Tim Disney, Nathan Faubion, David Herman, C. Flanagan
{"title":"Sweeten your JavaScript: hygienic macros for ES5","authors":"Tim Disney, Nathan Faubion, David Herman, C. Flanagan","doi":"10.1145/2661088.2661097","DOIUrl":null,"url":null,"abstract":"Lisp and Scheme have demonstrated the power of macros to enable programmers to evolve and craft languages. In languages with more complex syntax, macros have had less success. In part, this has been due to the difficulty in building expressive hygienic macro systems for such languages. JavaScript in particular presents unique challenges for macro systems due to ambiguities in the lexing stage that force the JavaScript lexer and parser to be intertwined. In this paper we present a novel solution to the lexing ambiguity of JavaScript that enables us to cleanly separate the JavaScript lexer and parser by recording enough history during lexing to resolve ambiguities. We give an algorithm for this solution along with a proof that it does in fact correctly resolve ambiguities in the language. Though the algorithm and proof we present is specific to JavaScript, the general technique can be applied to other languages with ambiguous grammars. With lexer and parser separated, we then implement an expressive hygienic macro system for JavaScript called sweet.js.","PeriodicalId":244838,"journal":{"name":"Proceedings of the 10th ACM Symposium on Dynamic languages","volume":"57 Pt 2 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2014-10-14","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"17","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 10th ACM Symposium on Dynamic languages","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/2661088.2661097","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 17

Abstract

Lisp and Scheme have demonstrated the power of macros to enable programmers to evolve and craft languages. In languages with more complex syntax, macros have had less success. In part, this has been due to the difficulty in building expressive hygienic macro systems for such languages. JavaScript in particular presents unique challenges for macro systems due to ambiguities in the lexing stage that force the JavaScript lexer and parser to be intertwined. In this paper we present a novel solution to the lexing ambiguity of JavaScript that enables us to cleanly separate the JavaScript lexer and parser by recording enough history during lexing to resolve ambiguities. We give an algorithm for this solution along with a proof that it does in fact correctly resolve ambiguities in the language. Though the algorithm and proof we present is specific to JavaScript, the general technique can be applied to other languages with ambiguous grammars. With lexer and parser separated, we then implement an expressive hygienic macro system for JavaScript called sweet.js.
为ES5添加JavaScript:卫生宏
Lisp和Scheme已经展示了宏的强大功能,使程序员能够发展和创造语言。在语法更复杂的语言中,宏就不那么成功了。在某种程度上,这是由于为这些语言构建具有表现力的卫生宏系统的困难。由于词法分析阶段的模糊性迫使JavaScript词法分析器和解析器交织在一起,JavaScript尤其给宏系统带来了独特的挑战。在本文中,我们提出了一种新的解决JavaScript词法歧义的方法,通过在词法分析过程中记录足够的历史来解决歧义,使我们能够清晰地分离JavaScript词法分析器和解析器。我们给出了这个解决方案的一个算法,并证明它实际上正确地解决了语言中的歧义。虽然我们提供的算法和证明是特定于JavaScript的,但一般技术可以应用于语法不明确的其他语言。在词法分析器和解析器分离之后,我们为JavaScript实现了一个具有表现力的健康宏系统sweet.js。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信