Tcl Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

grammar::peg::interp - Interpreter for parsing expression grammars

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require grammar::mengine ?0.1?
package require grammar::peg::interp ?0.1.2?

::grammar::peg::interp::setup peg
::grammar::peg::interp::parse nextcmd errorvar astvar

DESCRIPTION

This package provides commands for the controlled matching of a character stream via a parsing expression grammar and the creation of an abstract syntax tree for the stream and partials.

It is built on top of the virtual machine provided by the package grammar::me::tcl and directly interprets the parsing expression grammar given to it. In other words, the grammar is not pre-compiled but used as is.

The grammar to be interpreted is taken from a container object following the interface specified by the package grammar::peg::container. Only the relevant parts are copied into the state of this package.

It should be noted that the package provides exactly one instance of the interpreter, and interpreting a second grammar requires the user to either abort or complete a running interpretation, or to put them into different Tcl interpreters.

Also of note is that the implementation assumes a pull-type handling of the input. In other words, the interpreter pulls characters from the input stream as it needs them. For usage in a push environment, i.e. where the environment pushes new characters as they come we have to put the engine into its own thread.

THE INTERPRETER API

The package exports the following API

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category grammar_peg of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.

KEYWORDS

LL(k), TDPL, context-free languages, expression, grammar, matching, parsing, parsing expression, parsing expression grammar, push down automaton, recursive descent, state, top-down parsing languages, transducer, virtual machine

CATEGORY

Grammars and finite automata

COPYRIGHT

Copyright © 2005-2011 Andreas Kupries