øAslickproductions.org/forum/index.php?PHPSESSID=68p7via6vbjki8mblg09r3gui5&topic=457.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index6827-4.htmlslickproductions.org/forum/index.php?board=16.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index6827-4.html.zxÉ_h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈÐy´OKtext/htmlISO-8859-1gzip@øÕy´ÿÿÿÿÿÿÿÿWed, 11 Mar 2020 04:05:54 GMT0ó°° ®0®P®€§²ð®É_h^Ny´ Wrote the expression parser last night.

Author Topic: Wrote the expression parser last night.  (Read 4725 times)

Entroper

  • Moderator
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Wrote the expression parser last night.
« on: March 27, 2008, 10:32:03 AM »
I love trees, recursion, and polymorphism.   :happy:

JCE3000GT

  • Master of FF4
  • *
  • Posts: 1,429
  • Gender: Male
  • Vladof
    • View Profile
    • BlitzKrieg Innovations
Re: Wrote the expression parser last night.
« Reply #1 on: March 27, 2008, 07:02:32 PM »
I love trees, recursion, and polymorphism.   :happy:

You know what's coming...































 :picsorstfu:

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Wrote the expression parser last night.
« Reply #2 on: March 27, 2008, 09:21:50 PM »
I'm more wondering what that post was about in the first place. Give explanation! Or I may send the :cookie: after you...

119 bugs fixed and counting.

Odbarc

  • Hell's Rider
  • *
  • Posts: 424
  • Gender: Male
  • FF6 obsessed
    • View Profile
    • Newage3.com, a text based web game RPG I Admin.
Re: Wrote the expression parser last night.
« Reply #3 on: March 27, 2008, 11:29:14 PM »
I love trees, recursion, and polymorphism.   :happy:

I have no idea what your talking about, but I'm excited!

Entroper

  • Moderator
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: Wrote the expression parser last night.
« Reply #4 on: March 29, 2008, 04:59:34 PM »
Well, for those who don't know programming, you won't understand.  For those who do...

The expression system is a tree data structure, where each node in the tree is a class derived from the Expression abstract base class.  Leaf nodes are literals or variable names, and non-leaf nodes are operators like +, -, AND, OR, >, <, etc.  So when your expression contains a +, there's a node in the tree for the + which has two expressions as children.  That's the trees.

The recursion comes as a natural result of working with trees.  To evaluate an operator like +, you simply evaluate its sub-expressions, add the results together, and return the answer.  The recursion stops when you evaluate a literal or variable node (which just returns the value).  And the polymorphism comes in with the Evaluate() function being a pure virtual function in the Expression class.

Entroper

  • Moderator
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: Wrote the expression parser last night.
« Reply #5 on: March 29, 2008, 06:44:11 PM »
I'm working on ways to display the expressions as strings and write them to files for the script editor now.

Can you guys deal with prefix notation?  It's definitely going to be that way in the file, and I think it'll be viewable as a tree in the editor.  But it would be nice to collapse the tree down to a single line, and I don't want people to be horribly confused by prefix notation.  Prefix notation is where you write + 2 3 instead of 2 + 3, or * 5 + 2 3 instead of 5*(2+3) for example.

Deathlike2

  • FF4 R&D Master
  • *
  • Posts: 3,538
  • I'm looking at you, bitch!
    • View Profile
Re: Wrote the expression parser last night.
« Reply #6 on: March 29, 2008, 07:06:00 PM »
Notation that follows the order of (math/algebraic) operations would be preferred.
Working on the next Yet To Be Named FF4 "Hardtype" Hack Download Latest: v1.48

Video Demos: #1 #2 #3

Entroper

  • Moderator
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: Wrote the expression parser last night.
« Reply #7 on: March 29, 2008, 11:11:55 PM »
Yeah, I should NOT have written that code after driving back down from DC last night.  I just now got it to pass my tests after spending the last hour fixing a huge number of errors.  :bah:

Entroper

  • Moderator
  • *
  • Posts: 235
  • Gender: Male
    • View Profile
Re: Wrote the expression parser last night.
« Reply #8 on: March 30, 2008, 12:21:12 AM »
Note for future reference:

Code: [Select]
return new ExprBinaryOp(op, BuildExpression(in), BuildExpression(in));
Seems like a simple line of code.  Interestingly enough, in testing, it turns out that the second call to BuildExpression() actually executes first!  Since it is important that expressions are read from files in the same order as they are written to files, this resulted in the order of operations being reversed.  I had to change the above to:

Code: [Select]
Expression *lhs = BuildExpression();
Expression *rhs = BuildExpression();
return new ExprBinaryOp(op, lhs, rhs);
This ensured the order was correct.  Pretty strange if you ask me... I had no idea that function parameters were not always evaluated left-to-right.