Introduction SPIRIT
TOP NEXT
Usage summary
yac [Input mode]
Input mode
-i, –interactiveData input interactively
-f, –file FILEData input from FILE
-p, –pipedData piped through stdin

YAC is Yet Another Calculator. It is a command line tool that can accept data from a file, piped through stdin or input interactively from the command line. New variables and functions can be defined using a syntax similar to that of Gnuplot.


    print 2+3*sin(sqrt(2)/2)    # outputs 3.94891
    pi_4 = 3.1415926536 / 4
    print cos(pi_4)             # outputs 0.707107
    foo(a,b) = a+b
    print foo(1,2)              # outputs 3 

It supplies only two pre-defined variables, pi and e, but has a comprehensive set of built-in functions: abs, acos, acosh, asin, asinh, atan, atan2, atanh, besj0, besj1, besy0, besy1, ceil, cos, cosh, exp, floor, log, log10, sgn, sin, sinh, sqrt, tan, tanh and, if present in your system C library, erf and erfc. These functions are the same as the corresponding functions in the Unix math library except that all functions take double arguments. Radians are used by those functions that accept or return angles.

Compilation

The YAC source code requires that either the Boost 1.31.0 (or later) or the Spirit 1.8.0 (or later) distributions be present in the compile path. Here, compiling with g++ under Linux:


    g++ -I$HOME/boost/cvs -o yac yac.cpp 

Lucio Flores has kindly contributed solution and project files for MS VC++.

Documentation overview

YAC's parser has been written using the Spirit parser framework. Spirit enables a parser to be written with a syntax that is a recognizable approximation to Extended Backus Normal Form (EBNF). It is a joy to use, not least because the user documentation is truly excellent. However, some of Spirit's most powerful facilities are quite difficult to get to grips with. YAC was written to investigate these facilities more thoroughly. This documentation should be of interest to those thinking of using closures, lambda functions, lazy functions and the functor parser in their own code.

The documentation that follows is organized into three sections. The Grammar overview provides a formal definition of the grammar understood by YAC. The Virtual machine describes just how YAC evaluates the parsed data. The Parser provides the missing link, describing in some detail just how the input data is used to generate the computational tree. This last section is by far the largest of the three.

TOP NEXT

Valid XHTML 1.1! Valid CSS!