Permalink
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (79 sloc) 3.57 KB
# base.metagrammar
# Base syntax for Modsplan grammars
# (This is documentation only, not read by Modsplan compiler.)
# Modsplan grammar is a BNF variant.
#
# Items of a production may be:
# a literal (in quotes)
# a nonterminal (lowercase identifier)
#
# Items may be suffixed with a quantifier character to indicate repetition:
# '*' = 0 or more
# '+' = 1 or more
# '?' = 0 or 1
#
# A separator character (usually ',') may occur immediately before a quantifier.
# This indicates that repetitions are separated by that character.
#
# Alternates must be spelled out with a separate production.
# This is a reminder that additional alternates may appear in imported files.
#
# A space may appear only as noted; extra spaces are ignored.
#
# (See metagrammar.metagrammar for the syntax of metagrammars.)
grammar => line*
line => statement? comment? '\n' # '\n' represents a newline (end-of-line marker)
comment => "#" P* # if not at start of line, must be preceded by a space
# P* is a string of printable chars (see charclass below)
statement => enable
statement => import
statement => production
enable => 'enable' option # space required after 'enable'
option => identifier
identifier => L+ # one or more lowercase letters (see charclass below)
import => 'use' filename,+ # one or more filenames, separated by ", ";
# space required after 'use'
filename => identifier # no extension, assumes same extension as current file
production => nonterminal flag* '=>' alternate # space required before & after '=>'
nonterminal => nonterm # "nonterminal" on left side only; "nonterm" may be on right
# (nonterminal is extended in tokens.metagrammar)
nonterm => identifier
flag => '.' identifier # no spaces between nonterminal and flags
alternate => word+ # spaces must separate adjacent words
word => item repeater? # no space between item and repeater
repeater => separator? quantifier # no space between separator and quantifier
# (separator used to separate repeated items)
separator => ','
separator => '.'
separator => ';'
separator => ':'
separator => '/'
separator => '|'
separator => '\'
separator => '&'
separator => '-'
separator => '='
quantifier => '*' # zero or more
quantifier => '+' # one or more
quantifier => '?' # zero or one
item => nonterm
item => literal
literal => '"' P* '"' # a quoted string of printable characters
literal => "'" P* "'" # (P is a character class, see below)
# In token specifications (and metagrammars), an item may be a character class,
# represented by a single uppercase letter.
# (See tokens.metagrammar, metagrammar.metagrammar)
charclass => 'U' # any upper case letter
charclass => 'L' # any lower case letter
charclass => 'D' # any digit
charclass => 'P' # any printable characters, must be followed by terminal or end of line
# P must be used with '*'
# (a space is considered a printable character)
# In syntax specifications, an item may be a tokenname,
# represented by an uppercase letter followed by uppercase letters or underscores.
# Token names are defined in a token specification.
# (See syntax.metagrammar, tokens.metagrammar)
tokenname => U upper+ # must have more than one character
# (single uppercase letter reserved for character classes)
upper => U
upper => '_'