kiama

A Scala library for language processing.

View the Project on GitHub

Documentation Home

User Manual Examples
Research Reading
Installation
Releases

Converting text into structures that Kiama can process

Up: User Manual, Prev: Context, Next: Rewriting

It is necessary to have a tree representation of the data that is to be manipulated in order to use Kiama’s facilities. This representation is usually an abstract syntax tree (AST) that encodes the structure of a program written in some language, but the tree could represent any hierarchical data.

There are currently two convenient methods for building tree structured representations for use with Kiama: using the Scala parser combinator library and using the separate Rats! parser generator. For documentation on how to use Rats! with Scala, please see the sbt-rats project and the Rats! documentation. For simplicity, the remainder of this documentation focuses on combinator-based parsing.

Combinator-based parsing is common in languages such as Haskell and ML in packages such as Parsec. The basic idea of combinator parsing is to write expressions that look like the context-free grammar productions of the language that is to be parsed. The value of an expression is a parsing object that can be applied to a specific input source. The result of that application is either an indication of parsing success and possibly a value representing the parsed text, or an indication of failure and a failure message.

Detailed documentation for the parsing library may be found in the Kiama API documentation (search “Parsers” to start). Chapter 31 of Programming in Scala provides an excellent overview of a similar library that used to be part of the Scala standard library. This chapter from the first edition of the book is freely available.

More detailed information on using the parsing library with Kiama can be found in these pages:

Up: User Manual, Prev: Context, Next: Rewriting