research

Lazy functional parser combinators in Java

Abstract

A parser is a program that checks if a text is a sentence of the language as described by a grammar. Traditionally, the program text of a parser is generated from a grammar description, after which it is compiled and subsequently run. The language accepted by such a parser is, by the nature of this process, hardcoded in the program. Another approach, primarily taken in the context of functional languages, allows parsers to be constructed at runtime, thus dynamically creating parsers by combining elements from libraries of higher level parsing concepts; this explanins the the name "parser combinators". Efficient implementation of this concept relies heavily on the laziness that is available in modern functional languages [13, 14]. This paper shows how to use parser combinators in a functional language as well as Java, and shows how parser combinators can be implemented in Java. Implementing parser combinators is accomplished by combining two libraries. The first one, written in Haskell, defines error-correcting and analysing parser combinators [2]. The second one consists of a small Java library implementing lazy functional behavior. The combinator library is straightforwardly coded in Java, using lazy behavior where necessary. In this paper all three aspects, the two libraries and its combination, are explained

    Similar works