Skip to content

Notation

NameMath notationPlain textOther namesOther notations
AlphabetΣ\Sigma
Empty stringε\varepsilon""
Empty language\emptysetset: {}\{\}, Br: ϕ\phi
Trivial languageϵ\epsilonset: {ε}\{\varepsilon\}, RE: ϵ\epsilon, Br: λ\lambda
Singleton language{a}\{a\}RE: aa
SymbolXXXVariable, Non-terminal
Tokenaa"a"Letter, Terminal
RuleSS \rightarrow \ldotsS -> ...Language equationBNF: S := ..., PEG: S <- ...
ConcatenationXYXYX Ysequence, cartesian p.XYX \cdot Y, Might: XYX \circ Y, set: X×YX \times Y
Unordered choiceXYX \vert YX|Yunion, disjunctionRE: X+YX+Y, set: XYX \cup Y
Kleene starXX^\astX*Kleene closureMight: XX \star
Kleene plusX+XXX \cdot X^*, X{1,}
OptionalX?XϵX \vert \epsilon, X{0,1}
QuantifierX{n,m}, X{n,}, X{n}
Any characterΣ\Sigma.
IntersectionXYX \cap YconjuctionBr: X&YX \& Y
NegationXX^\primeabsolute complementset: ΣX\Sigma^* \setminus X, !X!X, LcL^c
Positive lookahead(&X)Y(\&X) Y&X Y
Negative lookahead(!X)Y(!X) Y!X Y
Range[a-z]
Set of charactersabca \vert b \vert c[abc]set: {a,b,c}\{a, b, c\}
Negation of setΣ(ab)\Sigma \setminus (a \vert b)[^ab]
Escape sequences"\n"
Ordered choiceX/YX / YX / Y
End of file!.

Examples

There are a lot of different formalisms about languges and they all use slightly different notations, but in the end it’s the same thing.

Regular Expressions

Regular expressions doesn’t use symbols and rules to define language. There is only one rule - regular expression. Classical regular expressions use only tokens, concatenation, unordered choice and Kleene star. Also in science papers they don’t bother to put quotes around letters - this way notation is more terse.

For example

RELanguage
ϵ\epsilon{""}
aa{"a"}
abab{"ab"}
aba \vert b{"a", "b"}
aa^*{"", "a", "aa", ...}
(ab)c(a \vert b)c{"ac", "bc"}

Regular Expressions Extended

Same as classical regular expressions, but also adds intersection and negation (which makes it full set of Boolean operations). Those two operations doesn’t add to calculation power (still can produce only regular languages).

See: Janusz A. Brzozowski. 1964. Derivatives of Regular Expressions. J. ACM 11, 4 (Oct. 1964), 481–494. https://doi.org/10.1145/321239.321249

Modern regular expressions

Modern regular expressions add some more tricks, like: Kleene plus, Optional, Quantifier, Any character, Range, Set of characters, Negation of set, Escape sequences. Depends on the flavor (implementation). Those, again, doesn’t add to computational power, but they are quite convenient.

Chomsky generative grammar

Chomsky grammar uses: symbols (non-terminals), rules, tokens (terminals), concatenation, unordered choice.

ChomskyLanguage
SϵS \rightarrow \epsilon{""}
SaS \rightarrow a{"a"}
SabS \rightarrow ab{"ab"}
SabS \rightarrow a \vert b{"a", "b"}
SSaϵS \rightarrow Sa \vert \epsilon{"", "a", "aa", ...}
Xab;SXcX \rightarrow a \vert b; S \rightarrow X c{"ac", "bc"}

Becuase "\vert" is unordered choice those are the same rules:

S1S1aϵS2ϵS2aS3ϵS3S3aS_1 \rightarrow S_1 a \vert \epsilon \\ S_2 \rightarrow \epsilon \vert S_2 a \\ S_3 \rightarrow \epsilon \\ S_3 \rightarrow S_3 a

Depending on which restrictions you put on the rules it can genrate: regular, context-free, context-sensitive, recursive enumerable languages. This formalism is used to define Chomsky hierarchy.

Backus–Naur form

BNF is variation of Chomsky grammar which can generate only context-free languages. There are a lot of variations which also add: Kleene plus, Optional, Quantifier, Any character, Range, Set of characters, Negation of set, Escape sequences. Which doesn’t add anything to computational power, but makes it more practical. BNF looks like this

<S> ::= "" | "a"

Parsing Expression Grammars

PEG again can be treated as variation of Chomsky grammar, but instead of unoredered choice it uses ordered chocie and also adds positive lookahead, negative lookahead and any character. PEG can recognize some context-sensitive grammars. PEG looks like this:

AaAb/ϵBbBc/ϵS&(A!b)aB!.A \leftarrow a A b / \epsilon \\ B \leftarrow b B c / \epsilon \\ S \leftarrow \&(A !b) a^\ast B!.

Parsing with Derivatives

PwD adds to classical regular expressions: rules and symbols (which allows to do general recursion). PwD can handle context-free languages. You can express Kleene closure in three ways:

S1SaϵS2aSϵS3aS_1 \rightarrow Sa \vert \epsilon \\ S_2 \rightarrow aS \vert \epsilon \\ S_3 \rightarrow a^* \\

You can as well say that they added Kleene star to Chomsky grammar.

Conjuctive grammar

It adds intersection to Chomsky grammar. It can handle some context-sensitive languages. It looks like this (in original paper they use &\& instead of \cap):

AAaϵCCcϵXaAbϵYbBcϵSXCAYA \rightarrow Aa \vert \epsilon \\ C \rightarrow Cc \vert \epsilon \\ X \rightarrow a A b \vert \epsilon \\ Y \rightarrow b B c \vert \epsilon \\ S \rightarrow XC \cap AY

Boolean grammar

It adds intersection and negationto Chomsky grammar. It can handle some context-sensitive languages.

Interesting: in PwD they added general recursion to classical regular expressions to recieve context-free Chomsky grammar. If we add general recursion to REE we will recieve Boolean grammar.

Regular Expressions with Lookahead

REwLA adds positive and negative lookaheads to classical regular expressions.

Interesting: in PwD they added general recursion to classical regular expressions to recieve context-free Chomsky grammar. If we add general recursion to REwLA we will recieve PEG. And ordered choice can be expressed as A/B=A(!A)BA / B = A \vert (!A)B.

History

There is an interesting story behind how notation changed over time. See this video

From slide 21 of the talk):

  • 1951 Stephen Kleene develops regular expressions to describe McCulloch-Pitts (1943) nerve nets (uses for choice; considers postfix , but decides to make it a binary operator to avoid having empty strings: x∗y means any number of copies of x, followed by y).
  • 1956 Journal publication of Kleene’s technical report: binary only.
  • 1958 Copi, Elgot, and Wright formulate REs using · and and postfix .
  • 1962 Janusz Brzozowki uses binary + for and introduces postfix +.
  • 1968 Ken Thompson’s paper “Regular Expression Search Algorithm” uses |.
  • 1973 Thompson creates grep from ed editor for use by Doug McIlroy.
  • 1975 Alfred Aho creates egrep (includes ( ), |, *, +, ?).
  • 1978 CMU Alphard project uses regular expressions with *, +, and #.
  • 1981 CMU FEG and IDL use regular expressions with *, +, and ?.

Operations concept map

TODO: I need to update it and explain abbreviations.