Using a Script to Build 3D Scenes

Let’s say we wanted to build an English-like scripting language to draw 3D scenes. The language might look something like this:

 
x = Cube
 
y = Sphere
 
y.radius = 20
 
draw x
 
draw y to the left of x and behind x

The fastest way to get this running is probably with Pattern 24, Syntax-Directed Interpreter. Most likely we wouldn’t care about speed. Issuing commands is a lot faster than rendering objects in 3D, so parsing and interpreting would not be the bottleneck. The interpreter would need Pattern 2, LL(1) Recursive-Descent Lexer and Pattern 3, LL(1) Recursive-Descent Parser or Pattern 4, LL(k) Recursive-Descent Parser. To go beyond recognition, we’d need to add actions to the parser that respond to the ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.