LCM EBNF Grammar

This section provides information about the Extend Backus-Naur Form (EBNF) grammar for LCM expressions.

Keywords

The reserved keywords of LCM are:

and else false if mod not or pre then true abort action alias
as automaton await begin block by case combine connect delayed do
done each end exit extern final finalize for force freeze from fun
functor goto halt handle in initial inout instance join let loop
macro module next nothing now open out pause procedure direction
run sfc sig signal state step strong struct suspend sustain times
to transition trap type val var weak when while with

Identifiers

LCM identifiers are sequences of letters, digits, "_" (the underscore character), starting with a letter. Letters contain at least the 52 lowercase and uppercase letters from the ASCII set.

Examples:

  • "A", "X1", A_B" are valid identifiers.
  • "1X", "_X", "A B", "A.B" are not identifiers .

However, any string enclosed within $" " is a valid identifier, assuming that a backslash has to be added before a backslash or a double quote.

For instance, $"A.B" and $" this is a valid identifier with a \" double quote" are valid.

Paths

A path defines the location of an LCM definition (constant, function, block or type) inside the module hierarchy.

For instance, the path "A" refers to the definition "A" in the current or parent module.

The path "A@B@C" refers to the definition "C" of the module "B" which is inside the module "A"

Grammar


  • {} stands for repetition
  • [] stands for option
path    
| ident {"@" ident}   my_module@my_block
Access expression  
"." "(" INT ")" tuple access S.(1)
| "." ident structure access S.a
| "." "[" INT { "," INT } "]" array element access S.[3,5]
Access expression  
"." "(" INT ")" tuple access S.(1)
| "." ident structure access S.a
| "." "[" INT { "," INT } "]" array element access S.[3,5]
expr expression  
literal    
| path  
| expr access    
| "(" expr [ ":" path ] ")" type constraint (1:int32)
  parenthesis in expressions (2*(3+1))
| path expr function call f(2,3)
    g 2
    M@f{a=2;b=3}
| "if" expr "then" expr "else" expr    
| expr binary_op expr    
| unary_op expr    
| "?" ident signal status: present or absent ? A
| "pre" ident signal status and value at previous cycle pre A
| "?" [ "(" ] "pre" ident [ ")" ] signal status at previous cycle  
| "(" expr { "," expr } ")" tuple constructor ( A and not B, A or B)
| "{" ident "=" { ";" ident "=" expr } "}" record constructor {a=32; b= 42;c=52}
expr expression  
literal    
| path  
| expr access    
| "(" expr [ ":" path ] ")" type constraint (1:int32)
  parenthesis in expressions (2*(3+1))
| path expr function call f(2,3)
    g 2
    M@f{a=2;b=3}
| "if" expr "then" expr "else" expr    
| expr binary_op expr    
| unary_op expr    
| "?" ident signal status: present or absent ? A
| "pre" ident signal status and value at previous cycle pre A
| "?" [ "(" ] "pre" ident [ ")" ] signal status at previous cycle  
| "(" expr { "," expr } ")" tuple constructor ( A and not B, A or B)
| "{" ident "=" { ";" ident "=" expr } "}" record constructor {a=32; b= 42;c=52}
| "[" expr { ";" expr } "]" element wise array constructor [[1;2];[3;4];[5;6]]
| expr "^" "[" INT { "," INT } "]" short cut for array constructor false^[4,5]