Skip to content
apfohl edited this page Nov 24, 2014 · 3 revisions

Language

Define float variable

f = 1;
f = 1.;
f = .1;
f = 1.123;

Define a vector

v = [1, 2, 3];
v = [1 + 1, f, a + b];

Multiply vector with scalar

w = 4 * [1, 2, 3];

Add/Sub two vectors

u = [1, 2] + [4, 6];
u = [1, 2] - [4, 6];

Add/Sub/Mult/Div scalars

s = 1 + 3 / 4 - 7 * 12.6;

Precedence

p = (1 + 2) * 3;

Syntax

Lexer

[a-zA-Z][a-zA-Z0-9]* return IDENTIFIER;
[0-9]+(\.[0-9]+)?    return NUMBER;
[ \t\n]+             ;
"["                  return LBRACKET;
"]"                  return RBRACKET;
"("                  return LPAREN;
")"                  return RPAREN;
","                  return COMMA;
";"                  return SEMIC;
"="                  return EQ;
"+"                  return ADD;
"-"                  return SUB;
"*"                  return MULT;
"/"                  return DIV;

Parser

translation_unit             := declaration_sequence
declaration_sequence         := declaration declaration_sequence | declaration

declaration                  := IDENTIFIER EQ expression SEMIC
vector                       := LBRACKET components RBRACKET
components                   := (atomic_expression COMMA components) | atomic_expression

expression                   := additive_expression
additive_expression          := addition | multiplicative_expression
addition                     := (additive_expression ADD multiplicative_expression) | (additive_expression SUB multiplicative_expression)
multiplicative_expression    := multiplication | negation
multiplication               := (multiplicative_expression MULT negation) | (multiplicative_expression DIV negation)
negation                     := (SUB negation) | primary_expression
primary_expression           := (LPAREN atomic_expression RPAREN) | atomic
atomic                       := IDENTIFIER | NUMBER | vector