syntax, semantics,

Syntax
Syntax is determined by formal rules saying how to construct expressions of the language from the set of atomic tokens (known as alphabet). From the mathematical point of view the syntax of a language can be defined as a (usually infinite) set of all correct strings of tokens from the alphabet. Unfortunately, such definition of syntax (that can be found in popular textbooks e.g. on context-free grammars or regular expressions) is incomplete from the point of view of semantics. Semantic rules are usually associated with syntactic rules. It may happen that for the same set of correct strings there are two sets of syntactic rules A and B, but the set A is correct, while the set B is wrong. For instance, consider the SQL statement
select X from Y where Z
and two sets of rules A and B determining its syntax. However, the set A assumes implicitly the parentheses as in  select X from (Y where Z), while the set B assumes implicitly the parentheses as in  (select X from Y) where Z. Although both A and B produce the same set of SQL statements, A is correct, while B is wrong (inconsistent with the actual semantics of SQL).
Syntax is usually specified by rules of context-free grammars, perhaps with additional constraints (for instance, concerning typing). In SBA we take little attention to concrete syntax, leaving this issue for possible implementations. All our definitions will be based on abstract syntax. Perhaps, at some moment SBQL will require standardization, and at that moment the unified concrete SBQL syntax will be determined. In existing implementations of SBQL it is a bit different.

Semantics
Semantics determines the meaning of syntactic constructs, that is, the relationship between syntactic constructs and elements of some universe of meanings. In the popular understanding semantics addresses human minds and in this case it can be expressed in terms of a natural language. Such semantics we can see, for instance, in UML diagrams, whose syntactic constructs are explained through more or less understandable phrases in our everyday tongue or by relationships with other (also informal) constructs. Such semantics, however, is valueless for a machine, it is not enough precise, too ambiguous and contains a lot of unspecified or poorly specified details.
The machine requires precise formal semantics. The general definition of formal semantics is not as easy as the definition of syntax because it requires the formal definition of the mentioned universe of meanings and the definition of mappings of the syntax into the universe of meanings. Such a definition is also not univocal, as it depends on who or what is the addressee of the definition. In particular, the description of semantics can be different for compiler writers and for application programmers who are/will be the users of the language. In our explanation we take the point of view of compiler or interpreter designers rather than application programmers. Obviously, this point of view requires from us to be extremely precise in specification and sensitive to all, even smallest semantic details.
In particular, we can assume that the universe of the meanings is the set of all the sequences of instructions of the Java virtual machine (JVM). The definition would be a mapping of the set of all the language expressions into the set of sequences of instructions of JVM. The definition of semantics assumes that the meaning of JVM instructions is non-definable; it is given as an axiom. Such an approach assumes that the definition of the semantics is done by the designers of a compiler or interpreter of the given language. The definition would be, however, valueless for application programmers, who rarely understands the actions of the Java virtual machine. Moreover, every team that attempts to implement Java (or other language) defines its own semantics, incompatible with the semantics of other teams.

structure
Image result for programming language processors structure

1 comment:

  1. Understanding syntax and semantics is essential for clear communication in programming and linguistics. With Ninza Host, you can ensure that websites or platforms focused on educational content about these concepts are hosted reliably, offering smooth and efficient user experiences.

    ReplyDelete