The Nara programming language specification

This is a WIP specification of the Nara programming language.

Nara is a high level, general purpose programming language. It runs on a Virtual Machine and is garbage collected.

Notation

This document uses EBNF to denotate lexemes and syntax. Uppercase names denote Syntax constructs, whereas lowercase denotes Lexic constructs.

Syntax      = { Production }
Optional    = [ identifier ]
ZeroOrMore  = { number }
OneOrMore   = letter, { letter }
Alternative = Expression | Statement
Literal     = "abc"

The notation a..z represents literals from a to z.

Lexemes - Tokens

As of now, an identifier can only start with lowercase or underscore.

digit     = 0..9
lowercase = a..z
uppercase = A..Z

identifier_char  = "_" | lowercase | uppercase | digit
identifier_start = "_" | lowercase
identifier       = identifier_start, { identifier_char }

The only comment supported is single line, with 2 slashes until EOL.

comment  = "//", any_except_newline

Integer literals support decimal, hexadecimal, octal and binary. Those last 3 must start with a 0 and a letter.

int_literal = decimal_int
            | hex_int
            | octal_int
            | binary_int

digit     = 0..9
binary_digit  = "0" | "1"
octal_digit   = 0..7
hex_digit     = 0..9 | a..f | A..F

binary_int = "0", "b" | "B", binary_digit, { binary_digit }
octal_int  = "0", "o" | "O", octal_digit, { octal_digit }
hex_int    = "0", "x" | "X", hex_digit, { hex_digit }

decimal_int = digit { digit }

Floating point literals require a digit before and after the dot, while scientific notation requires the e and sign.

float_literal = decimal_int, ".", digit, { digit }, [ exponent ]
              | decimal_int, [ exponent ]

exponent      = "e"|"E", "+"|"-", digit, { digit }

Operators don't have any special rules, they are just symbols grouped.

operator_char = "+" | "-" | "=" | "*" | "!" | "/" | "|" | "@" | "#" | "$" 
              | "~" | "%" | "&" | "?" | "<" | ">" | "^" | "." | ":"

operator = operator_char, { operator_char }

Strings are single line only, and don't support interpolation as of now.

quote = '"'
backslash = "\\"
newline = "\n"

invalid_string_char = quote | newline

escape_sequence = backslash, (all_characters - newline)

string_char = (all_characters - invalid_string_char) | escape_sequence

string_literal = quote, { string_char }, quote

Virtual Machine

Settings

Regular