Saturday, March 20, 2010

Expression Handling (2nd approach)

After the first implementation, I have made a few more improvements and now, after submitting my assignment I think it's safe to post the final version of the classes here. Source code is available here (MediaFire). You may want to read the documentation here (Google Docs, in Vietnamese). The script is now accept natural expression input from console. The most interesting feature is each variable can also be enter as an expression (and it will ask for it's variables also). What does this mean?

For example, you input an expression: 5+x+y*z. Obviously, it will be calculated at 5 + x + ( y * z)
But because you used 3 variables, it will ask your for x, y, z. I will assign x with value of 20, y with 10.
Now is the fun stuff: I input "a-b" for z. Uhhhh. What do you think the script will do now?
Ah ha, it will ask for z.a (which means the 'a' variable of 'z' expression), 100 to go
And then z.b: 1000 to go
The result is -17985 (I'm not really sure with this result but you can check yourself)

That example is from the documentation. Feel free to leave comment


  1. Trung's here. Your solution is good but I think it's a bit partial.
    I have this good book, it is Compiler, principle, technique and tools. It's about making a compiler, which should be a good reference for Expression Handling, care about that?

  2. Got no notification about your comment. Sorry mate :D

    Yeah, sounds like an interesting book. Send me via email please?

  3. No, it's actually in real papers...
    Do a google search on this book's name, it's a famous one :D or I can lend you mine (if you still need it then :") )