Matlab Grammar
statements = statements (statements)*
statement = declare | assign | expr
clear = 'clear' id';'
declare = 'global' id ';'
assign = var '=' ( list | string | expr ) ';'
var = id('.'id)* | id '(' expr (',' expr)* ')'
literal = integer | float
list = '[' expr (',' expr)* ']'
expr = add_expr
add_expr = mul_expr (('+'|'-') mul_expr )*
mul_expr = primary (('*'|'/') primary )*
primary = '(' expr ')' | var | list | literal | '-' primary
Token definition
string = '[char]*'
integer = [0:9]
float = ...
Operator Precedence
You can build expressions that use any combination of arithmetic, relational, and logical operators. Precedence levels determine the order in which MATLAB® evaluates an expression. Within each precedence level, operators have equal precedence and are evaluated from left to right. The precedence rules for MATLAB operators are shown in this list, ordered from highest precedence level to lowest precedence level:
- Parentheses ()
- Transpose (.'), power (.^), complex conjugate transpose ('), matrix power (^)
- Unary plus (+), unary minus (-), logical negation (~)
- Multiplication (.*), right division (./), left division (.\), matrix multiplication (*), matrix right division (/), matrix left division (\)
- Addition (+), subtraction (-)
- Colon operator (:)
- Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=)
- Element-wise AND (&)
- Element-wise OR (|)
- Short-circuit AND (&&)
- Short-circuit OR (||)
Associativity of operators
- power (.^) is left associative in Matlab