smarty标签到php转换/替换

Here is the following "Smarty" tpl code:

{if !$document}
    {assign var=document value=15}
    {"document set"}
{/if}

bellow is the equivalent code but in PHP I've converted manually:

<?php if (!$document) { ?>
    <?php $document=15; ?>
    <?php echo "document set"; ?>
<?php } ?>

The problem is to find the most simple way to convert/replace such lines of code automatically without the use of "Smarty" internal engine routines.

I thought maybe regex is a solution.

If you could share your thoughts/solutions on the subject.

Thank you.