A language is a named collection of rules for imposing structure on text.
LanguageDeclaration: Attributesopt language Name LanguageBody LanguageBody: { RuleDeclarationsopt } RuleDeclarations: RuleDeclaration RuleDeclarations RuleDeclaration
The language that follows recognizes the single text value "Hello World"
:
module HelloWorld { language HelloWorld { syntax Main = "Hello World"; } }
A language may consist of any number of rules. The following language recognizes the single text value "Hello World"
:
module HelloWorld { language HelloWorld { syntax Main = Hello Whitespace World; token Hello = "Hello"; token World = "World"; token Whitespace = " "; } }
The three rules Hello, World
, and Whitespace
recognize the three single text values "Hello"
, "World"
, and " "
respectively. The rule Main
combines these three rules in sequence. The difference between syntax and token rules is described in Section 11.1.
Main
is the distinguished start rule for a language. A language recognizes a text value if and only if Main
recognizes a value. Also, the output for Main
is the output for the language.
Rules are members of a language. A language can use rules defined in another language using member access notation. The HelloWorld
language recognizes the single text value "Hello World"
using rules defined in the Words
language:
module HelloWorld { language Words { token Hello = "Hello"; token World = "World"; } language HelloWorld { syntax Main = Words.Hello Whitespace Words.World; token Whitespace = = " "; } }
All rules defined within the same module are accessible in this way. Rules defined in other modules must be exported and imported as defined in the next chapter.