Coder Social home page Coder Social logo

Comments (12)

VinGarcia avatar VinGarcia commented on July 20, 2024

Hello @grazba, the compiling process is as you described but there are some details that might help you:

  1. You don't need to compile the files test-shunting-yard.cpp and catch.cpp they are used for testing when adding new features to the library itself.
  2. The core-shunting-yard.o binary is formed by compiling the following files into a single file:
  • shunting-yard.cpp
  • packToken.cpp
  • functions.cpp
  • containers.cpp
  1. The built-in features is composed only by the builtin-features.cpp file. This file is actually very simple, it just includes several files from the directory builtin-features, it exists only to simplify the building process.

I noticed that the Makefile includes the core files when building the release version of builtin-features.o, this seems to be a mistake on my part since it is not required I will remove it now and commit the change.

So although I am not experienced with Visual Studio, I bet you could just include all the files I mentioned when creating the libraries. The reason for creating 2 .o files is so it is easier to remove the builtin-features if you don't like them and prefer to implement everything. If you are not planing on removing any of the existing built-in features you could compile all these .cpp files into a single library.

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

Also there is a difference between a .dll which is a Shared Library and an Object file. I actually never needed to use a Shared Library myself, the .o the Makefile create are just a precompiled version of the .cpp files meant to be included in your compilation process, but they could be replaced by the original .cpp files with no loss.

The only requirement they might need to work is for the compiler to be compatible with C++11 standard. In GCC this is made by adding a flag to the compiler: -std=c++11

I hope this is helpful, I will be available if you have any other doubts =]

from cparse.

 avatar commented on July 20, 2024

Thank you for your answers, it helped a lot !

I had an issue with ref-qualifiers (not supported by the compiler we're using).
i compiled it in a static library successfully thank you very much.

from cparse.

 avatar commented on July 20, 2024

Hi again , so i have to reopen this one ^^ !

So i did get it work, but the built in features are not there, i added the builtin-features.cpp file to the project and even added the headers to it as well just for good measure.

But for a reason the parser can not recognize the operators , if i declare a variable and send it to the parser to evaluate and print it it works fine.

I tried to create another project that uses the first library (the core) and adds the built in features and the results are the same no operators are recognized.

the only things i changed in the source code is adding a header file include for the integer types used (it's necessary on windows) and i deleted the && qualifier (not supported by my compiler).

It should not change how things work (just some memory waste no big deal) or am i wrong ?

thank you again !

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

Yes it should not have changed the behavior.

The built-in features are added during static initialization time: On each of the files in builtin-features/ you will find a singleton class being declared, it has no attributes and it is only used to register the operators, reserved words and etc on the global structures that hold them. An example of such class:

class Startup {
  Startup() {
    // access global variables only once at initialization time.
  }

// This name after the class declares an instance of this class (named _Startup)
// at static initialization time making the constructor run only once:
} _Startup;

If they are not running it might mean these constructors are not being executed which might have 2 reasons:

  1. There is some problem when including these files into your code.
  2. Your code is being executed at initialization time, i.e. before main() is executed. If this was the case your compiler could schedule to execute a cparse expression before the operations are registered, but this is an unlikely scenario.

In any case you could confirm if it is being executed by adding a std::cout << "here i am" << std::endl; inside the Startup constructor in the file "builtin-features/operations.h".

If the problem lays in the static initialization order you could replace these Startup classes with a global function that you may call once inside your code. But again this is only if you are initializing static class instances that execute cparse expressions at contruction time, which is an unlikely scenario.

If you find out anything new about this problem tell me, I want it solved as well =]

from cparse.

 avatar commented on July 20, 2024

well i printed something on each of the constructors to see if the code is even executed and apparently it is not.
I'm trying to understand where/when is the the built-in code executed and i find it odd that the built-in features files do not have any include statements for the core types. You said it is at static initialization time, but most of the structs do not define an instance except one

struct Startup {
Startup() {

	std::cout << "Startup functions !!! \n";
...
}
} base_functions_startup;

i'm thinking about including the adding of features into my code that should help me go forward, but it still bugs me that i can't make it a whole static library that i can use directly in another project.

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

Check the file builtin-features.cpp this is the file that include the core headers and then include the files in the builtin-features/ directory.

It is a little confusing but before this change all the builtin-features were kept in a single file whicih was much more complex to read.

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

Also if you look carefully all of them declare instances, except the name the instance use is the same as the class name (this is a way of implementing the singleton pattern, since once this instance exist the class name is not acessible by other parts of the code, only the instance).

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

I have made some changes on the builtin-features files to improve its readability:

  1. builtin-features/*.h were renamed to builtin-features/*.inc: They are not header files they are cpp files meant for inclusion. According to google style guide for C++ their extension should be .inc.
  2. The Startup class instances had the same name of their classes, but this was confusing, now the name used is "_Startup", so it is more readable.

I am also bugged about why these are not being executed. I am thinking about how to improve this so it won't give you too much trouble to initialize them.

I have an idea of how to do it, tonight I will try to implement it, it should greatly simplify setting up the library without static initialization.

Hopefully this will solve it for you.

from cparse.

 avatar commented on July 20, 2024

So as i expected if i add the features in my code it works fine ! i'll look more into it to find a way to get everything as a library (or two keeping the original design) and if i get it working i'll share the solution files for visual studio 2013-2015-2017.

looking forward to your changes too , have a good one talk soon.

from cparse.

VinGarcia avatar VinGarcia commented on July 20, 2024

Hello @grazba, I was unable to work yesterday night but I just did it.

There is now a new file called cparse/builtin-features.inc.

If you include this file inside your main.cpp file you will be able to call the function cparse_startup() that will initialize all built-in features. An example of this would be:

#include "cparse/builtin-features.inc"

int main() {
  cparse_startup();
  
  // ... Your code goes here ...
}

There is one caveat: If you do include this file you should not include the object file builtin-features.o (it could complain about the redefinition of functions).

Also, you must not include this .inc file more than once or it will also complain about the redefinition of functions.

I liked the way it turned out. If this solves your problem you may mark this issue as solved. I will later update the Wiki so this option is explained to everyone.

from cparse.

 avatar commented on July 20, 2024

Thanks for the update, this solution is similar to what i'm doing, i have to add features anyways so keeping the built-in features in my project and only using the core as a library is a great solution.

I will close the issue now thank you again !

from cparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.