70's futuristic technology

Programming focused drivel

Friday, August 20, 2004

I have been chipping away at my simple templating engine.
I have been having a hard time wrapping my brain around
looping conditions. Basically it took me a while to figure
out a data structure that would allow me to access the
template data as I parsed and executed tempalte code.

I finally have a working prototype. The template programmer
would store their data in multi-dimensional arrays and
put them into the TemplateData instance.

The TemplateEngine will now have a Hashtable for looping
contexts. A Stack is placed into this Hashtable and a
reference to the multi-dimensional array is pushed onto
the stack. As we enter loops, a new value is pushed onto
the stack, which is the Array.get( stack.peek(), index )
of our loopContext. As we delve into deeply nested loops,
we get closer and closer to the String stored in the array.

Once we enter the loop context where the value will be used,
a String is what will be pushed into the stack, instead of
another reference to a multi-dimensional array.

Uses of variables are a simple peek() call.

As we exit loop contexts, we pop the stack.
My prototype is a hardcoded 3x loop, now to generalize the code
to handel n deep loops.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home