About class's(OOP): i need some information. And Multidimensional Vectors

Pages: 12
hmm. if you allow yourself to use goto and create an anything union or similar class to represent loosely typed variables, you should be able to use those in c++ to mimic anything in basic, with pretty much a one to one translation. I had to deal with that in a matlab translator I wrote, one min its a string, then an integer, then a matrix of doubles, then a string again... which was more of a 'hey programmer, we need to talk in the back ally behind the building after lunch today' issue than anything else. You can do the loosely typed thing, but c++ really, REALLY hates it (for good reasons) so its sometimes a bit annoying to make it fit.
@Cambalinho

Ok, so you want to write a C++/VB hybrid porting tool. And it looks like it will involve parsing. Cool :+)

So there could be several scenarios:

1. Some sections of pure C++, followed by some sections of pure VB , alternating;
2. Some C++ with pieces of VB embedded in it ;
3. Some VB with pieces of C++ embedded in it ;

With that in mind could you provide some sample code which you need to port.

Presumably the pure c++ will remain as it is, and just be written straight to the output file.

Please note, I have no direct experience with the following, just living up to my username - putting out ideas :+) There are plenty of people here who do have that experience :+)

One thing that comes to mind is the use of a Finite State Machine (FSM):

https://en.wikipedia.org/wiki/Finite-state_machine

Here is a link to a description of 2 things in the Boost library:
https://stackoverflow.com/questions/4275602/boost-statechart-vs-meta-state-machine

Your FSM could determine a state by reading tokens (keywords, expressions, operators, variables names, data etc)

As a minimum you could use this to detect what is c++ and what is VB for option 1 above say. Then use it to turn the VB into C++. Obviously options 2 and 3 above are much more complex.

So this is only a methodology, I imagine you will still want a data structure. You may even need an Abstract Syntax Tree:
https://en.wikipedia.org/wiki/Abstract_syntax_tree

I can't help thinking that your idea of multidimensional vectors won't scale very well, and won't be very flexible.

This all might sound complex, but start out small (decide on a few syntax's to support) then go from there.

Good Luck!!


Edit: you may get more replies if you turn off the solved green tick :+)
Last edited on
TheIdeasMan: i have several code, i can share it... because uses 2 files...(*.h and *.cpp) sorry.
- i have an uncompleted header file with windows controls and graphics and more.
- i have my own Main() function for be more easy to use and getting the arguments and if the program was executed ;)

but see these nice print:
https://ibb.co/BZZPgs1
now you see what i can do for now
thank you for all
Hi,

Another idea:

http://llvm.org/docs/tutorial/
https://llvm.org/docs/tutorial/LangImpl01.html

I am not sure what method you have used so far, but this looks easy to follow, simple and modern.
i'm using a compiler way. yes i had get several information on how i create a compiler.. i use that way.. very cool
what i don't know is convert the language to exe.. something that i didn't learned.
but you have right, theres anothers languages that can make my work. but i'm creating, too, my own libraries(*.hpp).
thank you so much for all
Ok I hope everything goes well :+)
TheIdeasMan: yes goes very well ;)
lets go back for i understand 1 thing not programming.
my topic wasn't so easy to understand, can you explain what i miss more?
(maybe i learn more express me)
Hi,

Can you make use of Google Translate? I am having trouble understanding what you are saying.

Can you tell us what your spoken language is ? :+)

https://translate.google.com/


what i don't know is convert the language to exe.. something that i didn't learned.


I can answer that in terms of using the llvm compiler (I read through all 10 chapters of the documentation).

The code examples implement the lexer, parser and creates the Abstract Syntax Tree (AST)
llvm uses the AST to emit an IR (Intermediate Representation) .
It can compile this IR into an executable. I imagine the IR makes it easier to produce assembly code, which then translates directly into an executable.

i'm using a compiler way.


Which compiling system are you using?

but i'm creating, too, my own libraries(*.hpp).


Can you explain more about that?


Just thinking, if you want to share your code in a semi private way, maybe send a link to your code on github (or similar) via a PM to me or others here who might want to help.
i was trying to understand why my topic is so confused.
can you explain why my topic is so confused?
(i can understand 90% or more what you said... but i need understand why my topic is so confused)

