Chapter 1 Flashcards
(37 cards)
Natural Languages
Languages that people speak (like English) which are not designed by people but evolved naturally
Formal Languages
Languages that are designed by people for specific applications (like music score or programming languages)
For which application did people design programming languages as a formal language?
To express computations
How are formal languages’ syntax rules like?
They have strict syntax rules that govern the structure of statements. For eg - 3 + 3 = 6 has a correct syntax in Math but 3+ =5–$8 hasn’t.
Syntax Rule Flavors - how many and what are they?
Two, tokens and structure
What are tokens in a formal language?
Basic elements of the language, such as words, numbers and chemical elements (for chemistry). For eg, + is a token in Maths and Fe is a token in chemistry (for iron).
Token syntax rule in a formal language
Have to contain only valid tokens in a statement. For example, $ is not a valid token in Maths, but + is.
Structure syntax rule in a formal language
Tokens has to be combined in a correct way. For eg - 3 + / 3 is incorrect because although + and / are correct tokens in Maths, they can’t be immediately after one another.
Parsing
A process of analyzing a string of symbols, either in natural or formal languages, conforming to the rules of a formal grammar of the language by breaking it into parts
Difference between natural and formal language: Ambiguity
Natural -> Full of ambiguity, people deal with this by using contextual clues and other info
Formal -> Nearly or completely unambiguous, any statements has exactly one meaning regardless of context
Difference between natural and formal language: Redundancy
Natural -> Lots of redundancy and verbose because of ambiguity and to reduce misunderstandings
Formal -> Less redundant and more concise
Difference between natural and formal language: Literalness
Natural -> Full of idiom and metaphor, for eg - under the weather
Formal -> Mean exactly what they say
How can a computer program be understood and why?
Because the meaning of a computer program is unambiguous and literal, it can be understood entirely by analysis of the tokens and structure.
Difference between natural and formal language: Errors
Small errors in spelling and punctuation, which can be ok in a natural language, can make a big difference in a formal language.
What is a value in a program?
One of the basic things a program works with, like integer 39 or string “Hello”
What are types in a programming language?
A type is a category of values, like type ‘int’ for whole numbers (integers).
What is exponentiation and what is the operator in python?
Raising a number to a power, like 2 to the power of 3 and in python, it is **.
What is a program?
A sequence of instructions that specifies how to perform a computation
Three types of computation
Mathematical, Symbolic and Graphical
Example of Symbolic Computation
Searching and replacing text in a document
Basic instructions of programming languages
Input, Output, Math, Conditional Execution, Repetition
Examples of Input instruction
Get data from the keyboard, a file, the network, or some other device
Examples of output instruction
Display data on the screen, save it in a file, send it over the network, etc.
Examples of Math instruction
Perform basic mathematical operations like addition and multiplication