表达简单的几何处理计算图

时间:2019-05-04 03:34:41

标签: compiler-construction dsl

我正在编写一个简单的几何构图/操作库。该库需要允许客户端表达如下所示的高级逻辑:

table_base = Cylinder(r=..., h=..., anchor=None)
table_stem = Cylinder(r=..., h=..., anchor=None)
table_top = Cylinder(r=..., h=..., anchor=None)

# Build an abstract entity 'table' by specifying relationships
# between its components. No concrete locations specified yet. 
table = Geometry()
table.add(table_base)
table.stack(table_stem, table_base)
table.stack(table_top, table_stem)

# Provide concrete location for the base
# Assume 'table_base' is accessible via its name
table['table_base'].anchor = (0, 0, 0)  

# At this point we have information to populate 
# 'anchor' locations for other components
table.build()

如上所示,我们首先构建基元(假设我对此有表示)。然后,我们将table构建为抽象几何对象。最后,我们提供底座的锚点位置。当我点击build()时,我希望这些信息在依赖关系树中级联,并为其他组件填充anchor位置。诚然,我可以要求客户预订自己的锚点位置,但是对于复杂的对象,这将变得乏味。在build步骤之前,什么合适的表示形式来保持组件之间的抽象关系?

您可能会说,我没有编译器或编写DSL的背景。因此,即使我要寻找的名称也将是一个很好的起点。语言偏好Python,但我对概念理解更感兴趣。

0 个答案:

没有答案