:: krowemoh

Friday | 13 DEC 2024
Posts Links Other About Now

previous
next

The Template Language - IF

2023-06-18
basic, template-language

I've now implemented my IF logic in my renderer and I'm more sure now than ever that I haven't found the right strategy to writing a compiler. I'm still getting there. The logic I've implemented is that once I see the start of an IF block I want to find the entire block. This means I need to make sure I keep track of where I am in the block and at what level I'm at.

This means that IF statements shouldn't be single lines and you can't use shortcuts, you need to use the block structure. This means that IF statements should end with THEN and a final END should close the block.

Once I have the full block, I then also keep track of conditionals and their associated block.

Once I have a list of conditionals and their blocks, I go through the conditionals and the first one that passes, I will then render that block.

It's a very simple system but it took some time to work out all the kinks.

I'm not a big fan of the code as it involves many different pieces and I think it could be simpler.

I also made my blog index page into a template and my renderer is definitely slow. It's faster to read in the item in the template than to pass it in from the BASIC program. This was an unexpected result.

It also takes about 2 seconds to get 500 items looped over and the template rendered for them which is just a little bit too long. I need to figure out where the slowdown is because this ridiculously slow.

I don't even think its the recursive render because it should be at most only 3 levels. Maybe there is something else that is causing the slowdown but I will need to look at that or this is all unusable.

The final logic I think I need to implement is a regular loop. Once I have this I think I have all the pieces I need for a fully functional templaying language.