is like a compiler outputting errors in your coding.
but instead of letting the compiler to do it.. the try, catch is used thus preventing the program's compiler from making noise.
don't know if the experts here understand what i am trying to explain here~
how should i explain.. erm...
- take over from the program's compiler check for error role and output my own output version of check for error role
1 2 3 4 5
// my program
int main()
{
int x [10] = {0};
1 2 3 4 5 6 7 8 9 10 11 12
// this is what it should appear when i execute it~
Line 1: int main ()
( @ line No 4 inserted to stack
( @ line No 4 matched with } @ line No 4
Line 5: {
{ @ line No 5 inserted to stack
Line 6: int x [10] = {0};
[ @ line No 6 inserted to stack
[ @ line No 6 matched with ] @ line No 6
{ @ line No 6 inserted to stack
{ @ line No 6 matched with } @ line No 6
{ @ line No 5 - not matched // forgot to close the program
So you want to build a basic C++ parser to replace front-end for your compiler? Is that it? That's a tricky task, depending on your compiler; some of them are closed-source.
Or do you want a completely separate program that you can run in addition to your compiler to check for errors? That would be easier, but you'd still have to create a parser, which could be tedious depending on your skill level.
Also, are you sure you're completely familiar with the concept of a stack? :/
Hoo boy. You may think this is a good idea, but it isn't. Parsing C++ code is way beyond tricky. It's a nightmare of epic, biblical, lovecraftian proportions. Consider the simple code: a f(b,c);
If a, b and c are types, this is a declaration for a function f returning an a object, which takes a b object and a c object. If b and c are variables, this could be a declaration and initialization of an a object called f, using b and c to initialize it.
And of course there's templates and stuff, which make you write a lot of interpreter-like functionality.
lets say i want to design a program to like when i encounter a bracket in my codes i want to know where it is situated, eg at which line in a program statement.
or create a c++ program to analyze any c++ program, treated as text file?
A bracket matcher is indeed feasible. Make a function that calls itself when it encounters a bracket, and then returns when it encounters the opposing bracket or the end of file. If it encounters the close bracket, print where the two brackets are. If i encounters end of file, print an error saying where the unmatched bracket is.
For something as simple as bracket matching, you'd just need a few counters, an std::string, and an std::string::find_first_of() function in a while loop. Well... a bit more than that, but I hope you get an idea of where to start. :)