PLC Session 2

In this second meeting we started to do our presentation that we presented with our groups, in this session 2 we talked about Describing Syntax and semantics that were presented by our friend’s group. This Session divided into 5 topics

  • Introduction
  • The General Problem of Describing Syntax
  • Formal Methods of Describing Syntax
  • Attribute Grammars
  • Semantics

First, we got introduction that covers a little of the whole subject. In this topic we learn about syntax and semantics, The syntax of a programming language is the form of its expressions, statements, and program units. Whereas the semantics of a programming language is the meaning of those expressions, statements, and program units. Next topic is about The General Problem of Describing Syntax .A language, whether natural (such as English) or artificial (such as Java), is a set of strings of characters from some alphabet. The strings of a language are called sentences or statements , that also means language is a set of sentences. There are also lexemes, lexemes is the lowest level syntactic unit of a language. Lexemes can be categorized and form a token. Move to the other topic, it is formal method  of describing syntax. In this topic we learn about context free grammar and Backus Naur Form that abbreviated into BNF . BNF is a natural notation for describing syntax, also BNF is nearly identical to Chomsky’s generative devices for context-free languages, called context-free grammars. We also learned that the fundamental of BNF consists of abstractions are used to represent classes of syntactic structures for example abstraction <assign>

<assign> →  <var> = <expression>

Where <assign> are called Left Hand Side(LHS) means that abstraction being defined

The next right of the arrow are called Right Hand Side(RHS) consists
of some mixture of tokens, lexemes, and references to other abstractions.

Abstraction in BNF are often called non terminal and the lexemes and token are  often called terminal .Non terminal itself are often enclosed in angle brackets. These non terminal and terminals are formed into what we call rules and a finite number of non empty rules are called grammar.In BNF an abstraction or non terminal can have more than one Right Hand Side. BNF can have recursive  if its LHS appears in its RHS for example

<ident_list> → identifier                                                                                                                                                    |identifier ,<ident_list>

A derivation is a repeated application of rules, starting with the start symbol and ending with a sentence (all terminal symbols).We also learn that a grammar is a generative device for defining languages. The sentences of the language are generated through a sequence of applications of the rules, beginning with a special nonterminal of the grammar called the start symbol. This sequence of rule applications is called a derivation. An example of derivation is

<program> => <stmts> => <stmt>

=> <var> = <expr>

=> a = <expr>

=> a = <term> + <term>

=> a = <var> + <term>

=> a = b + <term>

=> a = b + const

where the example of above’s grammar is

<program>  → <stmts>

<stmts>  → <stmt> | <stmt> ; <stmts>

<stmt>  → <var> = <expr>

<var>  → a | b | c | d

<expr>  → <term> + <term> | <term> – <term>

<term>  → <var> | const

The other topics is about attribute grammar, attribut grammar is a context free grammar. The attributes are divided into two groups: synthesized attributes and inherited attributes. The synthesized attributes are the result of the attribute evaluation rules, and may also use the values of the inherited attributes. The inherited attributes are passed down from parent nodes.In this session we also talked about semantics topic, semantics are the meaning of various elements in the program. A program can syntactically right but semantically wrong for example

int velocity, width;

Both of these variables are integers. From the compiler’s point of view, they are exactly the same. However, judging by the names, one is the width of something, while the other is velocity of something.

velocity = width;

Syntactically, this is okay, since you can assign integers to each other. However, semantically, this is totally wrong, since the width and the velocity didn’t have any relation whatsoever.  Semantics can be approach in three major classes Operational Semantics, Denotational Semantics, and Axiomatic Semantics .

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *