Closed jimin-kiim closed 1 year ago
Syntax
: the form of structure of the expressions, statements and program unitsSemantics
: the meaning of the expressions, statements and program units$Syntax$ : while(bool_expr) statement $Semantics$ : "when the current value of the Boolean expression is true, the embedded statement is executed. If the Boolean expression if false, control transfers to the statement following the while construct"
language
: a set of sentencessentence
: a string of characters over some alphabetlexeme
: the lowest level syntactic unit of a languagetoken
: a category of lexemessentence index = 2 * count + 17;
lexemes index, =, 2, *, count, +, 17, ;
tokens - lexemes identifier - index, count int_literal - 2, 17 equal_sign - = mult_op - * plus_op - + semicolon - ;
CFG
(Context-Free Grammars)terminals
: lexemes and tokensabstractions
(syntactic variables, nonterminal symbols or nonterminals)
LHS
(Left Hand Side) : the left side of the arrow where the abstraction is definedRHS
(Right Hand Side) : the right side of the arrow where the string of terminals and/or nonterminals is placed. An abstraction can have more than one RHSgrammar
: a collection of rulesderivation
: a sequence of rule applications, a repeated application of rules
start symbol
: a special nonterminal of grammar where any sentences of a language beginsentential form
: every string of symbols in a derivationsentence
: a sentential from that has only terminal symbols (end result of derivation)a left[right]most derivation
: expanding the left[right]most nonterminal in each sentential formparse tree
: a hierarchical representation of a derivation
Grammar
<if_stmt> → if (<expression>) <statement> [else <statement>]
for
Syntax
<assign> -> <var> = <expr>
Semantics
describe the meaning of a statement or program by specifying the effects of running it on a machine. The effects on the machine are viewed as the sequence of changes in its state
writing a small test program to determine the meaning of some programming language construct, often while learning the language is using kind of operational semantics to determine the meaning of the construct.
the change in the state of the machine defines the meaning of the statement
depend on programming languages of lower levels, not mathematics
to use operational semantics for a high-level language, a virtual machine is needed
two different levels of uses of operational semantics
most rigorous and most widely known formal method for describing the meaning of programs
based on recursive function theory
mathematical objects denote the meaning of their corresponding syntactic entities.
the process of building a denotational specification for a language : defining a mathematical object for each language entity and a function that maps instances of the language entities onto instances of the corresponding mathematical objects
syntactic domain : domain, semantic domain : range
the meaning of language constructs are defined by only the values of the program's variables
the state of a program is the values of all its current variables
let VARMAP be a function that when given a variable name and a state, returns the current value of the variable
since it's complex, it is of little use to language users
provides an excellent way to describe a language precisely
based on formal logic (predicate calculus)
original purpose : formal program verification ( to prove the correctness of programs)
Axioms and inference rules are defined for each statement type in the language to allow transformations of logic expressions into more formal logic expressions
assertions
: logic expressions
precondition
: an assertion before a statement that states the relationships and constraints among variables that are true at that point in execution
postcondition
: an assertion following a statement
a weakest precondition
: the least restrictive precondition that will guarantee the postcondition
inference rule
: a method of inferring the truth of one assertion on the basis of the values of our assertions. If S1, S2, S3, ..., Sn are all true then the truth of S can be inferred.
antecedent
: the top part of an inference ruleconsequent
: the bottom part of an inference rule
{P} statement {Q}
axiom : a logical statement that is assumed to be true.
a = b + 1 (a > 1) one possible precondition : b > 10 weakest precondition : b > 0
sum = 2 * x + 1 (sum > 1) one possible precondition : x > 10 weakest precondition : x > 0
weakest precondition P is defined by the axiom which means that P is computed as Q with all instances of x replaced by E.