Skip to content

Download and Setup

Vinícius Garcia edited this page May 14, 2018 · 20 revisions

For Linux Users

  1. Clone or download it from the official github repo into your project's folder:
git clone https://github.com/cparse/cparse.git cparse
  1. Compile it using make:
$ cd cparse
$ make release

This will create the core-shunting-yard.o and builtin-features.o binaries.

  1. Write your code including the shunting-yard header file:
// your_code.cpp
#include <iostream>
#include "./shunting-yard.h"

int main() {
  std::cout << calculator::calculate("'Hello ' + 'World'") << std::endl;
}
  1. Compile your project including these 2 binaries and its headers:
$ g++ -I./cparse your_code.cpp cparse/{core-shunting-yard.o,builtin-features.o}

If you want to modify existing built-in functions and operations please see the topic:

For Visual Studio/Windows Users

Note: VS 2017 or later is required for C++11 support.

  1. Clone or download it from the official github repo into your project's folder:
git clone https://github.com/cparse/cparse.git cparse
  1. Include the cparse directory to your project's path

  2. Include the core files into your project:

  • cparse/shunting-yard.cpp
  • cparse/packToken.cpp
  • cparse/functions.cpp
  • cparse/containers.cpp
  1. Write your code including the shunting-yard header file and the optional builtin-features.inc file:
// your_code.cpp
#include <iostream>
#include "./cparse/shunting-yard.h"
#include "./cparse/builtin-features.inc"

int main() {
  // Initialize it only once:
  cparse_startup();

  std::cout << calculator::calculate("'Hello ' + 'World'") << std::endl;
}
  1. Compile and run your project. The output "Hello World" should appear on the console.

Overwriting the built-in functions and operations:

Please note that this is an advanced option: If you just want to add new functions and operations alongside the built-in ones this is not required for you. This topic is required only if you want to erase/replace/modify existing functionalities to make sure your programming language has only the functions you want in it.

To make it possible to modify the existing built-in features, their code is kept separate. So to modify it you just need to make a copy of it and use it instead or explaining in more details:

  • You should not include the cparse/builtin-features.inc file or the cparse/builtin-features.o binary.
  • You should copy the directory cparse/builtin-features/ and the file cparse/builtin-features.inc to your project
  • Then edit your copy of the builtin-features.inc to include the files from your copy of the builtin-features/ directory.

And that's it.

Now you can safely edit any of the files in your copy of the directory builtin-features/ and instead of including the cparse/builtin-features.o binary file or including the cparse/builtin-features.inc file you should just make use of your own copies of them.

Note: In the case of the builtin-features.o file you should also make a copy of the cparse/builtin-features.cpp file and change it to use your copy of builtin-features.inc, then compile it into the .o version using the gcc -c option.

Clone this wiki locally