# This grammar file describes the syntax of SSS grammar files. See the SSS specification for more documentation. # A grammar can be a GramComment, a Comment, a Keyword, a Constant, an Identifier, a Bracket, a Square, a Brace, a String, a Number or one of four treatments of a non-terminal, called Exact, Option, Star and Plus. grammar ::= { # A grammar can itself be a comment. Such a grammar accepts only the empty string. GramComment {COMMENT} # A Comment is the keyword "COMMENT". It is a terminal that accepts any SSS comment. Comment {"COMMENT"} # A Word is written as an SSS string, which must lex as a single SSS keyword, SSS punctuation or SSS separator. It is a terminal which accepts only one sentence: the specified keyword. Word {STRING} # A Constant is the keyword "CONSTANT". It is a terminal that accepts any SSS constant. Constant {"CONSTANT"} # An Identifier is analogous to a Constant. Identifier {"IDENTIFIER"} # A Bracket is the keyword "ROUND" followed by a grammar in brackets. It is a terminal which accepts anything in matched round brackets. The grammar in brackets is used to parse the contents of the brackets, but not before the outer sentence has been completely parsed. Round {"ROUND" ROUND(grammar)} # A Square is the keyword "SQUARE" followed by a grammar in brackets. It is a terminal which accepts anything in matched square brackets. Square {"SQUARE" ROUND(grammar)} # A Brace is the keyword "BRACE" followed by a grammar in brackets. It is a terminal which accepts anything in matched braces (curly brackets). Brace {"BRACE" ROUND(grammar)} # A String is the keyword "STRING". It is a terminal which accepts any SSS string. String {"STRING"} # A Number is analogous to a String. Number {"NUMBER"} # A Char is analogous to a String. Char {"CHAR"} # An Exact is a quantified non-terminal which accepts exactly one sentence accepted by the named non-terminal. Exact {IDENTIFIER} # An Option is a quantified non-terminal which accepts zero or one sentence(s) accepted by the named non-terminal. Option {IDENTIFIER "?"} # A Star is a quantified non-terminal which accepts zero or more sentences accepted by the named non-terminal. Star {IDENTIFIER "*"} # A Plus is a quantified non-terminal which accepts one or more sentence(s) accepted by the named non-terminal. Plus {IDENTIFIER "+"} } # A production can be a ProdComment or a Production. production ::= { # A production can itself be a comment. Such a production does not accept any sentence. ProdComment {COMMENT} # A Production consists of an identifying Constant followed by a list of gramars. # Not enforced here: the grammars must not all be GramComments and Options and Stars. Production {CONSTANT BRACE(grammar+)} } # A declaration can be a DecComment, a NonTerminal or a Root. declaration ::= { # A DecComment is just an SSS comment. It does not define anything. DecComment {COMMENT} # A NonTerminal is of the form "name ::= {production ...}". It defines a non-terminal by listing its productions in order from most to least preferred. NonTerminal {IDENTIFIER "::=" BRACE(production+)} # A Root is of the form "ROOT grammar". It defines the outermost grammar, used to parse a whole sentence. Root {"ROOT" grammar} } # The root is a list of declarations. # Not enforced here: each declaration may only mention (except in 'BRACE()') non-terminals defined by earlier NonTerminals. # Not enforced here: there must be exactly one Root declaration. ROOT declaration+