# L-system definition

To learn basics of Malsys and L-systems work, please take a look at basic topics on documentation page. Another good place for learning is gallery. All entries in gallery have source included in details, just pick some simple one and experiment with their source.

## L-system inheritance

L-system can inherit (extend) all features from some other L-system. The pre-existing L-system is called base or ancestor and the new L-system is called derived L-system or child L-system. Inheritance behavior of individual L-system statements can be found on their reference pages along with examples but they all follows simple rule: derived L-system will redefine definitions in base L-system.

In following example there are defined two L-systems, `BaseLsystem`

and `DerivedLsystem`

which derives `BaseLsystem`

. `BaseLsystem`

will produce `B B B B B A`

but `DerivedLsystem`

overrides number of iterations to 2 and overrides rewrite rule for symbol `A`

. Due to overrides `DerivedLsystem`

will produce `X X A`

.

#### Input

1 2 3 4 5 6 7 8 9 10 11 12 13 | lsystem BaseLsystem { set symbols axiom = A; set iterations = 5; rewrite A to B A; } lsystem DerivedLsystem extends BaseLsystem { set iterations = 2; rewrite A to X A; } process BaseLsystem with SymbolPrinter; process DerivedLsystem with SymbolPrinter; |

#### Output

B B B B B A

X X A

It is possible to inherit more than one L-system. Their features are overridden in appropriate order.

#### Input

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | lsystem BaseLsystemX { set symbols axiom = A; set iterations = 5; rewrite A to X A; } lsystem BaseLsystemY { rewrite A to Y A; } lsystem DerivedLsystem extends BaseLsystemX, BaseLsystemY { set iterations = 2; } process DerivedLsystem with SymbolPrinter; |

#### Output

Y Y A

## Abstract L-systems

Only difference between abstract and normal (non-abstract) L-system is in processing with `all`

keyword. Abstract L-systems are not processed by process statement with `all`

keyword but non-abstract are. Abstract L-systems are designed for creating base (ancestor) L-systems in L-system inheritance.

#### Input

1 2 3 4 5 6 7 8 9 10 11 12 | abstract lsystem AbstarctLsystem { set symbols axiom = A; set iterations = 5; rewrite A to B A; } lsystem DerivedLsystem extends AbstarctLsystem { set iterations = 2; rewrite A to X A; } process all with SymbolPrinter; |

#### Output

X X A

## Formal grammar

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | lsystem_def = 'abstract'? 'lsystem' ID ('(' params_list? ')')? baseLsystems? '{' lsystem_statement* '}' params_list = ID ('=' expression)? (',' params_list)? baseLsystems = 'extends' baseLsystemsList baseLsystemsList = ID ('(' expression (',' expression)+ ')')? baseLsystemsList? lsystem_statement = | empty_statement | constant_def | function_def | component_property_assign | symbols_interpretation_def | rewrite_rule |

For formal grammar for L-system statements see constant definition, function definition, component property assign definition, symbol interpretation definition, and rewrite rule documentation pages.