Results 1 - 10
of
15
Packrat Parsing: Simple, Powerful, Lazy, Linear Time
"... Packrat parsing is a novel technique for implementing parsers in a lazy functional programming language. A packrat parser provides the power and flexibility of top-down parsing with backtracking and unlimited lookahead, but nevertheless guarantees linear parse time. Any language defined by an LL(k) ..."
Abstract
-
Cited by 47 (4 self)
- Add to MetaCart
Packrat parsing is a novel technique for implementing parsers in a lazy functional programming language. A packrat parser provides the power and flexibility of top-down parsing with backtracking and unlimited lookahead, but nevertheless guarantees linear parse time. Any language defined by an LL(k) or LR(k) grammar can be recognized by a packrat parser, in addition to many languages that conventional linear-time algorithms do not support. This additional power simplifies the handling of common syntactic idioms such as the widespread but troublesome longest-match rule, enables the use of sophisticated disambiguation strategies such as syntactic and semantic predicates, provides better grammar composition properties, and allows lexical analysis to be integrated seamlessly into parsing. Yet despite its power, packrat parsing shares the same simplicity and elegance as recursive descent parsing; in fact converting a backtracking recursive descent parser into a linear-time packrat parser often involves only a fairly straightforward structural change. This paper describes packrat parsing informally with emphasis on its use in practical applications, and explores its advantages and disadvantages with respect to the more conventional alternatives.
Functional Parsers
, 1995
"... . In an informal way the `list of successes' method for writing parsers using a lazy functional language (Gofer) is described. The library of higher-order functions (known as `parser combinators') that is developed is used for writing parsers for nested parentheses and operator expressions with ..."
Abstract
-
Cited by 46 (1 self)
- Add to MetaCart
. In an informal way the `list of successes' method for writing parsers using a lazy functional language (Gofer) is described. The library of higher-order functions (known as `parser combinators') that is developed is used for writing parsers for nested parentheses and operator expressions with an arbitrary number of priorities. The method is applied on itself to write a parser for grammars, that yields a parser for the language of the grammar. In the text exercises are provided, the solutions of which are given at the end of the article. 1 Introduction This article is an informal introduction to writing parsers in a lazy functional language using `parser combinators'. Most of the techniques have been described by Burge [2], Wadler [5] and Hutton [3]. Recently, the use of so-called monads has become quite popular in connection with parser combinators [6, 7]. We will not use them in this article, however, to show that no magic is involved in using parser combinators. You are ne...
Packrat Parsing: a Practical Linear-Time Algorithm with Backtracking
, 2002
"... Packrat parsing is a novel and practical method for implementing linear-time parsers for grammars defined in Top-Down Parsing Language (TDPL). While TDPL was originally created as a formal model for top-down parsers with backtracking capability, this thesis extends TDPL into a powerful general-purpo ..."
Abstract
-
Cited by 14 (2 self)
- Add to MetaCart
Packrat parsing is a novel and practical method for implementing linear-time parsers for grammars defined in Top-Down Parsing Language (TDPL). While TDPL was originally created as a formal model for top-down parsers with backtracking capability, this thesis extends TDPL into a powerful general-purpose notation for describing language syntax, providing a compelling alternative to traditional context-free grammars (CFGs). Common syntactic idioms that cannot be represented concisely in a CFG are easily expressed in TDPL, such as longest-match disambiguation and "syntactic predicates," making it possible to describe the complete lexical and grammatical syntax of a practical programming language in a single TDPL grammar. Packrat parsing is an adaptation of a 30-year-old tabular parsing algorithm that was never put into practice until now. A packrat parser can recognize any string defined by a TDPL grammar in linear time, providing the power and flexibility of a backtracking recursive descent parser without the attendant risk of exponential parse time. A packrat parser can recognize any LL($k$) or LR($k$) language, as well as many languages requiring unlimited lookahead that cannot be parsed by shift/reduce parsers. Packrat parsing also provides better composition properties than LL/LR parsing, making it more suitable for dynamic or extensible languages. The primary disadvantage of packrat parsing is its storage cost, which is a constant multiple of the total input size rather than being proportional to the nesting depth of the syntactic constructs appearing in the input. Monadic combinators and lazy evaluation enable elegant and direct implementations of packrat parsers in recent functional programming languages such as Haskell. Three different packrat parsers for the Java language are presented here, demonstrating the construction of packrat parsers in Haskell using primitive pattern matching, using monadic combinators, and by automatic generation from a declarative parser specification. The prototype packrat parser generator developed for the third case itself uses a packrat parser to read its parser specifications, and supports full TDPL notation extended with ``semantic predicates,'' allowing parsing decisions to depend on the semantic values of other syntactic entities. Experimental results show that all of these packrat parsers run reliably in linear time, efficiently support ``scannerless'' parsing with integrated lexical analysis, and provide the user-friendly error-handling facilities necessary in practical applications.
Exception Handling in the Spreadsheet Paradigm
- IEEE Transactions on Software Engineering
, 2000
"... Exception handling is widely regarded as a necessity in programming languages today, and almost every programming language currently used for professional software development supports some form of it. However, spreadsheet systems, which may be the most widely used type of "programming language" tod ..."
Abstract
-
Cited by 3 (3 self)
- Add to MetaCart
Exception handling is widely regarded as a necessity in programming languages today, and almost every programming language currently used for professional software development supports some form of it. However, spreadsheet systems, which may be the most widely used type of "programming language" today in terms of number of users using it to create "programs" (spreadsheets), have traditionally had only extremely limited support for exception handling. Spreadsheet system users range from end users to professional programmers, and this wide range suggests that an approach to exception handling for spreadsheet systems needs to be compatible with the equational reasoning model of spreadsheet formulas, yet feature expressive power comparable to that found in other programming languages.
Parser Combinators in Scala
, 2008
"... Parser combinators are well-known in functional programming languages such as Haskell. In this paper, we describe how they are implemented as a library in Scala, a functional object-oriented language. Thanks to Scala’s flexible syntax, we are able to closely approximate the EBNF notation supported b ..."
Abstract
-
Cited by 3 (1 self)
- Add to MetaCart
Parser combinators are well-known in functional programming languages such as Haskell. In this paper, we describe how they are implemented as a library in Scala, a functional object-oriented language. Thanks to Scala’s flexible syntax, we are able to closely approximate the EBNF notation supported by dedicated parser generators. For the uninitiated, we first explain the concept of parser combinators by developing a minimal library from scratch. We then turn to the existing Scala library, and discuss its features using various examples.
Exception Handlers in Functional Programming Languages
- IEEE Transactions on Software Engineering
, 1993
"... Constructs for expressing exception handling can greatly help to avoid clutter in code by allowing the programmer to separate the code to handle unusual situations from the code for the normal case. Handling exceptions in functional languages has received less attention mainly due to the inherent co ..."
Abstract
-
Cited by 2 (0 self)
- Add to MetaCart
Constructs for expressing exception handling can greatly help to avoid clutter in code by allowing the programmer to separate the code to handle unusual situations from the code for the normal case. Handling exceptions in functional languages has received less attention mainly due to the inherent conflict between the control flow oriented approach of exception handlers and the functional style of evaluation. This has (i) resulted in loss of referential transparency, (ii) made non-strict constructs behave as strict functions, and most importantly, (iii) forced an order of evaluation on the subexpressions in a function. In this paper, we propose a new approach to embed exception handlers in functional languages. The proposed approach discards the conventional view of treating exceptions as a means of effecting a control transfer; instead, exceptions are used to change the state of an object. The two types of exceptions, Terminate and Resume, are treated differently in this paper. A Termi...
Soutei, a Logic-Based Trust-Management System System Description
"... Abstract. We describe the design and implementation of a trust-management system Soutei, a dialect of Binder, for access control in distributed systems. Soutei policies and credentials are written in a declarative logic-based security language and thus constitute distributed logic programs. Soutei p ..."
Abstract
-
Cited by 2 (0 self)
- Add to MetaCart
Abstract. We describe the design and implementation of a trust-management system Soutei, a dialect of Binder, for access control in distributed systems. Soutei policies and credentials are written in a declarative logic-based security language and thus constitute distributed logic programs. Soutei policies are modular, concise, and readable. They support policy verification, and, despite the simplicity of the language, express role- and attribute-based access control lists, and conditional delegation. We describe the real-world deployment of Soutei into a publish-subscribe web service with distributed and compartmentalized administration, emphasizing the often overlooked aspect of authorizing the creation of resources and the corresponding policies. Soutei brings Binder from a research prototype into the real world. Supporting large, truly distributed policies required non-trivial changes to Binder, in particular mode-restriction and goal-directed top-down evaluation. To improve the robustness of our evaluator, we describe a fair and terminating backtracking algorithm.
The Lazy Functional Side of Logic Programming
- In Proc. of the Int. Workshop on Logic Program Synthesis and Transformation
, 2000
"... this paper we show, among other things, that logical structures such as dierence lists have a natural counterpart in lazy functional programs; i.e. that most programs using dierence-lists are functional in nature. This shows immediately that many common non-well-moded programs are functional in natu ..."
Abstract
-
Cited by 1 (0 self)
- Add to MetaCart
this paper we show, among other things, that logical structures such as dierence lists have a natural counterpart in lazy functional programs; i.e. that most programs using dierence-lists are functional in nature. This shows immediately that many common non-well-moded programs are functional in nature and that well-modedness is thus not a necessary attribute of those logic programs behaving functionally. We do this by employing a straightforward { literal { translation of moded logic programs into Haskell, a lazy functional language
Mixing Induction and Coinduction
, 2009
"... Purely inductive definitions give rise to tree-shaped values where all branches have finite depth, and purely coinductive definitions give rise to values where all branches are potentially infinite. If this is too restrictive, then an alternative is to use mixed induction and coinduction. This techn ..."
Abstract
-
Cited by 1 (0 self)
- Add to MetaCart
Purely inductive definitions give rise to tree-shaped values where all branches have finite depth, and purely coinductive definitions give rise to values where all branches are potentially infinite. If this is too restrictive, then an alternative is to use mixed induction and coinduction. This technique appears to be fairly unknown. The aim of this paper is to make the technique more widely known, and to present several new applications of it, including a parser combinator library which guarantees termination of parsing, and a method for combining coinductively defined inference systems with rules like transitivity. The developments presented in the paper have been formalised and checked in Agda, a dependently typed programming language and proof assistant.
A System F with call-by-name exceptions
"... Abstract. We present an extension of System F with call-by-name exceptions. The type system is enriched with two syntactic constructs: a union type A ⋆ ∪ {ε} for programs of type A whose execution may raise the exception ε at top level, and a corruption type A {ε} for programs that may raise the exc ..."
Abstract
-
Cited by 1 (0 self)
- Add to MetaCart
Abstract. We present an extension of System F with call-by-name exceptions. The type system is enriched with two syntactic constructs: a union type A ⋆ ∪ {ε} for programs of type A whose execution may raise the exception ε at top level, and a corruption type A {ε} for programs that may raise the exception ε in any evaluation context (not necessarily at top level). We present the syntax and reduction rules of the system, as well as its typing and subtyping rules. We then study its properties, such as confluence. Finally, we construct a realizability model using orthogonality techniques, from which we deduce that well-typed programs are weakly normalizing and that the ones who have the type of natural numbers really compute a natural number, without raising exceptions. 1

