We will examine how parsing proceeds for a grammar that only describes the y-axis line and its tick marks and does so in a very simple way. When a grammar is entered into the system, a Lisp defgrammar macro expands the form into one that includes an additional defrule macro, applied to each rule structure. When the defrule forms expand, they define the CLOS classes for each non-terminal as well as the goal predicates for the search and the generator functions needed. These macros act as the parser generators. Once they have been applied, the parsing process then acts as a top-down tree-search.
A simple grammar with three rules:
;;; ****************** < X-Ticks > *************** ( Y-Ticks -> Ticks Y-Line (Y-Line) (Ticks (touch Y-Line '?) :constraints (> (size Ticks) 2))) ;;; ****************** < X-Line > *************** ( Y-Line -> Line (:constraints (vertp Line) (long Line))) ;;; ****************** < Ticks > *************** ( Ticks -> Set(Line) (:element-constraints (horizp Line) (short Line)))
The parse is assumed to be started at the top node, Y-Ticks. Parsing proceeds by a depth-first search to discover and build elements that satisfy the various geometric constraints. The order of the search is dictated by the order of the constituents in the body of the rule (not in the order of the constituents in the "->" production).
Our grammars, because of the way they are designed and operate, are called Context-based Constraint Grammars. It is essentially an Attributed Multiset Grammar, but its use of context is new. A rule inherits a context specified in its parent that restricts the set of items within which the rule is allowed to search for a solution. This successive narrowing of the search set helps to make the parsing process more efficient. Parsing generates a set of all distinct solutions that satisfy the constraints. In the example above, the set is a singleton. In addition, the same element can be reused or shared by various parts of a single solution, see the discussion of sharing.
When the parse is complete we can highlight the elements in the Diagram Viewer that make up the Y-Ticks structure, as shown on the right. Note that this simple grammar also identifies the top and bottom sides of a data point as tick marks. This is avoided in our more complex grammars by requiring that a tick mark not be a line that participates in a polygon. |
Next: Parsing runs with timing |
Back to Index page |