i'm creating class's on C++, on header files, for create windows and controls and use CMD and Graphics and more.... these is very cool.
with controls is a little limited, because i'm using the Windows 7.. the Windows 8 and above, can make the child controls transparent and semitransparent, the Windows 7 only on parent windows lol
i was trying to understand why my topic is so confused.
can you explain why my topic is so confused?


Well your replies are short, and don't really make sense in English. That is why I keep asking you to use Google Translate. Note that I not judging you for poor English :+) I fully understand how it is a nightmare of a language, and how effective would I be at communicating if I was in your country trying to use your language? Is your language Portuguese?

And you seem to be doing several things, none of which you explain in much detail. To start with your question was about nested c++ classes and multi-dimensional vectors, then there was mixed c++ and Visual Basic being compiled (it took a long time for that information to arrive), now we have windows and controls and graphics and more, and transparent controls on Windows 7.

So basically we have some fragments of information, not enough context, not all questions being answered, and we are back at the start - trying to guess.

The answer to all this is for you to post your code, or PM us a link to it on GitHub or similar.
No I had trouble with that, there was nothing there.
Hi,

Thanks for posting your code :+)

I looked at your code, but I don't see any evidence of your original question which seemed to be about nested classes in C++. I don't see any compilation of C++ anywhere. Was the topic about mixed C++ and VB? With that in mind, why wouldn't you just use .NET? I don't know much about .NET, but one can have a choice of languages: one might even be able to have one module in VB and another in C++, then combine them into 1 executable? Also, I reckon writing .NET code is a better thing than writing with Windows API. Perhaps ask one of the Windows people (I am a Linux Guy).

In general when doing a project, always look to see if there is some framework, library or tool that will help you - someone will have probably already done what you want to do, or at least partially. And those tools are likely to be much better than what code you could write.

With the llvm compiler I mentioned earlier: the lexer, parser, compiler, optimizer and AST are all obvious components. With your code those things are not so obvious.

Looking at your code in testfolder.zip:

* There is too much code in main.cpp.
In most projects of a reasonable size the main.cpp is quite small, only 50 LOC say.
* Consider pulling out the class definitions into *.hpp files, or *.tpp if they are templates. Name them the same as the classes, and have 1 class per file. The *.hpp and *.tpp are naming conventions which mean c++ header and template files. *.h means C header code.
* Put class function definitions into *.cpp files with the same names as the classes. Again one cpp file per class
* Avoid writing implementation code inline
* Your functions are too long. Keep them short, say 40 LOC or less. At the moment some of the functions are several hundred LOC.
Your comments often point to code which could be in a function. Example //Expressions:
* Avoid using namespace standard; It will bite you in the ass one day. There is plenty written about this on the web.
* STL container size() functions return a std::size_t , not unsigned int. Avoid the compiler having to do an implicit cast.

About your earlier question of making an executable:

In general this is a big tedious job, basically it involves converting the code from whatever language into assembler code, then compile that into an executable. That is why a tool like the llvm compiler is good, because it uses the Intermediate Representation (IR), which it can then easily convert into assembly then to executable.

As I said earlier, you might as well use .NET
- you didn't see the code about these question, because i'm trying get some information... i must finish somethings for it ;)
- yes my functions are too big, some i can short them;
- theres 1 thing that i don't like, realy, make the class header on 1 file and then define it on other file, i think, it's 2 works and make the things more separed... ok it's a person opinion;
- yes the main.cpp have too much code, i'm learn more what i can ;)

- "Your comments often point to code which could be in a function. Example '//Expressions:' "
maybe you can tell me more about the comments.

"I don't see any compilation of C++ anywhere."
hey i'm using the compilation:
- get the tokens;
- testing if the tokens are correct;
- getting the code line(expression, variable creation(more)) and test it's rules;
- then convert the code to C++ and call the C++ free compiler to make the exe(ok... these one isn't done, because, for now, i'm converting the code.
these is a big nice project that i'm learning and i'm not on school... i can learn much more about it, that i love ;)
thank you so much for all to all
- you didn't see the code about these question, because i'm trying get some information... i must finish somethings for it ;)


