SS (Syntax Semantics)

BAB II
Syntax dan Semantics
Syntax : form or structure of the expression, statement, and program unit.

Semantics : the meaning of expression, statement, and program unit.

Syntax Terminology :
Sentence, string of characters over some alphabet.
Language, a set of sentences.

Definition of Languages
Recognizer : A tool that decides whether a sentence belong to a language.
Generator : A device that generate language, it can check a sentence by comparing it to the structure of the generator

Context-Free grammar(CFG) and Backus-Naur Form(BNF) are Language Generator.

BNF used to represent classes of syntactic structures. They act like syntactic variables

There are two rule, Left-Hand Side (LHS) which are nonterminal and Right-Hand Side (RHS).

Nonterminals are often enclosed in angle brackets.

<ident_list> → identifier | identifier, <ident_list>
<if_stmt> → if <logic_expr> then <stmt>
        ^
nonterminal

Example of Grammar :
<program> ® <stmts>
   <stmts> ® <stmt> | <stmt> ; <stmts>
   <stmt> ® <var> = <expr>
   <var> ® a | b | c | d
   <expr> ® <term> + <term> | <term> - <term>
   <term> ® <var> | const

Example of Derivation :
<program> => <stmts> => <stmt>
                      => <var> = <expr>
                      => a = <expr>
                      => a = <term> + <term>
                      => a = <var> + <term>
                      => a = b + <term>
                      => a = b + const

Every string of symbols in a derivation is a sentential form
sentence is a sentential form that has only terminal symbols
leftmost derivation is one in which the leftmost nonterminal in each sentential form is the one that is expanded

Semantics

There are three kinds of Semantics
·         Operational Semantics
Describe the meaning of a program by executing its statements on a machine, either simulated or actual.  The change in the state of the machine (memory, registers, etc.) defines the meaning of the statement
·         Denotational Semantics
Based on recursive function theory
The most abstract semantics description method
Define a function that maps instances of the language entities onto instances of the corresponding mathematical objects
·         Axiomatic Semantics
Based on formal logic (predicate calculus)
Original purpose: formal program verification
Axioms or inference rules are defined for each statement type in the language (to allow transformations of logic expressions into more formal logic expressions)
The logic expressions are called assertions
Denotation Semantics vs Operational Semantics
          In operational semantics, the state changes are defined by coded algorithms
          In denotational semantics, the state changes are defined by rigorous mathematical functions

 Inti dari materi ini adalah kita mengerti bagaimana caranya sebuah bahasa yang kita gunakan akan mentranslasi bahasa yang kita gunakan seperti (C++, Java, Perl, atau Python) menjadi bahasa yang dapat dimengerti komputer, dengan berbagai cara tergantung pada pembuat bahasa, ini penting karena saat kita menggunakan bahasa lain atau bahasa baru, kita harus mengerti cara kerja mereka terlebih dahulu




Tidak ada komentar:

Posting Komentar