Brownian Circuits Language (BCL)
This page describes the current BCL specification as accepted by BCLCompiler in src/BCL/compiler.py. It is limited to syntax that is actually accepted by the present implementation.
Related pages:
1. Purpose Of BCL
BCL is a text format for describing CellSpace layouts and compiling them into YAML. The generated YAML can be passed directly to Config.cellspace_path.
The top-level YAML output is a list. Each entry looks like this:
- coord:
x: 10
y: 20
value: 1
2. Supported Features
coord.define(name, x, y)place.signal_line(x, y)place.token(x, y)place.recycle_bin(x, y)place.cell(x, y, value)element Name(param) { ... }place.Name(instance, param[expr, expr])
Comments start with # and continue to the end of the line.
3. Grammar
program := { statement | comment | blank }
statement := coord_define
| place_signal_line
| place_token
| place_recycle_bin
| place_cell
| element_define
| place_element
coord_define := "coord.define(" IDENT "," EXPR "," EXPR ")"
place_signal_line := "place.signal_line(" EXPR "," EXPR ")"
place_token := "place.token(" EXPR "," EXPR ")"
place_recycle_bin := "place.recycle_bin(" EXPR "," EXPR ")"
place_cell := "place.cell(" EXPR "," EXPR "," EXPR ")"
element_define := "element" IDENT "(" IDENT ")" "{" { statement_like_line } "}"
place_element := "place." IDENT "(" IDENT "," IDENT "[" EXPR "," EXPR "]" ")"
EXPR := INT
| IDENT ".x" [ ("+"|"-") INT ]
| IDENT ".y" [ ("+"|"-") INT ]
IDENT := [A-Za-z_][A-Za-z0-9_]*
INT := -?[0-9]+
Actual expression handling follows BCLCompiler._eval_value().
4. Cell Values
place.signal_line(x, y)->value = 1place.token(x, y)->value = 2place.recycle_bin(x, y)->value = -1place.cell(x, y, v)->value = v
5. element Expansion
element blocks are expanded in preprocessing.
Example:
element Dot(p){
place.cell(p.x, p.y, 3)
}
place.Dot(dot_1, p[15, 25])
Implementation constraints:
- only one parameter is supported
- the
param[...]name at the call site must match the definition parameter - multi-parameter
elementdefinitions are not supported
6. Unsupported Syntax
The current compiler rejects:
input: ...output: ...construct info(...) { ... }- multi-parameter
element - arbitrary expressions such as
a.x + b.x
7. CLI
The bcl command is exposed through project.scripts in pyproject.toml.
bcl INPUT.bcl -o OUTPUT.yaml
Example:
bcl Sample/bclfile/sample.bcl -o /tmp/sample.yaml
8. Python API
from BCL.compiler import BCLCompiler
comp = BCLCompiler()
comp.read_file("Sample/bclfile/sample.bcl")
comp.parse()
ir = comp.lower_to_ir()
comp.write_yaml(ir, "/tmp/cellspace.yaml")
For the one-shot path:
from BCL.compiler import BCLCompiler
BCLCompiler().compile_file("Sample/bclfile/sample.bcl", "/tmp/sample.yaml")
9. Minimal Example
# anchor
coord.define(io_a, 10, 20)
# primitive placements
place.signal_line(io_a.x, io_a.y)
place.token(io_a.x+1, io_a.y)
place.recycle_bin(io_a.x+2, io_a.y)
# macro
element Dot(p){
place.cell(p.x, p.y, 3)
}
place.Dot(dot_1, p[15, 25])
10. From BCL To PyBCA
- compile
.bclinto YAML - pass the generated YAML into
Config.cellspace_path - pass Rule YAML files into
Config.rule_paths - run
Engine.run()
11. Implementation Consistency
For the current sample assets, the following consistency checks were confirmed.
- all
Sample/bclfile/*.bclfiles parsed successfully BNN.bclmatchedSample/Cellspace/BNN.yamlC-Join_from_JF.bclmatchedSample/Cellspace/2-way_C-Join.yaml
12. Relationship To The GUI
bcl-editorusesBCLCompilerinternally for validation and YAML exportRule Editoroperates on Rule YAML files- see GUI Tools Guide for GUI details