Java Stack Block tracer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Java Stack Block tracer

  1. #1
    Join Date
    Feb 2004
    Posts
    8

    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

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    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...
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Feb 2004
    Posts
    8
    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

  4. #4
    Join Date
    Feb 2004
    Posts
    808
    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
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center