I am trying to understand what BNF, metalanguage, and metasyntax are.

From https://proofwiki.org/wiki/Definition:Metalanguage

A metalanguage of a formal language is a formal language used to specify the formal language (make statements about the formal language).

The object language of a metalanguage is the language described by that metalanguage.

  1. From https://proofwiki.org/wiki/Definition:Syntax

    The syntax of a formal language is its structure, and is specified by a formal grammar of the formal language.

    So I wonder if a formal grammar of a formal language is a metalanguage of the formal language?

  2. From https://proofwiki.org/wiki/Definition:Metalanguage/Metasyntax

    The syntax of a metalanguage is called a metasyntax of the object language of that metalanguage.

    From http://en.wikipedia.org/wiki/Extended_Backus–Naur_Form

    Extended Backus–Naur Form (EBNF) is a family of metasyntax notations, any of which can be used to express a context-free grammar.

    Does it mean that a context-free grammar is a metalanguage of a context-free language, and EBNF is a syntax for the context-free grammar as a metalanguage, and therefore EBNF is a metasyntax for the context-free language as a object language?

  3. From http://en.wikipedia.org/wiki/Metasyntax

    A metasyntax 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.

    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).

    Does it mean that EBNF is a metalanguage of a formal language, and this formal language is a context-free grammar?

Thanks and regards!


1 Answer 1


In general, informally, a metalanguage is a language used to talk about a language, possibly to specify it or to study its properties.

For example, linguists use English to describe the English language. As a consequence English is used as its own metalanguage. To avoid confusion, various quoting system are used to distinguish the two level. For example, when talking about a small animal that barks, we use the word "dog". Here, "dog" represent a word of a language being talked about, not any of the possible meanings of that word in the language it belongs to. It cannot bite.

When a language A is used as metalanguage to talk about a language B, B is called the object language. But, though sometimes used in a formal way, this is very similar to saying that wheather is the object of many conversations.

In computer science, a well known example is the programming language ML. The name ML actually stand for metalanguage. ML was initially conceived by Robin Milner as a metalanguage to develop proofs about a small language called pplambda in the LCF theorem prover. Hence, both syntactic and semantic properties of pplambda can be expressed in ML.

Another well known example is Lisp, a language that is its own meta language, and has been the first programming language to have that property. Lisp programs can be syntactically represented as a Lisp data structure. The semantics of Lisp is also expressed in Lisp, since the first Lisp interpreter was written in Lisp.

This works so well that the feat has since be often repeated for many other programming languages, and it is very customary to write the first compiler of a language in the language itself, as part of a language bootstrapping process. Hence the language is self compiling. This requires defining both the syntax and the semantics of the language in itself.

So, in effect, most programming languages are, or can be, a metalanguage for themselves, and for other programming languages. That is actually the least one can expect from languages that often claim to have Turing power.

The concept of metalanguage often concerns a conplete object language, whether natural language or programming language, with syntax and semantics. But it can also concern languages in the formal language sense, which are only syntax. A mathematical formalism used to describe (a family of) formal languages (regular sets, context-free, recursively enumerable, ...) is a metalanguage for this formal language.

This is more interesting when the syntax of the metalanguage belongs to the same language family as the formal languages it describes. The best known example is the BNF language (Backus-Naur Form), and its later EBNF variant. It is a language used to write context-free (CF) grammars, thus to define purely syntactic languages. Its own syntax is context-free, hence describable in BNF. Hence BNF can be syntactically its own metalanguage, but not semantically. But then, BNF describes only CF languages and has no claim for Turing power.

It is to be noted that BNF has a CF syntax, but it also has semantics. The semantics of a BNF program is precisely a CF grammar and the formal language it defines, to which the BNF program associates no semantics. A context-free grammar just defines a formal language, and no semantics is associated. Hence it is wrong to consider that BNF is a CF grammar. BNF has a CF grammar which defines its syntax.

Answering your questions

