Formal language is a set of formulae under some rules/structure. Formally, a formal language is a subset of all the finite-length words over a given alphabet.
Definition
Formal Language ^definition
Let be a set of symbols (also called letters). is the set of all possible (finite-length) words/formulae (sequences of letters) that can be constructed from . Then, the set is a formal language if:
Any formula that is an element of is well-formed under it.
Examples
Example: Snake Case
In programming, camel case refers to a naming convention for variables, that requires all characters to be lower case, and any spaces are replaced with an underscore (_). For example age
, max_speed
and hello_how_are_you
are all examples of variables named in snake case. Technically, numbers are also allowed, but for the sake of simplicity, let’s only restrict ourselves to the English alphabet. Let’s define it as a formal language.
Our symbol set (alphabet/vocabulary) is:
Then, our formal language, can be:
Here, is defined as a formula/word in and must satisfy the condition that it is any finite permutation of all lowercase letters, plus the underscore for it to be well-formed. Then, can be any of:
abab
_______ab
snake_case
____
Examples (1) and (3) are normal, but (2) and (4), while technically allowed under , aren’t exactly what we mean when we talk about snake case. Let’s have a clear set of rules for a word/formula, to belong in :
- It must start with an English letter (a-z)
- Every underscore must be preceded and succeeded by an English letter i.e. we can only have one underscore between two strings of english letters.
First, we can only look at cases where we want two words, separated with an underscore. Here, we can put two symbols next to each other to concatenate them, not multiply!!
But now we #todo