AQA A2 Computing - 1.6 Regular Expressions, BNF and RPN Flashcards
Natural Language
Comprises of a set of rules and governed by rules which define the order in which words may be put together to craete speech. These rules define the grammar or syntax of the language.
Formal Language
Defined using two components: its alphabet and its rules of syntax. For example, a formal language is used to describe the hardness of lead in pencils.
Regular Language
Any language that a Finite State Machine will accept.
Metalanguage
A metalaguage is a language used to describe a real language.
Real Language
A real language is consists of strings of characters chosen from some set or alphabet of characters.
Regular Expression
A notation for defining all the valid strings of a formal language or a special text string for describing a search pattern.
Regular Expressions: Alternation (bed?ban)
A vertical bar ? is used to separate alternatives. For example bed?ban is used to match strings bed and ban.
Regular Expressions: Character Class (b[ae]d)
An alternative way of representing alternation. B[ae]d matched bad and bed because [] encloses a list of alternative characters. Particularly useful for ranges of characters. E.g. [a-z] for all lower case characters, or [A-Za-z] for all upper and lowercase characters.
Regular Expressions: Grouping (gr(a?e)y)
Round brackets are used to define the scope and prescedence of the operators, among other uses. E.g. gray?grey and gr(a?e)y are equivalent patterns describing the set containing grey and gray.
Regular Expressions: Negation (n^t)
This will match any character that is not in the character class. N.B This does NOT meat ‘an n not followed by a t’. It means ‘an n followed by a character that is not a t’
Regular Expressions: Quatification “?”
Indicates that there is zero or one of the preceeding element. E.g. colou?r matches color and colour
Regular Expressions: Quatification “*”
Indicates that there are zero or more of the preceeding element. E.g. ab*c matches ac, abc, abbc, abbbc and so on
Regular Expressions: Quatification “+”
Indicates that there are zero or more of the preceeding element. E.g. ab+c matches abc, abbc, abbbc and so on but NOT ac
Backus-Naur form (BNF)
a notation for expressing the rules for constructing valid strings in a regular language
Syntax
The rules by which words and symbols are combined to form language structures (expressions, statements etc.)