Regarding the two preliminary quotes. They are expressed in the context of formal systems, and "formal" means mathematically defined, which may include both syntax and semantics for the language. It does not contradict the above discussion, but rather confirms it.

  1. A formal grammar of a formal language is not a metalanguage of the formal language. The mathematical formalism used to write the grammar is in this case the metalanguage.

    The quote goes into an issue that I did not address here, that of the structure that a syntax definition can attach to the strings of a formal language. It is, as far as I see, quite unrelated to the concept of metalanguage, when we talk of formal languages in the formal language theory sense. Two different syntactic definitions can produce the same language, when considering only the string it defines for the language. But these definitions implicitly associate diffrerent structures with the string (such as parse-trees in the context-free case) and that can be important.

    When the formal language is actually the syntax of a complete language that also has semantics, the structure is important as it is usually organizing the definition of the semantics, which is the purpose of many metalanguages.

  2. As written above, a context-free grammar cannot be a metalanguage since it has no semantics. The formalism used to write the CF grammar is a metalanguage for the purely syntactic formal language defined by this CF grammar. EBNF is a language with both syntax and semantics. A program (or whatever you want to call it: text, description, grammar, ...) written in EBNF is a text using the syntax of EBNF. This text has a meaning, defined by the semantics of EBNF, which is the CF grammar it describes. EBNF is not a metasyntax, but a meta language for syntax.

    This calls for more precision. I consider that the word metasyntax is just shorthand for the expression "syntax of [a/the] metalanguage". I do not ses what other meaning it could have.

    The first quote is just nonsense to me. The second quote is poorly phrased and should rather be (if I understand the intent):

    Extended Backus-Naur Form (EBNF) is a family of metalanguages for defining syntax, any of which can be used to express a context-free grammar.

  3. The quote (out of its context) is in agreement with what I said so far. The expression "formal metalanguage" is not to be understood as formal language in the formal language theory sense, but as a language with a formally, i.e., mathematically, defined syntax and semantics.

    This quote alone just say that EBNF is a widely used metalanguage for computer languages, but without being more precise about it. Actually, according to me, EBNF is a metalanguage for (more than one) formal languages in the formal language theory sense, since it can only talk about the syntax, and pure syntax without semantics may be seen as such a formal language. But these formal languages are those described by the grammars expressed in EBNF. A grammar itself is not a language, but it may be part of a language seen as a global object of study, since it can describe its syntax.

I hope this clarifies things.

  • $\begingroup$ Thanks, babou! I am still trying to understand. Do you have clear references about metalanguages, metasyntax, ...? $\endgroup$
    – Tim
    Jul 12, 2014 at 23:20
  • $\begingroup$ No, I do not have any specific reference. It is mostly knowledge I collected over time, as I often had to use the concept in various technical areas. Many people will call EBNF metasyntax, because it seems to look like metalanguage for describing full languages with syntax and semantics. But that is only loose talk. You were asking for precision. But your comments are welcome, especially if you think I may have been inconsistent. $\endgroup$
    – babou
    Jul 12, 2014 at 23:29
  • $\begingroup$ By " conplete object language", do you mean non-formal language? $\endgroup$
    – Tim
    Jul 12, 2014 at 23:49
  • $\begingroup$ @Tim Yes, I mean non-formal, i.e. not a formal language in the sense of formal language theory, having also semantics. One other thing I should have said is that, since a metalanguage is supposed to provide the means to talk about something, namely another language, it must necessarily have semantics. Only formal language theory has languages that are pure syntax. $\endgroup$
    – babou
    Jul 13, 2014 at 0:00
  • $\begingroup$ Thanks. (1) By "the structure that a syntax definition can attach to the strings of a formal language", do you mean a syntax attach some structures to the strings of a formal language, and a formal language without a syntax has no those structures? (2) What are the structures that a syntax can bring, e.g. "parse-trees in the context-free case"? (3) By "Two different syntactic definitions can produce the same language, when considering only the string it defines for the language", do you mean that a formal language can have multiple different syntaxes? $\endgroup$
    – Tim
    Jul 13, 2014 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.