Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Metasyntax
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Allowable structure and composition of phrases and sentences of a metalanguage}} {{More citations needed|date=December 2009}} A '''metasyntax''' is a syntax used to define the syntax of a [[programming language]] or [[formal language]]. It describes the allowable structure and composition of phrases and sentences of a [[metalanguage]], which is used to describe either a [[natural language]] or a computer programming language.<ref>Sellink, Alex, and Chris Verhoef. "[http://ai2-s2-pdfs.s3.amazonaws.com/575f/904555f4b6eb7d89ab84e2f4e4ca677ce17b.pdf Development, assessment, and reengineering of language descriptions]." Software Maintenance and Reengineering, 2000. Proceedings of the Fourth European. IEEE, 2000.</ref> Some of the widely used formal metalanguages for computer languages are [[Backus–Naur form]] (BNF), [[extended Backus–Naur form]] (EBNF), [[Wirth syntax notation]] (WSN), and [[augmented Backus–Naur form]] (ABNF). Metalanguages have their own metasyntax each composed of [[terminal symbol]]s, [[nonterminal symbol]]s, and ''metasymbols''. A terminal symbol, such as a word or a token, is a stand-alone structure in a language being defined. A nonterminal symbol represents a [[syntactic]] category, which defines one or more valid phrasal or sentence structure consisted of an n-element subset. Metasymbols provide syntactic information for denotational purposes in a given metasyntax. Terminals, nonterminals, and metasymbols do not apply across all metalanguages. Typically, the metalanguage for token-level languages (formally called "[[regular language]]s") does not have nonterminals because nesting is not an issue in these regular languages. English, as a metalanguage for describing certain languages, does not contain metasymbols since all explanation could be done using English expression. There are only certain formal metalanguages used for describing recursive languages (formally called [[context-free language]]s) that have terminals, nonterminals, and metasymbols in their metasyntax. ==Element of metasyntax== * Terminals: a stand-alone syntactic structure. Terminals could be denoted by double quoting the name of the terminals. :e.g. {{code|"else"}} , {{code|"if"}}, {{code|"then"}}, {{code|"while"}} * Nonterminals: a symbolic representation defining a set of allowable syntactic structures that is composed of a subset of elements. Nonterminals could be denoted by angle bracketing the name of the nonterminals. :e.g. {{code|<int>}}, {{code|<char>}}, {{code|<boolean>}} * Metasymbol: a symbolic representation denoting syntactic information. :e.g. {{code|:{{=}}}} , {{code|{{!}}}}, {{code|{} }}, {{code|()}}, {{code|[]}}, {{code|*}} ==Methods of phrase termination== * Juxtaposition: e.g. {{code|A B}} * Alternation: e.g. {{code|A{{!}}B}} * Repetition: e.g. {{code|{A B} }} * Optional phrase: e.g. {{code|[A B]}} * Grouping: e.g. {{code|(A{{!}}B)}} ==Specific metasyntax conventions== ===The standard convention=== * '[[Backus–Naur form]]' denotes [[nonterminal symbol]]s by angle bracketing the name of the [[syntactic category]], while it denotes [[terminal symbol]]s by double quoting the terminal words. Terminals can never appear on the left-hand side of the metasymbol {{code|::{{=}}}} in a [[Parse tree|derivation]] rule. The body of the definition on the right-hand side may be composed with several alternative forms with each alternative syntactic construct being separated by the metasymbol {{code|{{!}}}}. Each of these alternative construct may be either terminal or nonterminal. * '[[Extended Backus–Naur form]]' uses all facilities in BNF and introduces two more metasymbols for additional features. One of these two new features is applied to denote an optional phrase in a statement by square bracketing the optional phrase. The second feature is applied to denote a phrase that is to be repeated zero or more times by curly bracketing the phrase. * '[[Wirth syntax notation]]' uses all facilities in EBNF except that the nonterminals are not necessarily angle bracketed but are always defined on the right-hand side of {{code|{{=}}}} in its production rule. It also does not require every nonterminal to be explicitly defined. Nonterminals such as {{code|<text>}} and {{code|<opt-whitespace>}} are implicitly defined as ASCII-character and optional white space respectively. * '[[Augmented Backus–Naur form]]' denotes nonterminal symbols by starting a one-word-name with an alphabet as the name of the syntactic category. Angle brackets are not required. Terminal symbols are either denoted by double quoted words or denoted by the following numeric structure: a {{code|%}}, followed by {{code|b}} or {{code|x}} or {{code|d}}, followed by a numeric value or a ''concatenation of numeric values'' separated by {{code|.}}. Metasymbol {{code|-}} is placed between two numeric values to denote ''value range''. As that of BNF, the terminals of ABNF never occurs on the left-hand-side of the metasymbol {{code|{{=}}}} in the derivation rule. Metasymbol {{code|/}} denotes ''alternations''. White space is used to separate elements in the body of the definition. The metasyntax for ''repetition'' in ABNF has several forms. A {{code|*}} preceding an element denotes the element to be repeated zero or more times. Numeric value {{var|n1}} followed by {{code|*}} followed by numeric value {{var|n2}} followed by an element denotes the element to be repeated at least {{var|n1}} times and at most {{var|n2}} times. A single numeric value {{var|n}} preceding an element denotes the element to be repeated {{var|n}} times. ''Comments'' may be express after metasymbol {{code|;}}. As in EBNF, square bracketing a phrase denotes the phrase to be ''optional''. ===Variations=== The metasyntax convention of these formal metalanguages are not yet formalized. Many metasyntactic variations or extensions exist in the reference manual of various computer programming languages. One variation to the standard convention for denoting nonterminals and terminals is to remove metasymbols such as angle brackets and quotations and apply ''font types'' to the intended words. In [[Ada (programming language)|Ada]], for example, syntactic categories are denoted by applying lower case [[sans-serif font]] on the intended words or symbols. All terminal words or symbols, in Ada, consist of characters of code position between {{mono|16#20#}} and {{mono|16#7E#}} (inclusive). The definition for each character set is referred to the International Standard described by [[ISO/IEC]] 10646:2003. In [[C (programming language)|C]] and [[Java (programming language)|Java]], syntactic categories are denoted using [[italic font]] while terminal symbols are denoted by [[sans-serif|gothic]] font. In [[J (programming language)|J]], its metasyntax does not apply metasymbols to describe J's syntax at all. Rather, all syntactic explanations are done in a metalanguage very similar to English called Dictionary, which is uniquely documented for J. ===Advantage of the extensions=== The purpose of the new extensions is to provide a simpler and unambiguous metasyntax. In terms of simplicity, BNF's metanotation definitely does not help to make the metasyntax easier-to-read as the open-end and close-end metasymbols appear too abundantly. In terms of ambiguity, BNF's metanotation generates unnecessary complexity when quotation marks, apostrophes, less-than signs or greater-than signs come to serve as terminal symbols, which they often do. The extended metasyntax utilizes properties such as case, font, and code position of characters to reduce unnecessary aforementioned complexity. Moreover, some metalanguages use fonted separator categories to incorporate metasyntactic features for layout conventions, which are not formally supported by BNF. ==See also== *[[Adaptive grammar]] *[[Comparison of parser generators]] *[[Metapragmatics]] *[[Metasemantics]] *[[Metavariable (logic)]] ==References== <references /> {{Metasyntax}} [[Category:Metalanguages| ]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Code
(
edit
)
Template:Metasyntax
(
edit
)
Template:Mono
(
edit
)
Template:More citations needed
(
edit
)
Template:Short description
(
edit
)
Template:Var
(
edit
)