Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    Spirit 1.8.6

    Download button

    No screenshots available
    Downloads: 350  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Fair (2.7/5)
    14 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Joel de Guzman | More programs
    Boost Software Licen... / FREE
    March 31st, 2008, 14:57 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Spirit description

    Spirit is an object-oriented recursive-descent parser generator framework implemented using template meta-programming techniques

    Spirit is an recursive-descent object-oriented parser generator framework implemented using template meta-programming techniques. Expression templates allow us to approximate the syntax of Extended Backus-Normal Form (EBNF) completely in C++.

    The Spirit framework enables a target grammar to be written exclusively in C++. Inline EBNF grammar specifications can mix freely with other C++ code and, thanks to the generative power of C++ templates, are immediately executable. In retrospect, conventional compiler-compilers or parser-generators have to perform an additional translation step from the source EBNF code to C or C++ code.

    A simple EBNF grammar snippet:

    group ::= '(' expression ')'
    factor ::= integer | group
    term ::= factor (('*' factor) | ('/' factor))*
    expression ::= term (('+' term) | ('-' term))*

    is approximated using Spirit's facilities as seen in this code snippet:

    group = '(' >> expression >> ')';
    factor = integer | group;
    term = factor >> *(('*' >> factor) | ('/' >> factor));
    expression = term >> *(('+' >> term) | ('-' >> term));

    Through the magic of expression templates, this is perfectly valid and executable C++ code. The production rule expression is in fact an object that has a member function parse that does the work given a source code written in the grammar that we have just declared. Yes, it's a calculator. We shall simplify for now by skipping the type declarations and the definition of the rule integer invoked by factor. The production rule expression in our grammar specification, traditionally called the start symbol, can recognize inputs such as:

    12345
    -12345
    +12345
    1 + 2
    1 * 2
    1/2 + 3/4
    1 + 2 + 3 + 4
    1 * 2 * 3 * 4
    (1 + 2) * (3 + 4)
    (-1 + 2) * (3 + -4)
    1 + ((6 * 200) - 20) / 6
    (1 + (2 + (3 + (4 + 5))))

    Certainly we have done some modifications to the original EBNF syntax. This is done to conform to C++ syntax rules. Most notably we see the abundance of shift >> operators. Since there are no 'empty' operators in C++, it is simply not possible to write something like:

    a b

    as seen in math syntax, for example, to mean multiplication or, in our case, as seen in EBNF syntax to mean sequencing (b should follow a). The framework uses the shift >> operator instead for this purpose. We take the >> operator, with arrows pointing to the right, to mean "is followed by". Thus we write:

    a >> b

    The alternative operator | and the parentheses () remain as is. The assignment operator = is used in place of EBNF's ::=. Last but not least, the Kleene star * which used to be a postfix operator in EBNF becomes a prefix. Instead of:

    a* //... in EBNF syntax,

    we write:

    *a //... in Spirit.

    since there are no postfix stars, "*", in C/C++. Finally, we terminate each rule with the ubiquitous semi-colon, ";".

    What's New in This Release:

    · Fixed a integer overflow bug preventing to fail parsing on certain large integers. This bug was reported and fixed by Michael Andersen Nexø



    Product's homepage

      


    TAGS:

    object-oriented framework | parser generator | recursive-descent framework | C++ | framework | parser

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM