Symbol interpretation definition

Defines interpretation action to set of symbols. In following examples debugInterpretation property is set to show actual calls on renderer.

Basic interpretation definition

Arguments from symbols are forwarded to interpreter actions. Symbol with no defined interpretation is ignored.

Input

1
2
3
4
5
6
lsystem InterpretationExample01 {
set debugInterpretation = true;
set symbols axiom = F(2.5) + F(5, 0) G H;
interpret F as DrawForward;
}
process all with ThreeJsRenderer;

Output

Begin processing
F(2.5) => DrawForward(2.5)
+ => 
F(5, 0) => DrawForward(5, 0)
G => 
H => 
End processing

More than one symbol can be specified for one action.

Input

1
2
3
4
5
6
lsystem InterpretationExample02 {
set debugInterpretation = true;
set symbols axiom = B A A C;
interpret A B C as DrawForward(8);
}
process all with ThreeJsRenderer;

Output

Begin processing
B => DrawForward(8)
A => DrawForward(8)
A => DrawForward(8)
C => DrawForward(8)
End processing

Interpretation action default parameters

Arguments that are not supplied by symbol are taken from action's defaults.

Input

1
2
3
4
5
6
lsystem InterpretationExample03 {
set debugInterpretation = true;
set symbols axiom = F F(5) F(5, 6, 7);
interpret F as DrawForward(0, 1 + 1);
}
process all with ThreeJsRenderer;

Output

Begin processing
F => DrawForward(0, 2)
F(5) => DrawForward(5, 2)
F(5, 6, 7) => DrawForward(5, 6, 7)
End processing

Custom action invoking

Arguments from symbols are matched on local variables listed after symbol. Unmapped symbol's arguments are ignored.

Input

1
2
3
4
5
6
lsystem InterpretationExample04 {
set debugInterpretation = true;
set symbols axiom = F(1, 2) F(2, 2, 2);
interpret F(a, b) as DrawForward(a + b);
}
process all with ThreeJsRenderer;

Output

Begin processing
F(1, 2) => DrawForward(3)
F(2, 2, 2) => DrawForward(4)
End processing

Not enough custom arguments supplied by symbol to map all parameters causes an error.

Input

1
2
3
4
5
6
lsystem InterpretationExample05 {
set debugInterpretation = true;
set symbols axiom = F F(5);
interpret F(a, b) as DrawForward(a + b);
}
process all with ThreeJsRenderer;

Output

  1. Warning [Malsys.Processing.ProcessConfigurationBuilder+Message#ComponentValueAssignNotUsed]: Component value assignment `compressSvg` not used. No component to assign to.
  2. Info [Malsys.Processing.Components.Common.RandomGeneratorProvider+Message#NoSeed]: No random seed given, using value 569676324.
  3. Error [Malsys.Processing.ProcessManager+Message#LsystemEvalFailed]: Evaluation of L-system `InterpretationExample05` failed. Not enough custom arguments supplied by symbol `F` to interpretation of `DrawForward`.

When custom parameters are specified, no automatic argument forwarding is done.

Input

1
2
3
4
5
6
lsystem InterpretationExample06 {
set debugInterpretation = true;
set symbols axiom = F(5) F(2, 4);
interpret F(a) as DrawForward(0);
}
process all with ThreeJsRenderer;

Output

Begin processing
F(5) => DrawForward(0)
F(2, 4) => DrawForward(0)
End processing

More symbols can be specified, custom parameters are after last.

Input

1
2
3
4
5
6
lsystem InterpretationExample07 {
set debugInterpretation = true;
set symbols axiom = A(1) B(2) C(3) B(4);
interpret A B C (a) as DrawForward(a * a);
}
process all with ThreeJsRenderer;

Output

Begin processing
A(1) => DrawForward(1)
B(2) => DrawForward(4)
C(3) => DrawForward(9)
B(4) => DrawForward(16)
End processing

Default values of custom parameters

Default values of custom parameters can be also specified.

Input

1
2
3
4
5
6
lsystem InterpretationExample08 {
set debugInterpretation = true;
set symbols axiom = F F(2) F(2,4);
interpret F(a = 5) as DrawForward(a);
}
process all with ThreeJsRenderer;

Output

Begin processing
F => DrawForward(5)
F(2) => DrawForward(2)
F(2, 4) => DrawForward(2)
End processing

All parameters with default values have to be after parameters without default value.

Input

1
2
3
4
5
6
lsystem InterpretationExample09 {
set debugInterpretation = true;
set symbols axiom = F(1, 2) F(1, 2, 3);
interpret F(a, b, c = 5) as DrawForward(a, b, c);
}
process all with ThreeJsRenderer;

Output

Begin processing
F(1, 2) => DrawForward(1, 2, 5)
F(1, 2, 3) => DrawForward(1, 2, 3)
End processing

More symbols can be specified, custom parameters are after last.

Input

1
2
3
4
5
6
lsystem InterpretationExample10 {
set debugInterpretation = true;
set symbols axiom = A(2) C(8, 8, 8) B(2, 2);
interpret A B C (a, b = 5) as DrawForward(a, b);
}
process all with ThreeJsRenderer;

Output

Begin processing
A(2) => DrawForward(2, 5)
C(8, 8, 8) => DrawForward(8, 8)
B(2, 2) => DrawForward(2, 2)
End processing

Prevent implicit argument forwarding

Sometimes we use symbol's arguments only in rewrite rules to control rewriting process and we do not want to forward them to interpretation method. Imagine we want to call DrawForward(10) on all symbols A but A's have some parameters. Because argument forwarding is disabled when explicit parameters are specified we can just specify "dummy" parameter that we don't use. Do not forget to specify default value of dummy parameter to allow interpreting symbols without arguments.

Input

1
2
3
4
5
6
lsystem InterpretationExample11 {
set debugInterpretation = true;
set symbols axiom = A(-5) A(20, 5) A A(0.01);
interpret A (dummy = 0) as DrawForward(10);
}
process all with ThreeJsRenderer;

Output

Begin processing
A(-5) => DrawForward(10)
A(20, 5) => DrawForward(10)
A => DrawForward(10)
A(0.01) => DrawForward(10)
End processing

Arguments and default values are expressions

Arguments of action and default values of custom parameters can be expressions. Global or local constants can be also used.

Input

1
2
3
4
5
6
7
8
9
let three = 1 + 2;
lsystem InterpretationExample12 {
set debugInterpretation = true;
let six = three * 2;
set symbols axiom = A(1) A(1, 2) A(2, 3);
interpret A (a, b = 0)
as DrawForward((a + three) * six, a + b * three);
}
process all with ThreeJsRenderer;

Output

Begin processing
A(1) => DrawForward(24, 1)
A(1, 2) => DrawForward(24, 7)
A(2, 3) => DrawForward(30, 11)
End processing

Redefinition of interpret actions

If there are two interpret definitions for one symbol the older definition is replaced by newer one.

Input

1
2
3
4
5
6
7
lsystem InterpretationExample13 {
set debugInterpretation = true;
set symbols axiom = A B;
interpret A B as StartBranch;
interpret B as Nothing;
}
process all with ThreeJsRenderer;

Output

Begin processing
A => StartBranch
B => Nothing
End processing

Interpretation redefinition is especially important in L-system inheritance. If base L-system defines some interpretations the definitions in derived L-system always replaces old ones.

Input

1
2
3
4
5
6
7
8
9
abstract lsystem Base {
interpret A B as StartBranch;
}
lsystem InterpretationExample14 extends Base {
set symbols axiom = A B;
set debugInterpretation = true;
interpret A as Nothing;
}
process all with ThreeJsRenderer;

Output

Begin processing
A => Nothing
B => StartBranch
End processing

Formal grammar

1
2
3
4
5
6
7
symbols_interpretation_def = 'interpret' SYMBOL+ symbol_params? 'as' ID action_params? ';'
 
symbol_params = '(' params_list? ')'
params_list = ID ('=' expression)? (',' params_list)?
 
action_params = '(' params_expr_list? ')'
params_expr_list = expression (',' params_expr_list)?