NAME

Marpa::R2::Semantics::Phases - Details of parse evaluation

Overview of the semantic phases

Most users will not need to read this document. Most applications will find that the order in which Marpa executes its semantics "just works". This document describes that order in detail. These details can matter in some applications, for example, those which exploit side effects. And some readers may also find this background material to be helpful.

Parse trees, parse results and parse series

As a reminder, when the semantics are applied to a parse tree, they produce a value called a parse result. Because Marpa allows ambiguous parsing, each parse can produce a parse series -- a series of zero or more parse trees, each with its own parse result. The first call to the the recognizer's value method after the recognizer is created is the start of the first parse series. The first parse series continues until there is a call to the the reset_evaluation method or until the recognizer is destroyed. Usually, an application is only interested in a single parse series.

When the reset_evaluation method is called for a recognizer, it begins a new parse series. The new parse series continues until there is another call to the the reset_evaluation method, or until the recognizer is destroyed.

Summary of the phases

While processing a parse series, we have:

  • A Series Setup Phase, which occurs during the first call of the recognizer's value method for that series. It is followed by

  • the processing of zero or more parse trees.

While processing a parse tree, we have:

  • A Tree Setup Phase, which occurs during the call of the recognizer's value method for that parse tree. It is followed by

  • a Tree Traveral Phase.

Node Evaluation Time is the Tree Traversal Phase, as seen from the point of view of each rule node. It is not a separate phase.

Series Setup Phase

During the Series Setup Phase all value action names are resolved to value actions -- constants or rule evaluation closures. The rule evaluation closures are never called in the Series Setup Phase. They will be called later, in the Tree Traversal Phase. Also, during the Series Setup Phase, the logic which ranks parse trees is executed.

Tree Setup Phase

In the Tree Setup Phase, the per-parse-tree variable is created. If a constructor was found for the action_object, it is run at this point, and the per-parse-tree variable is its return value. Exactly one Tree Setup Phase occurs for each parse tree.

Tree Traversal Phase

During the Tree Traversal Phase, the rule evaluation closures are called. Node Evaluation Time is the Tree Traversal Phase, as seen from the point of view of the individual nodes of the parse tree.

Copyright and License

  Copyright 2013 Jeffrey Kegler
  This file is part of Marpa::R2.  Marpa::R2 is free software: you can
  redistribute it and/or modify it under the terms of the GNU Lesser
  General Public License as published by the Free Software Foundation,
  either version 3 of the License, or (at your option) any later version.

  Marpa::R2 is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser
  General Public License along with Marpa::R2.  If not, see
  http://www.gnu.org/licenses/.