Well I can't comment on code I can't see, still after 1 week I am just trying to see what it is you want to do regarding the original question.

hey i'm using the compilation:


Yes you are compiling (converting the VB into C++), but I had the impression that there was a mixture of C++ and VB. Maybe this impression is wrong?

If you are going to have a file with sections of pure C++ followed by sections of pure VB, then you could cheat by tagging those sections with some kind of comment:

1
2
3
4
5
6
7
8
9
10
11
12
//C++

// C++ code here
//...

//End C++

//VB

//VB code here 
// ...
//End VB 


Then write the C++ code to another file and compile it separately.

If you don't do that, then you will be writing your own compiler to compile C++ code ....

This again takes me to the conclusion of using .NET , and you won't have to write any Win32 code.

- theres 1 thing that i don't like, realy, make the class header on 1 file and then define it on other file, i think, it's 2 works and make the things more separed... ok it's a person opinion;


Some of the reasons we have separate *.cpp and *.hpp files are:
* it allows reuse of the header files ;
* it makes life easier for the coder by keeping things separate ;
* we are not writing spaghetti code.

So it is more than a personal opinion.

With the code that should be in the main.cpp: only the Main function that you have, and line 1146 which should be inside Main function, not a global variable.

With the destructor of the compiler class:

If you have code in a destructor, then you are not doing RAII. However the code looks redundant, clearing the data from those vectors is pointless because they will be destroyed when they go out of scope.


maybe you can tell me more about the comments.


To make functions smaller, have them call other functions. The candidates for what can be in a function can include:

* the body (between the braces) of any of the loops (for, while, do)
* the body of if, else if, else statements
* switch statements
* the cases in the switch. Each case calls a function

Not all of these functions need be member functions of the compiler class. It might be possible to have some of them being free functions, otherwise they can be private: or protected: member functions, obviously some will necessarily be public.

You don't seem to have any kind of AST, so I can't help thinking that will be very limiting. For example can you process this: (a+b)/2.0; ?
The AST in the llvm compiler can process nested expressions, the more it is nested, the more it adds to the tree, this includes function calls too.

So with your project overall, you have, so far:

1. Converting VB code to C++ via compilation, with some Win32 code, in a limited fashion;
2. Wanting to use windows Forms with controls on them, with Win32 code.

If your project was just 1. without the Win32 code, then that might be feasible if written in pure C++. For example one could compile VB on Linux. Even then there is this: http://www.cplusplus.com/forum/lounge/246990/

But given requirements 1 and 2, this strongly points to using .NET (in my opinion), otherwise you would write massive amounts of code to reinvent the wheel. As far as I know, .NET was invented so one didn't have to write Win32 code, a lot of things can be done visually, without having to write much code at all.

I am sorry if this sounds terribly negative :+| But this is not the first time I have come across a project where a lot of time has been spent and lots of code written, but the coder has been unaware of what is already available. Then someone comes along, pours freezing water over the whole thing, and advises to abandon the existing code altogether. In these cases the coder is often unwilling to abandon everything, they can't seem to get over the investment they have put in, they see it all as a waste, but prefer to continue, eventually realizing they didn't achieve much. This sometimes happens in professional software development projects too, something will happen which in hindsight is a project killer, but they persevere and finish up wasting 10 times more money.

On the other hand, some people purposely do things like writing there own vector class for example, as a learning exercise. So you could continue with your project as a learning exercise if you want. Maybe use the llvm compiler directly, or at least learn about the AST. Using llvm is probably the easiest thing. Implementing your own AST would be a greater amount of work.

Or you could use llvm to compile a language that is only available on Windows, with a view to making an executable on another OS. It might be tough to find a language like that. I use the Eclipse IDE, it has plugins for lots of things, including all kinds of scripting, procedural and functional languages. This would also involve having to learn a bit about another OS, that is a good thing too

Or if you have a huge imagination, you could invent your own language :+D

As a final note, I keep mentioning llvm because it seems reasonable to me, but there may be other tools too.

Good Luck !!
thank you so much for all
Topic archived. No new replies allowed.
Pages: 12