The Parser

In addition to translate the user input into a valid Query Tree, the Parser has also other things to do:

Syntax checking

Apart from trivial syntax checking, the Query Tree should be valid with respect to Object Types, i.e. OpNode of the Query Tree should have children with the same Class Index. Only Association Nodes may change the Class Index, and the change must be consistent with the Association Name.

Identify maximal PT branches

The QT can be simplified if the nodes are not separated by an Association. Two Predicates that are hanging on a Union node can be expressed by a single Predicate where the two are OR'd (only works for distinct unions). If they are hanging on an Intersection the new Predicate will be the AND of the two. In the case of an Except there has to be a NOT operator. So a QT not containing an Association at all may be reduced to one single Predicate Tree, i.e. one Scope Query at the end. As an example, consider the tree


This can be reduced to 

Eliminate NOT operations above Domains

NOT operations will make the use of Intersection objects impossible in certain cases. The easiest thing to do to overcome this, is to propagate the NOT down to each Domain and take the other half of the sky / flux space. Instead of an AND we 'll have OR and vice versa. Since Domains may not have any other operation above them (syntax requirement), this should be no problem.