begin("house").

divide_y("80% 20%", "living_area roof").

end();

begin("church").





// main space

push().

occludes().

center().

scale("90%", "100%", "70%").

box().

select("face_x", "nave_walls").

select("face_z", "nave_facade").

push().

move("0", "100%", "0").

loft_box("80%", "100%", "0%").

select("face_x", "thin_wall").

pop().

pop().





// transept

push().

move("10%", "0", "0").

push().

occludes().

center().

rotate_y("90").

scale("70%", "100%", "50%").

box().

select("face_x", "transept_walls").

select("face_z", "transept_facade").

push().

move("0", "100%", "0").

loft_box("80%", "100%", "0%").

select("sides", "thin_wall").

select("prism_sides", "prism_cap").

pop().

pop().

pop().





// towers

push().

move("0", "0", "100%").

push().

scale("tower_width", "300%", "tower_depth").

move("0", "0", "-50%").

module("tower").

pop().

pop().





push().

push().

scale("tower_width", "300%", "tower_depth").

module("left_tower").

move("0", "0", "-50%").

pop().

pop().





// apse

push().

move("20%", "0", "0").

push().

occludes().

center().

scale("130%", "100%", "130%").

ngon("18").

select("sides", "nave_wall").

push().

occludes().

move("0", "100%", "0").

move("0", "0.5", "0").

loft_ngon("18", "100%", "0%").

select("sides", "thin_wall").

select("prism_sides", "prism_cap").

pop().

pop().

pop().

end().





If you were the last person in the world, would you build a parser?It is only me using this engine at this point. There is no UI for any of the things you can define for the virtual world. Not even configuration files, XML, INI, etc. It is all a big soup of C++ code. To me it is the same to change a value in a C++ file than to edit a configuration file.Then I started working on the architecture L-System. Soon I realized that writing grammars in C++ was not very good. They were extremely verbose and hard to read. It would be better if the grammar was written in a language designed just for that. For the first time in this project, I started considering parsing from an external file.Luckily I remembered an old trick. I saw it long time it in ancient UI systems to define menu structures. The trick is to define functions that always return the state you are building, so you can chain their calls.For instance, you can have a construct like:It is really three functions being chained one after the other, but it looks like an structured construct. The "begin" function returns a new rule object with the specified name, in this case "house". Then the "divide_y" function is called in the rule to specify a house will be divided in two spaces, the living area and the roof. The function also returns the rule, so if we wanted to add more instructions we could do it right there. Then the "end" function returns the grammar object so a new rule can begin.It is quite simple to use, the grammars are easy to read and you get all the help from the C++ compiler. Even the intellisense kicks in and gives you hints about function signatures. Also it allows to move into a different format in the future, even a dynamic UI. What changes is how the grammar objects are created, nothing more.Just so you get a feeling of the written grammars, I leave you with the rules that define the church of my earlier screenshots . This is just the main module for the church. It references other modules that I did not include here. In a future post I will explain what these functions actually do.