Visitor-based Attribute Grammars with Side Effect

A. Middelkoop, A. Dijkstra, S.D. Swierstra

    Research output: Contribution to journalArticleAcademicpeer-review

    Abstract

    The visitor design pattern is often applied to program traversal algorithms over Abstract Syntax Trees (ASTs). It defines a visitor, an object with a visit method that is executed for each node in the AST. These visitors have the advantage that the order of traversal is explicitly under control of the programmer, which is essential to deal with side-effectful computations. Unfortunately, the exchange of results between traversals is error-prone. Attribute Grammars (AGs) are an alternative way to write multi-traversal algorithms. An attribute evaluator decorates the AST with attributes in one or more traversals. The attributes form a convenient mechanism to exchange results between traversals. Unfortunately, AGs discourage the use of side effect. In this paper, we present ruler-front, a language capturing the combination of the above approaches. A ruler-front grammar can be translated to traversal algorithms in multiple languages. In this paper, we translate to the imperative, dynamically-typed language JavaScript.
    Original languageEnglish
    Pages (from-to)47-69
    Number of pages23
    JournalElectronic Notes in Theoretical Computer Science
    Volume264
    Issue number5
    DOIs
    Publication statusPublished - 2011

    Bibliographical note

    Workshop on Generative Technologies

    Fingerprint

    Dive into the research topics of 'Visitor-based Attribute Grammars with Side Effect'. Together they form a unique fingerprint.

    Cite this