Nominate our 2022 Qt Champions!

Formula 1.1-A mathematical expression evaluator has been released!

  • Formula
    Formula is a mathematical expression calculator, supporting user defined variables and functions. Formula can also be used as an interpreter of scripts with a specified indentation syntax. The core of program is lexer/parser generated by flex/bison, and the GUI consists of Qt widgets.

    A mathematical expression evaluator is an "interpreter". An interpreter is a program that is able to dynamically execute commands written is a defined language. Therefore, with a mathematical expression evaluator, you should be able to dynamically calculate formulas like: 2 + 5 * 3. This is very useful if, for instance, you have to parameterize parts of your applications and need to execute some calculations. The language used by this interpreter is the indentation syntax (similar to Python, not the same).

    Lexer and Parser
    In this program, the lexer and the parser will be generated by an external dedicated tool -- flex/bison.

    Creating the AST
    When evaluating an expression, the parser generated by bison is able to go through all the rules like this:


    Visitor Pattern, Semantic Analysis and Evaluation
    On top of the model, the visitor pattern is implemented.

    Indentation Syntax
    Python is famous for its indentation syntax. The Formula indentation syntax is similar to Python, but add more restrictions.

    • End-of-line is end of statement
    • End of indentation is end of block
    • Indentation is increased step-by-step
    • Semicolon is an illegal character in Formula
    • Indent should done by TABs, and using spaces is illegal

    Building Formula from Source

    git clone

    To build the program, you must have following tools installed:

    • Qt-SDks (version 4.8 or version 5.5)
    • flex-2.5 & bison-3.0
    • C++ compilers support c++11, for example, GCC on Linux, Clang on Mac OS X, MSVC on Windows
    • Cmake-3.0 -- a Crossplatform Build System (optional)

    Building Instructions

    on Unix-like OS (using CMake):

    mkdir build
    cd build
    cmake ..

    on Windows (using CMake):

    mkdir build
    cd build
    cmake .. -G "NMake Makefiles"

    on both platforms(using QMake)

    mkdir build
    cd build
    qmake ..
    make(or make)


    Copyright (C) 2015-2016, kylinsage

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see

Log in to reply