Difference between the language grammar and language syntax

@ftomassetti in your article EBNF: How to Describe the Grammar of a Language the metalanguage is used to define a new grammar.

In Augmented BNF for Syntax Specifications: ABNF the metalanguage is used to define a new syntax.

My concern is if both are used for the same purpose and if grammar and syntax are synonyms.


From my point of view, yes, grammar and syntax are the same thing, but I am not a good theorist and I tend to be very pragmatic regarding these things.

1 Like

Thanks, the same is with me but let’s wait for other opinions. Sometimes you could have a good idea but wording decides - especially while publishing.

The grammar defines the syntax, so for all intents and purposes you can use them interchangeably when you are developing a language.

The distinction becomes relevant when making a grammar for an existing language that you don’t have a grammar for. Then you want to accept a given syntax, but different grammars can be written for the same syntax, with different qualitative aspects.

Also when different grammars exist for the same syntax and you end up comparing them the distinction is relevant.

I would imagine @grammarware (Vadim Zaytsev) might have more to say.

1 Like

Thanks, @jurgen.vinju. My concern is if a language without grammar may exist at all. My point is that the grammar rules may be ambiguous or not formally defined, but each language must have some grammar. Do you agree?

Languages without grammars certainly exist. For each known class of grammars there exist languages which are not definable by grammars of that class. E.g.

  1. a language of the form n-times ‘a’ followed by n-times ‘b’ for all n = 1,2,… , i.e. a^n b^n has a context-free grammar but does not have a regular (finite automata) grammar.
  2. a language a^n b^n c^n for n = 1,2,… does not have a context free grammar but has a context-sensitive grammar,
  3. a language that consistys of all theorems of Peano arithmetics does not have a grammar at all, i.e. there is no algorithm which could decide that a given string of ASCII characters belongs to this language.
1 Like