FLAME  devel
 All Classes Functions Variables Typedefs Enumerations Pages
Lattice file syntax

Overview

The lattice file will contain one or more element definitions and one or more beamline definitions.

An element definition takes the form:

<instance_name> : <element_type>, <key>=<value>, ... ;

For example

dr001 : drift, L=0.1;

A beamline definition is constructed from zero or more element or beamline names.

<instance_name> : LINE = (<element>, ...) ;

For example

line1 : LINE = (dr001, dr001);

Entries in a beamline definition may be expressions using element and beamline names. For example

d1 : drift, L=1;
d2 : drift, L=2;
line1 : LINE = (d1, d2, d1);
line2 : LINE = (d1, line1, 2*line1, -line1);

A "USE" statement may be given to select which beamline is expanded and used. If no "USE" statement is given then the last "LINE" is used.

USE : line1;

Variables and Expressions

In addition to element and beamline definitinos, arbitrary variables may be defined. String, scalar and vector floating point values may be assigned to a variable.

var1 = 1.0;
var2 = "hello";
var3 = [1,2,3,4];

Expressions of these types may also be assigned. These expressions may use the values of previously defined variables, as well as operations and functions.

var4 = 1+var1;
var5 = cos(var4);

The full list of valid expressions is given on the Lattice File Expressions page.

Grammar definition

# unquoted word
KEYWORD := [A-Za-z]([A-Za-z0-9_:]*[A-Za-z0-9_])?
# floating point number
NUM := [0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?
# quoted string
STR := ".*"

# comment (ignored)
COMMENT := #.*\n

assignment : KEYWORD '=' expr ';'
element    : KEYWORD ':' KEYWORD properties ';'
line       : KEYWORD ':' KEYWORD '=' '(' line_list ')' ';'
func       : KEYWORD '(' expr ')' ';'
command    : KEYWORD ';'

properties :
           | ',' property properties
property : KEYWORD '=' expr

line_list :
          | expr
          | expr ',' line_list

expr : NUM
     | vector
     | STR
     | KEYWORD
     | expr '+' expr
     | expr '-' expr
     | expr '*' expr
     | expr '/' expr
     | '-' expr
     | '(' expr ')'
     | KEYWORD '(' expr ')'

expr_list :
          | expr
          | expr ',' expr_list

vector : '[' expr_list ']'

entry : assignment | element | line | func | command

file :
     | entry file