The problem I see with this approach is that the syntax is too vague for certain things... The grammar you describe there is able to lexically identify tokens and create a token tree. However, once you've built the tree, you have to re-walk it in order to manually determine if it's correct or not. For instance,
Code: Select all
material my_material
{
technique
{
pass
{
...
}
}
}
will create this tree sturcture (by the way, I've realised it doesn't recognise "material my_material {...}"):
Code: Select all
block_contents
block
keyword
{
block_contents
block
keyword
{
block_contents
block
keyword
{
block_contents [...]
}
}
}
But the problem is that
Code: Select all
material my_material
{
pass
{
technique
{
...
}
}
}
generates the same tree.
So we would need some extra token attributes (for instance, its value, to differentiate, ie "technique" and "pass"). And then, perform the syntax correctness check ourselves by hand on the tree.
Yacc/Bison can perform LALR analysis easily, checking the syntax correctness as they build the syntactic tree, and also performing associated syntactic/semantic actions (useful to build the objects structure -a material and their techniques, passes...- as the script is parsed).
IMHO, it's better to use an existing parser generator, though it might require to define each grammar separately, forced to duplicate some code there...