After dealing with the fallout from several developers at varying levels of experience coding with their own ad hoc styles, to deadlines, I want to settle on an AS3 framework to form the basis of future large-scale projects. I considered Cairngorm for a while, but I’m now leaning towards PureMVC for several reasons. First, the [...]
Two new bloggers have hit the scene recently that are a must for your daily reading: Gary Gilchrist - http://highway101.wordpress.com Gary is a software architect at Adobe that specializes in security and LiveCycle ES.  I’ve known Gary for over two years and have found him to be one of the smartest guys I know.   If you are interested in LiveCycle [...]
Over the last few months I’ve been learning ColdFusion and the more I learn the more I’m amazed at how powerful and easy it is to use. I used to use php for server side code but after reading so many articles on how Flex and ColdFusion works so well together I had to see [...]
I just updated The GAE SWF Project to version 1.21. New source code for the update is now available for download. All changes in this version are server-side: All requests apart from those to the PyAMF gateway go through the IndexHandler class. The app.yaml file no longer maps /examples/ urls to the various example SWF applications (currently [...]
I'm pleased to announce that the Prana Framework 0.5 release is now available. Download | API Documentation | Changelog In this release we further focused on bringing the core Inversion of Control container API closer to that of the well known Spring API. In addition, the release also contains the following: an XSD for editing object definition XML files application context classes that [...]
Just a quick note while I’m waiting for my flight to Toronto. We have a new version of the broadcaster for our Red5Server booth at FITC Toronto 2008 up and running. Thanks to Jerry Chabolla for his hard work pulling this together. Here’s the link, see you there! http://red5server.com/fitctoronto_booth/vcbroadcast.html
Often while working on dynamic flash websites, I get confronted with the challenge of placing multiple interactive items on top of an image. (think of it as a Ferrari with roll over popup zoom and detail buttons).  Since it's dynamic, x/y coordinates...
Just a quick note to let you know that I’ll be giving a presentation on Prana at the Dutch Flex Usergroup called Flugr on the 13th of June. So if you’re in the neighborhood (Utrecht) and would like to meet, feel free to visit the event. The following sessions will be given: - Benjamin Dobbler & Stephan [...]
It is very common to find repeated property values in a CSS stylesheet. CSS Variables allow authors to define variables that are reusable as property values anywhere in a stylesheet and queryable/modifiable through an extension of the CSS Object Model.
It is very common to find repeated property values in a CSS stylesheet. CSS Variables allow authors to define variables that are reusable as property values anywhere in a stylesheet and queryable/modifiable through an extension of the CSS Object Model.
We just had a small discussion on the Papervision3D list about using vague objects with untyped properties passed to methods as a single argument, rather than setting multiple arguments strongly typed and how that compares in terms of speed. It was suggested that it was faster to use untyped objects in a constructor call [...]
I just updated The GAE SWF Project to version 1.20 on appspot. A quick list of changes: Pulled out BaseView and BaseApplication classes. Simplified service calls. You no longer have to use Service.call() and pass a reference to the view instance. Just use execute("service.method", arg1, arg2, ...). Fixed a bug where the app was remembering the initial deep [...]
*UPDATED FOR GREAT WHITE* I have many requests by e-mail to update this example for Great White. Here you go: In case your curious, that’s a picture of me and my son. I’m the one on the right First you must download Tweener from here: http://code.google.com/p/tweener/downloads/list and add it to your classpath just [...]
Lost a few hours to this one today. I was trying to embed a font in a textfield with the antialising set to ‘Bitmap Text (no anti-alias)’. No matter what though, the font would not display in the text field when embedded. Turns out that internally flash actually renames the font, [...]
A garage full of cars, infinite rubber to burn, Flash physics, and lots of 2.0 cool effects, this is Monster Burnout, the latest creation of our friends at Hi-ReS! and Goodby, Silverstein & Partners, featuring the legendary Mr Doob. As he explains in his blog: Used the ubercool (and free) FlashDevelop 3.0.0 Beta 6 and it [...]
Welcome to the world’s northernmost sneakers’ store and showroom, in Norway. Click on a shoe to zoom in, use the arrow keys to navigate between shoes, click on the shoe again to zoom out. Kim Daniel Arthur has developed this really interesting shopping experience with PV3D 1.5. The interactivity is been done using InteractiveMaterials: adding standard [...]
Ok, I am a bit late with my report but I was a bit busy the last weeks working on the Multi-Mania conference we are organizing in May but I really wanted to make a short wrap up of the conference. In some words : 360 FLEX Europe was fantastic !! I cannot describe it in [...]

Finally I have a bit of free time to write down this post. Some days ago a guy on the forum asked about how to evaluate at runtime simple mathematical expressions with support for symbols and function calls.

Now that the eval function have been removed from the language for reasons I've not enought time to talk about, we need to parse and execute those expressions manually.

I built a simple Actionscript library that can be used to parse mathematical expressions: it has support for function calls, for variables and it is able to convert the expression into a postfix rappresentation if you may need it. The expression parser is quite simple and have been built manually following some concepts related to programming language compilers; it includes a Scanner (or lexer - however you want to call it) to tokenize the expression, a Parser that convert the expression into an Abstract Syntax Tree and a simple routine that evaluates that AST using a Symbol Table as evaluation context.

There are no comments inside the code right now; I hope to find a little bit of time to write an in depth discussion about this topic. In the mean time you can continue reading the entry for a general explanation about how does the code works and for some examples that may be useful.

Here is a simple example that shows how does the code works:


import it.sephiroth.expr.CompiledExpression;
import it.sephiroth.expr.Parser;
import it.sephiroth.expr.Scanner;

public class Example
{
  public static function run(): void
  {
    var expression: String = "sin( x / ( 8 / 2 + (-0.12 + 2.3) * x / x ) ) * 100";
    var scanner: Scanner = new Scanner( expression );
    var parser: Parser = new Parser( scanner );
    
    var compiled: CompiledExpression = parser.parse();
    
    var context: Object = {
      x:    100,
      sin:   Math.sin,
      cos:  Math.cos
    };
    
    trace( 'Postfix:', compiled.toString() );
    trace( 'Result:', compiled.execute( context ) );
  }
}

Before I forgot, you can download the source code here with a simple example included.

Subscribe to Planet Flash

Search

Tags

<head> 3d 3d Flash Actionscript actionscript 3 ActionScript 3.0 Adobe Adobe Air Adobe AIR (Apollo) Adobe Flash Adobe Flex AdobeMAX08 AIR AIR Adobe Integrated Runtime Announcements apollo Art AS2 as3 Asides awards Babble BEA Beautiful Web Books Business Cairngorm ColdFusion Community Components Conference Conferences degrafa design dev Development Events Examples Featured Flash Flash CS3 Flash experiments flash player Flex Flex 3 Flex Builder Flex Builder Development Flex Example FMS Fun Gallery General GeoWeb Google Industry Inspiration iphone Jobs Links linux Marketing MAX MAX 2007 Misc News news & events Off topic Open Source Other Papervision3D Parallax Denigrate Personal photos Photoshop Process Processing Resources RIA Singularity Site News Stuff techmology Technology Tennis Thinking Loud Tips Uncategorized Video Whatever

Blogs

Buttons

Planetarium