Originally I wrote this parser framework for my study thesis (see http://idlebox.net/blogtags/study_thesis_large_graphs). In the thesis millions of graph edges are processed and organized in an r-tree search index structure. Each vertex and edge had a number of attributes like "color" or "importance". These attributes could then be used in filter expressions to determine which edges are returned by a graph server and displayed on a remote client. The attributes of the filtered edges could be used to calculate the returned data set using expressions similar to SQL column selection clauses.
Four instructive example applications are included in the package. See Extensive Example Programs Including Source Code for more.
The library source and example programs are extensively documented using doxygen. The compiled doxygen HTML documentation can be found at http://idlebox.net/2007/stx-exparser/stx-exparser-0.7-doxygen/ (if you are not reading it right now).
If bugs should become known they will be posted on the above web page together with patches or corrected versions.
The complete source code is released under the GNU Lesser General Public License v2.1 (LGPL) which can be found in the file COPYING.
Furthermore a number of example CSV data files can be browsed, sorted, analyzed and filtered using the csvtool example. See http://idlebox.net/2007/stx-exparser/csvfilter.htt for an instructive use of this library.
A wxWidgets demo program is located in the directory wxparserdemo. Compiled binary versions can be found at http://idlebox.net/2007/stx-exparser/demo.htt
gcc 3.3 -O3
can take very long and a huge amount of RAM. This is due to the complex template classes created by Boost.Spirit. Compilation with gcc 4.x
is much faster.6 + 3 * 12
(5 + 3) * 5.25
(int)(30 * 1.4)
(5 + 1 + 1 + 1) * (4.25 + 0.4 * 2.5 / (3.1 - 0.525 * 4))
a * 5 + 3 * b + EXP( LOGN(2) ) + COS( PI() / 2 )
6 * 9 == 42
a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes")
and a third more complex (less documented) example program:
Furthermore a user-friendly graphical demonstration application is included:
char
' integer, 16-bit 'short
', 32-bit 'integer
' and 64-bit 'long
' integer byte
', 16-bit 'word
', 32-bit 'dword
' and 64-bit 'qword
' unsigned integers float
and double
) string
The reason to include the smaller integer types is based on the original purpose of this library. In my study thesis the resulting values were transfered over a network socket from a graph server to its drawing client. For this purpose it was important to convert the resulting values into smaller data types and thus reduce network traffic. For online-filtering applications this is probably not as important.
A user given input string is parsed by Spirit into an abstract syntax tree (AST). The AST is then processed into a tree of stx::ParseNode objects. During the construction of the stx::ParseNode objects all constant subtrees are folded into constant objects. This way repeated evaluation of the ParseTree is accelerated. At the end the top stx::ParseNode is returned in a stx::ParseTree enclosure.
The stx::ParseTree's main method is evaluate(), which takes a stx::SymbolTable and recursively evaluates the contained stx::ParseNode tree using the variable and functions contained in the symbol table. The result is returned as an stx::AnyScalar object.