Haskell, Do You Read Me? Constructing and Composing Efficient Top-down Parsers at Runtime

被引:0
作者
Viera, Marcos [1 ]
Swierstra, S. Doaitse [2 ]
Lempsink, Eelco [2 ]
机构
[1] Univ Republ Montevideo, Inst Computac, Montevideo, Uruguay
[2] Univ Utrecht, Dept Comp Sci, NL-3508 TB Utrecht, Netherlands
关键词
Design; Languages; Performance; Standardization; GADT; Haskell; Left-Corner Transform; Meta Programming; Parser Combinators; Type Systems; Typed Abstract Syntax; Typed Transformations;
D O I
10.1145/1543134.1411296
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
The Haskell definition and implementation of read is far from perfect. In the first place read is not able to handle the associativities defined for infix operators. Furthermore, it puts constraints on the way show is defined, and especially forces it to generate far more parentheses than expected. Lastly, it may give rise to exponential parsing times. All this is due to the compositionality requirement for re ad functions, which imposes a top-down parsing strategy. We propose a different approach, based on typed abstract syntax, in which grammars describing the data types are composed dynamically. Using the transformation libraries described in a companion paper these syntax descriptions are combined and transformed into parsers at runtime, from which the required re ad function are constructed. In this way we obtain linear parsing times, achieve consistency with the defined associativities, and may use a version of show which generates far fewer parentheses, thus improving readability of printed values. The described transformation algorithms can be incorporated in a Haskell compiler, thus moving most of the work involved to compile time.
引用
收藏
页码:63 / 74
页数:12
相关论文
共 15 条
[1]  
[Anonymous], 2004, P 2004 ACM SIGPLAN W
[2]  
BAARS A, 2008, UUCS21
[3]   Parsing permutation phrases [J].
Baars, AI ;
Löh, A ;
Swierstra, SD .
JOURNAL OF FUNCTIONAL PROGRAMMING, 2004, 14 :635-646
[4]   Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking [J].
Bouwers, Eric ;
Bravenboer, Martin ;
Visser, Eelco .
ELECTRONIC NOTES IN THEORETICAL COMPUTER SCIENCE, 2008, 203 (02) :85-101
[5]  
BRAVENBOER M, 2008, THESIS UTRECHT U UTR
[6]  
Jones SP, 2006, ACM SIGPLAN NOTICES, V41, P50
[7]  
Jones Simon Peyton, 2003, Haskell 98 language and libraries: the revised report
[8]   Scrap your boilerplate:: A practical design pattern for generic programming [J].
Lämmel, R ;
Jones, SP .
ACM SIGPLAN NOTICES, 2003, 38 (03) :26-37
[9]  
Lammel Ralf., 2004, ICFP 04, P244
[10]   Applicative programming with effects [J].
Mcbride, Conor ;
Paterson, Ross .
JOURNAL OF FUNCTIONAL PROGRAMMING, 2008, 18 (18) :1-13