below cant run

closed account (STR9GNh0)
----------------
Last edited on
You don't have to add anything, but you have to remove the braces on line 7
closed account (STR9GNh0)
------------------
Last edited on
What's your program supposed to do?
closed account (STR9GNh0)
to output the above.

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 



hopefully my explanation is clear enough~ sorry.
Last edited on
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? :/

-Albatross
Last edited on
closed account (STR9GNh0)
well... i am not sure thus i need a headstart. that's all. the rest i will do it myself.

thanks for any help assist.
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.
closed account (STR9GNh0)
ok...

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?

is there a way to do such things?
Last edited on
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.
closed account (STR9GNh0)
is there any starters for me ? i really don't wish to rely on people to help me.. but i just have no idea how to get this started.
try this out:
http://www.cplusplus.com/doc/tutorial/
I hope it helps.
oh, yeah, if you need specially just Array tutorial, the best one is here:
http://www.cplusplus.com/doc/tutorial/arrays/
closed account (STR9GNh0)
hello? does the above teach the specific info that i need?

if not, what's the point of showing those tutorials to me.
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. :)

http://cplusplus.com/reference/string/string/find_first_of/

NOTE: For more complex stuff, you might want to consider using regular expressions.

-Albatross
To Albatross: Not exactly. With that approach, { [ } ] will work when it shouldn't.
closed account (STR9GNh0)
anyway to use to bool statement to verify the match of left and right brackets?
Topic archived. No new replies allowed.