formal BNF/EBNF grammar specification for Verse?

Dearest Verse wizards!
The docs are great for getting started, but I’m really looking for the formal BNF/EBNF grammar spec for Verse.

Is it available anywhere, also in a work in progress form?

Why do I want it?

Clarity: A detailed grammar helps us nail down syntax rules.

  • Tooling: We can build cool stuff like syntax highlighters, parsers and more, making Verse coding smoother.

  • Learning: It’s a huge help for anyone teaching or learning Verse, making the language mechanics clearer.

  • Community: With a solid grammar, we can contribute more—whether it’s tutorials, resources, or code improvements.

So, any chance you could share or point us to the formal grammar spec for Verse? It’d be a massive help for all of us pushing the limits with UEFN and Verse.

THANK YOU!

1 Like

Hi.
As far as I know, This is the only article that mentions BNF

1 Like

Thank you for the link!

Looks like more months of guesswork and brute force debugging are ahead :smiley: may we have the power and resilience to push through - hahaha

1 Like

Update: since I seem to have little respect for my free time, I decided to go about it anyway while we wait for an official and complete one:

here’s super preliminary attempt: sharing it here in case it helps :

(* Enea's Unofficial EBNF Grammar for Verse - v30*)

(* Terminals *)
identifier = letter, { letter | digit | "_" } ;
integer = digit, { digit } ;
float = integer, ".", integer ;
string = "\"", { character }, "\"" ;

(* Non-Terminals *)
program = { import_statement | class_definition | function_definition | variable_declaration } ;

import_statement = "using", "{", identifier, { ",", identifier }, "}" ;

class_definition = identifier, ":=", "class", [ "<", class_specifier, ">" ], ":", class_body ;
class_specifier = "public" | "private" | "protected" | "internal" | "concrete" | "final" | "persistable" | "unique" ;
class_body = { variable_declaration | function_definition | constructor_definition | block_expression } ;

function_definition = identifier, "(", [ parameter_list ], ")", [ "<", function_specifier, ">" ], ":", type, "=", function_body ;
function_specifier = "suspends" | "transacts" | "decides" | "converges" | "override" ;
parameter_list = parameter, { ",", parameter } ;
parameter = identifier, ":", type ;
type = "void" | "int" | "float" | "string" | "bool" | "array", "<", type, ">" | "map", "<", type, ",", type, ">" | identifier ;

variable_declaration = ["var"], identifier, ":", type, ["=", expression] ;

constructor_definition = identifier, "(", [ parameter_list ], "):", class_body ;

block_expression = "block", ":", { statement } ;

statement = variable_declaration | assignment | function_call | if_statement | loop_statement | defer_statement | await_statement ;

assignment = identifier, "=", expression ;
function_call = identifier, "(", [ argument_list ], ")" ;
argument_list = expression, { ",", expression } ;

if_statement = "if", "(", expression, ")", block_expression ;
loop_statement = "loop", ":", block_expression ;
defer_statement = "defer", ":", block_expression ;
await_statement = "await", "(", expression, ")" ;

expression = literal | identifier | function_call | binary_expression | unary_expression ;
literal = integer | float | string | "true" | "false" ;
binary_expression = expression, binary_operator, expression ;
unary_expression = unary_operator, expression ;
binary_operator = "+" | "-" | "*" | "/" | "=" | "<>" | "<" | ">" | "<=" | ">=" ;
unary_operator = "-" | "not" ;

(* Comments *)
comment = "#", { character } ;
1 Like

Unfortunately, Conan’s answer is still the only one I can confirm here: we have a formal BNF for Verse, but it is not currently publicly available; the only thing that you can refer to is the VS Code extension for the current syntax highlighting. We definitely want this to be made available and we are slowly getting there.

2 Likes

FYI, since I really need it, based on a couple of feedbacks I tried to push it a tad further, sharing it here in case it can be helpful to others!

Looking forward to the offical one!

# Enea's Very Unofficial EBNF Grammar for Verse - v33

# Basic Symbols
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" |
         "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

# Identifiers
identifier = letter , { letter | digit | "_" } ;

# Types
type = "int" | "float" | "string" | "bool" | "void" | "array" "[" type "]" | "map" "[" type "," type "]" | "option" "{" type "}" | identifier ;

# Literals
integer_literal = digit , { digit } ;
float_literal = digit , { digit } , "." , digit , { digit } ;
string_literal = '"' , { character } , '"' ;
boolean_literal = "true" | "false" ;

# Expressions
expression = or_expression ;
or_expression = and_expression , { "or" , and_expression } ;
and_expression = equality_expression , { "and" , equality_expression } ;
equality_expression = relational_expression , { ( "=" | "<>" ) , relational_expression } ;
relational_expression = additive_expression , { ( "<" | ">" | "<=" | ">=" ) , additive_expression } ;
additive_expression = multiplicative_expression , { ( "+" | "-" ) , multiplicative_expression } ;
multiplicative_expression = unary_expression , { ( "*" | "/" | "%" ) , unary_expression } ;
unary_expression = [ ( "-" | "not" ) ] , primary_expression ;
primary_expression = identifier | integer_literal | float_literal | string_literal | boolean_literal | "(" , expression , ")" ;

# Statements
statement = block | assignment | if_statement | while_statement | for_statement | return_statement | expression_statement ;
block = "{" , { statement } , "}" ;
assignment = identifier , ":=" , expression , ";" ;
if_statement = "if" , "(" , expression , ")" , statement , [ "else" , statement ] ;
while_statement = "while" , "(" , expression , ")" , statement ;
for_statement = "for" , "(" , [ assignment ] , [ expression ] , ";" , [ assignment ] , ")" , statement ;
return_statement = "return" , [ expression ] , ";" ;
expression_statement = expression , ";" ;

# Declarations
declaration = class_declaration | function_declaration | variable_declaration ;
class_declaration = "class" , identifier , [ "(" , identifier , ")" ] , "{" , { class_member } , "}" ;
class_member = variable_declaration | function_declaration ;
function_declaration = identifier , "(" , [ parameter_list ] , ")" , [ "<" , "suspends" , ">" ] , ":" , type , "=" , block ;
parameter_list = parameter , { "," , parameter } ;
parameter = identifier , ":" , type ;
variable_declaration = "var" , identifier , ":" , type , [ ":=" , expression ] , ";" ;

# Programs
program = { declaration } ;

# Top-level rule
verse_program = { import_statement } , program ;
import_statement = "using" , "{" , string_literal , "}" , ";" ;
1 Like

Hi @enealefons :

While a little bit obscured, the Verse parser is now technically part of the UnrealEngine GitHub repository, which parses the Verse EBNF. You can see the various rules for the EBNF grammar within the comments in the file.

Refer to: https://github.com/EpicGames/UnrealEngine/blob/ue5-main/Engine/Source/Runtime/VerseCompiler/Public/uLang/Parser/VerseGrammar.h

2 Likes

! ! ! ! ! ! A M A Z I N G ! ! ! ! ! !
thank you SO MUCH @sonictke , this really helps! BUT… I get error 404 :smiley:
I’ll keep on looking

@enealefons the page works fine for me


I believe you need to follow the instructions here https://www.unrealengine.com/en-US/ue-on-github to be added

2 Likes

thank you @Mineblo , I reconnected my account to Github and now I’m in!
@sonictke thank you so much for the tip, I’m trying to reverse engineer in order to extract the rules I was missing… interesting task :smiley:

2 Likes