Code:
$code = array(
new Token("f", array("hello_world")),
new Token("{", array()),
new Token("printf", array("%s %s!\\n", "Hello", "World")),
new Token("}", array()),
new Token("printf", array("Test\\n")),
new Token("hello_world", array())
);
This is really a kludgy and non-extensible way to start with things. It works for very limited cases, but there's a reason why people use abstract syntax
trees, because you want to store logical blocks, rather than a mixture of random typeless symbols, which will make you put all sorts of unrelated code into blocks where they're not relevant (like the if (curly_brace) ignore(); style of code you already have).
How you actually want to write that is more like the following:
Code:
$code = array(
new Function("hello_world", array(/*no arguments*/), array(
new CallExpression("printf", array(
new StringExpression("%s %s!\n"),
new StringExpression("Hello"),
new StringExpression("World")
))
),
new CallExpression("printf", array(new StringExpression("Test\n"))),
new CallExpression("hello_world", array())
)
From there, it's much easier to add additional language features. Adding integers to this structure is simple, as is 1 + 1, as well as nesting functions in arguments such as printf("%i", getch()); Try to find an obvious way to do that with your original structure