-
Java Stack Block tracer
How you doing guys and gals,
i have a problem and i 'm really stuck. I have to write a porgram that read in a c file and output every integer in each block in the file. i know i need a stack.
e.g : read this from arg[0] :
int main()
{
int t = 6;
int x, y, z;
scanf("%d" , &t);
return 0;
}
void foo()
{
int folly = 9;
puts("what is meaning of this assignment?");
}
output
int t = 6
int x = 0
int y = 0
int z = 0
int folly = 9
Reading in the file the file is not the main issue , it's the algorithm i can't figure it out. i have a program that convert infix to postfix notation because i though this was a simmilar problem but i can't seem to get a hint.
The main tokens to be used in the stack i know are '{' 'int', and '}' because they denote each blocks. Can anyone please gives me a few hints or pointers, not asking for the full solution just a helping hand or any help at all.
thank you for your time,
Meldroz
If A equals success, then the formula is: A = X + Y + Z where X is work; Y is play; Z is keep your mouth shut. Albert Einstein
-
i fail to see why you would need a stack data structure, or infix/postfix routines..
infix converts (59+) to (5+9)
postfix converts (7^5) to (75^)
how does this help a simple search and print? either there's something about your assignment that you havent clearly explained.. or someone's shown you the wrong tree...
-
Hi,
This is basically like a parsing program, the'{' of the main would be like the '(' in a arithmetic problem, this is why i mentioned the the infix/posfix stuff because using the stack is the only way i've learned to handle that.
i have to push '{' on the stack and poped it when i hit '}' to know that this block was dealt with, and start with another block. when i see an "int", i have to ouput any variable in front of it, so shouldn' t that be pushed too until the end of that line?
i may be wrong but that's the hint i was given.
Don't know if that's clearer than before, but i know i have to use the stack to trace the "{" and "}" at least , i don't see any other way, well any easier way.
If A equals success, then the formula is: A = X + Y + Z where X is work; Y is play; Z is keep your mouth shut. Albert Einstein
-
to be honest, your output example doesnt look anything different froma list, which is why i suggested a simple sort of algorithm:
read_a_line
If_line_contains_the_word_int
..Print_it_out
..If it contains more letters (int a,b,c) separated by commas, print those out too
er...
no stacks, no infix/postfix.. just a simple BufferedReader and a couple of if statements
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks