-
Notifications
You must be signed in to change notification settings - Fork 0
Trailer Syntax
##Note You can use the online diagram generator to experiment with the Trailer syntax. ##Grammar Specification Trailer uses a modified EBNF notation to describe the railroad diagram. This chapter specifies the notation understood by Trailer in detail. ##Terminals and Non-Terminals ###Symbols Symbols, used to denote non-terminals, are arbitrary sequences of uppercase and lowercase letters, digits, and underscores.
symbol = alphanumeric, ( alphanumeric | underscore )+ ;
alphanumeric = ?A..Z? | ?a..z? | ?0..9? ;
underscore = '_' ;
###Strings Strings denote terminals. They are character sequences enclosed by either single, or double quotes.
string = (('"', ?char_sequence?, '"') | ("'", ?char_sequence?, "'")) ;
###Special Sequences A "special sequence" identifies complex terminals (such as sets of characters) which cannot concisely be represented as simple string terminals.
special_sequence = "?", ?char_sequence?, "?" ;
###Null Terminal The null, or empty terminal, is denoted by an underscore character.
empty_term = "_" ;
##Statements A statement consists of the defined symbol, followed by an equal sign, the production rule, and finally a semicolon.
statement = symbol, "=", rule, ";"
###Rules A production rule on the right-hand side of a statement is either a sequence, or a choice.
rule = sequence | choice ;
term = group | symbol | string | empty_term;
###Sequences A sequence is the concatenation of several terminals and/or non-terminals. It is denoted by a comma.
sequence = term, (",", term)* ;
###Choices A choice is a selection of several terminals and/or non-terminals. It is denoted by a vertical bar.
choice = term, ("|", term)* ;
##Groups ###Simple Groups A simple group is a term enclosed in parentheses. This permits the mixing of sequences and choices while maintaining clearly defined operator priorities.
group = simple_group | repetition_group ;
simple_group = "(", rule, ")" ;
###Repetitions
repetition_group = zero_or_many_group | at_least_once_group | zero_or_once_group ;
A repetition group is a term which may occur (a) once or never, (b) at least once, or (c) many times, or not at all
zero_or_once_group = "(", rule, ")?" ;
at_least_once_group = "(", rule, ")+" ;
zero_or_many_group = "(", rule, ")*" ;
##Syntax Diagram To see a syntax diagram of Trailer's EBNF notation, visit the online diagram generator and click on the link "Load Example".