PaGe:便携式LALR(1)解析器生成器

Suda Keishi, Abe Seika
{"title":"PaGe:便携式LALR(1)解析器生成器","authors":"Suda Keishi, Abe Seika","doi":"10.1145/2635648.2635650","DOIUrl":null,"url":null,"abstract":"PaGe is a portable, compact and reliable LALR(1) parser generator with more general disambiguation method compared to that of traditional parser generator such as Bison. From the past to the present, very many parser generators are implemented in various programming languages. In particular, Bison in C language is a notable one due to its high efficiency and reliability. It is surely the de fact standard parser generator in C. We have recently faced with a requirement of making some parsers for relatively large languages in Common Lisp. We prefer commercial products due to its reliability and user supports. Especially, problems with such complex tool should only be solved by someone who has deep knowledge about the tool. Thus, we chose ACL (Allegro Common Lisp) which is one of the most widely used Lisp programming environment. Unfortunately, ACL does not provide official parser generator. As for free software, as far as we know, there is no such tool comparable to Bison in the above sense. Since Lisp has powerful and universal syntactic expression, namely S-expression, it is sufficient for Lispers to express and handle any syntactic objects. We suspect that that is why parser generators are not so important to Lispers. Nevertheless reliable parser generator in Lisp is needed when we develop tools dealing with anther languages, such as compilers and program analizers. This is the motivation for developing original parser generator in Lisp. One of PaGe's concept is to give a legible implementation of DeRemer's method for Look-Ahead Set. This method makes us enable to generate LALR(1)-parsing-table dircetly from LR(0)-parsing-table by computing Look-Ahead Set based on formal definitions of them. For example, DeRemer's method has used in Bison, but there is few other implementation, particularly on Lisp. Therefore we decided to give a legible implementation for who would like to understand it. Other concept is to simplify PaGe's core program for efficiency and readability as possible. As a result, PaGe is composed of parser generator engine PaGEn and its wrapper. PaGEn is a pared parser-generator engine. PaGEn's input is a grammar whose \"symbols\" are restricted to non-negative integer. By this restriction, we were able to establish both program efficiency and algorithm readablity, for instance we can naturally use array as function. Consequently, the role of wrapper are mainly two of translation and interpreting. A wrapper translates symbolic input such as grammar or sequence of token into numeric input for PaGEn. PaGEn get this as input and return parsing-table or result of parse, for instance. Then the wrapper interprets this result for an user or other system. Now, we have defined only the wrapper for using PaGEn in the same way for traditional parser generator. If you wish to use PaGEn for other purpose, you need only to define the wrapper. Furthermore, PaGEn can deal with ambiguous grammar i.e. it supports disambiguation. PaGEn's disambiguation method is so simple. First we give two priority to each rule for reduce-time and shift-time. If some conflict has occurred, then, we try to solve each conflicts by comparing priorities. For Reduce/Reduce-conflicts, we solve it by Reduce using the rule which has the greatest reduce-time-priority in conflicted rules. For Shift/Reduce-conflicts, 2 pattern exists. If the propagation-priority, computed from several shift-time-priorities, is greater than the reduce-time-priority of the rule, we solve by shift. If the reduce-time-priority is greater than the propagation-priority we solve by reduce. This method is more general than the method which specifies the associativity of an operator directly, in translatability sense. And, dangling-else probrem can be solved uniformly in this method.","PeriodicalId":113396,"journal":{"name":"Proceedings of ILC 2014 on 8th International Lisp Conference","volume":"48 5 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2014-08-14","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":"{\"title\":\"PaGe: Portable LALR(1) Parser Generator\",\"authors\":\"Suda Keishi, Abe Seika\",\"doi\":\"10.1145/2635648.2635650\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"PaGe is a portable, compact and reliable LALR(1) parser generator with more general disambiguation method compared to that of traditional parser generator such as Bison. From the past to the present, very many parser generators are implemented in various programming languages. In particular, Bison in C language is a notable one due to its high efficiency and reliability. It is surely the de fact standard parser generator in C. We have recently faced with a requirement of making some parsers for relatively large languages in Common Lisp. We prefer commercial products due to its reliability and user supports. Especially, problems with such complex tool should only be solved by someone who has deep knowledge about the tool. Thus, we chose ACL (Allegro Common Lisp) which is one of the most widely used Lisp programming environment. Unfortunately, ACL does not provide official parser generator. As for free software, as far as we know, there is no such tool comparable to Bison in the above sense. Since Lisp has powerful and universal syntactic expression, namely S-expression, it is sufficient for Lispers to express and handle any syntactic objects. We suspect that that is why parser generators are not so important to Lispers. Nevertheless reliable parser generator in Lisp is needed when we develop tools dealing with anther languages, such as compilers and program analizers. This is the motivation for developing original parser generator in Lisp. One of PaGe's concept is to give a legible implementation of DeRemer's method for Look-Ahead Set. This method makes us enable to generate LALR(1)-parsing-table dircetly from LR(0)-parsing-table by computing Look-Ahead Set based on formal definitions of them. For example, DeRemer's method has used in Bison, but there is few other implementation, particularly on Lisp. Therefore we decided to give a legible implementation for who would like to understand it. Other concept is to simplify PaGe's core program for efficiency and readability as possible. As a result, PaGe is composed of parser generator engine PaGEn and its wrapper. PaGEn is a pared parser-generator engine. PaGEn's input is a grammar whose \\\"symbols\\\" are restricted to non-negative integer. By this restriction, we were able to establish both program efficiency and algorithm readablity, for instance we can naturally use array as function. Consequently, the role of wrapper are mainly two of translation and interpreting. A wrapper translates symbolic input such as grammar or sequence of token into numeric input for PaGEn. PaGEn get this as input and return parsing-table or result of parse, for instance. Then the wrapper interprets this result for an user or other system. Now, we have defined only the wrapper for using PaGEn in the same way for traditional parser generator. If you wish to use PaGEn for other purpose, you need only to define the wrapper. Furthermore, PaGEn can deal with ambiguous grammar i.e. it supports disambiguation. PaGEn's disambiguation method is so simple. First we give two priority to each rule for reduce-time and shift-time. If some conflict has occurred, then, we try to solve each conflicts by comparing priorities. For Reduce/Reduce-conflicts, we solve it by Reduce using the rule which has the greatest reduce-time-priority in conflicted rules. For Shift/Reduce-conflicts, 2 pattern exists. If the propagation-priority, computed from several shift-time-priorities, is greater than the reduce-time-priority of the rule, we solve by shift. If the reduce-time-priority is greater than the propagation-priority we solve by reduce. This method is more general than the method which specifies the associativity of an operator directly, in translatability sense. And, dangling-else probrem can be solved uniformly in this method.\",\"PeriodicalId\":113396,\"journal\":{\"name\":\"Proceedings of ILC 2014 on 8th International Lisp Conference\",\"volume\":\"48 5 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2014-08-14\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"0\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Proceedings of ILC 2014 on 8th International Lisp Conference\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/2635648.2635650\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of ILC 2014 on 8th International Lisp Conference","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/2635648.2635650","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0

摘要

PaGe是一个便携、紧凑、可靠的LALR(1)解析器生成器,与Bison等传统解析器生成器相比,它具有更通用的消歧方法。从过去到现在,很多解析器生成器都是用各种编程语言实现的。其中,C语言的Bison以其高效率和高可靠性而备受关注。事实上,它是c语言中标准的解析器生成器。我们最近面临着用Common Lisp为相对较大的语言制作一些解析器的需求。我们更喜欢商业产品,因为它的可靠性和用户支持。特别是,这种复杂工具的问题只能由对工具有深入了解的人来解决。因此,我们选择了使用最广泛的Lisp编程环境之一ACL (Allegro Common Lisp)。遗憾的是,ACL没有提供官方的解析器生成器。至于自由软件,据我们所知,在上述意义上,没有这样的工具可以与Bison相媲美。由于Lisp具有强大而通用的语法表达式,即s -表达式,因此Lispers可以表达和处理任何语法对象。我们怀疑这就是解析器生成器对Lispers不那么重要的原因。然而,当我们开发处理其他语言的工具(如编译器和程序分析器)时,需要Lisp中可靠的解析器生成器。这就是在Lisp中开发原始解析器生成器的动机。PaGe的概念之一是为forward - ahead Set提供一个清晰的DeRemer方法的实现。该方法使我们能够根据LR(0)-解析表的形式化定义,通过计算forward Set,直接从LALR(1)-解析表生成LALR(1)-解析表。例如,在Bison中使用了DeRemer的方法,但很少有其他实现,特别是在Lisp上。因此,我们决定为想要理解它的人提供一个清晰的实现。另一个概念是尽可能简化PaGe的核心程序,以提高效率和可读性。因此,PaGe由解析器生成器引擎PaGEn及其包装器组成。PaGEn是一个经过优化的解析器生成器引擎。PaGEn的输入是一个语法,其“符号”被限制为非负整数。通过这个限制,我们能够建立程序效率和算法可读性,例如,我们可以自然地使用数组作为函数。因此,包装的作用主要是翻译和口译两种。包装器将符号输入(如语法或记号序列)转换为PaGEn的数字输入。例如,PaGEn将其作为输入并返回解析表或解析结果。然后包装器为用户或其他系统解释此结果。现在,我们只定义了包装器,以与传统解析器生成器相同的方式使用PaGEn。如果希望将PaGEn用于其他目的,只需要定义包装器。此外,PaGEn可以处理歧义语法,即它支持消歧义。PaGEn的消歧方法非常简单。首先,我们给每条规则分别赋予了reduce-time和shift-time两个优先级。如果发生了一些冲突,那么,我们尝试通过比较优先级来解决每个冲突。对于Reduce/Reduce-conflicts,我们使用冲突规则中Reduce- time优先级最大的规则进行Reduce解决。对于Shift/ reduce -conflict,存在2模式。如果由多个移位时间优先级计算得到的传播优先级大于该规则的缩减时间优先级,则采用移位求解。如果减少时间优先级大于传播优先级,我们通过减少来解决。在可译性的意义上,这种方法比直接指定操作符的结合性的方法更通用。并且,该方法可以统一地求解悬垂问题。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
PaGe: Portable LALR(1) Parser Generator
PaGe is a portable, compact and reliable LALR(1) parser generator with more general disambiguation method compared to that of traditional parser generator such as Bison. From the past to the present, very many parser generators are implemented in various programming languages. In particular, Bison in C language is a notable one due to its high efficiency and reliability. It is surely the de fact standard parser generator in C. We have recently faced with a requirement of making some parsers for relatively large languages in Common Lisp. We prefer commercial products due to its reliability and user supports. Especially, problems with such complex tool should only be solved by someone who has deep knowledge about the tool. Thus, we chose ACL (Allegro Common Lisp) which is one of the most widely used Lisp programming environment. Unfortunately, ACL does not provide official parser generator. As for free software, as far as we know, there is no such tool comparable to Bison in the above sense. Since Lisp has powerful and universal syntactic expression, namely S-expression, it is sufficient for Lispers to express and handle any syntactic objects. We suspect that that is why parser generators are not so important to Lispers. Nevertheless reliable parser generator in Lisp is needed when we develop tools dealing with anther languages, such as compilers and program analizers. This is the motivation for developing original parser generator in Lisp. One of PaGe's concept is to give a legible implementation of DeRemer's method for Look-Ahead Set. This method makes us enable to generate LALR(1)-parsing-table dircetly from LR(0)-parsing-table by computing Look-Ahead Set based on formal definitions of them. For example, DeRemer's method has used in Bison, but there is few other implementation, particularly on Lisp. Therefore we decided to give a legible implementation for who would like to understand it. Other concept is to simplify PaGe's core program for efficiency and readability as possible. As a result, PaGe is composed of parser generator engine PaGEn and its wrapper. PaGEn is a pared parser-generator engine. PaGEn's input is a grammar whose "symbols" are restricted to non-negative integer. By this restriction, we were able to establish both program efficiency and algorithm readablity, for instance we can naturally use array as function. Consequently, the role of wrapper are mainly two of translation and interpreting. A wrapper translates symbolic input such as grammar or sequence of token into numeric input for PaGEn. PaGEn get this as input and return parsing-table or result of parse, for instance. Then the wrapper interprets this result for an user or other system. Now, we have defined only the wrapper for using PaGEn in the same way for traditional parser generator. If you wish to use PaGEn for other purpose, you need only to define the wrapper. Furthermore, PaGEn can deal with ambiguous grammar i.e. it supports disambiguation. PaGEn's disambiguation method is so simple. First we give two priority to each rule for reduce-time and shift-time. If some conflict has occurred, then, we try to solve each conflicts by comparing priorities. For Reduce/Reduce-conflicts, we solve it by Reduce using the rule which has the greatest reduce-time-priority in conflicted rules. For Shift/Reduce-conflicts, 2 pattern exists. If the propagation-priority, computed from several shift-time-priorities, is greater than the reduce-time-priority of the rule, we solve by shift. If the reduce-time-priority is greater than the propagation-priority we solve by reduce. This method is more general than the method which specifies the associativity of an operator directly, in translatability sense. And, dangling-else probrem can be solved uniformly in this method.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
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学术文献互助群
群 号:604180095
Book学术官方微信