Syntax and Semantics

Topics: Programming language, Context-free grammar, Formal grammar Pages: 8 (2374 words) Published: July 2, 2013
Semantics

In programming language theory, semantics is the field concerned with the rigorous mathematical study of the meaning of programming languages. It does so by evaluating the meaning of syntactically legal strings defined by a specific programming language, showing the computation involved. In such a case that the evaluation would be of syntactically illegal strings, the result would be non-computation. Semantics describes the processes a computer follows when executing a program in that specific language. This can be shown by describing the relationship between the input and output of a program, or an explanation of how the program will execute on a certain platform, hence creating a model of computation.

Semantics reveals the meaning of syntactically valid strings in a language. For natural languages, this means correlating sentences and phrases with the objects, thoughts, and feelings of our experiences. For programming languages, semantics describes the behavior that a computer follows when executing a program in the language. We might disclose this behavior by describing the relationship between the input and output of a program or by a step-by-step explanation of how a program will execute on a real or an abstract machine.

Semantics is concerned with the interpretation or understanding of programs and how to predict the outcome of program execution. The semantics of a programming language describe the relation between the syntax and the model of computation. Semantics can be thought of as a function which maps syntactical constructs to the computational model.

This approach is called syntax-directed semantics
There are several widely used techniques ( algebraic, axiomatic, denotational, operational, and translation) for the description of the semantics of programming languages. •Algebraic semantics describe the meaning of a program by defining an algebra. The algebraic relationships and operations are described by axioms and equations. •Axiomatic semantics defines the meaning of the program implicitly. It makes assertions about relationships that hold at each point in the execution of the program. Axioms define the properties of the control structures and state the properties that may be inferred. A property about a program is deduced by using the axioms. Each program has a pre-condition which describes the initial conditions required by the program prior to execution and a post-condition which describes, upon termination of the program, the desired program property. •Denotational semantics tell what is computed by giving a mathematical object (typically a function) which is the meaning of the program. Denotational semantics are used in comparitive studies of programming langauges. •Operational semantics tell how a computation is performed by defining how to simulate the execution of the program. Operational semantics may describe the syntactic transformations which mimic the execution of the program on an abstract machine or define a translation of the program into recursive functions. Operational semantics are used when learning a programming language and by compiler writers. •Translation semantics describe how to translate a program into an other langauge usually the language of a machine. Translation semantics are used in compilers. Much of the work in the semantics of programming languages is motivated by the problems encountered in trying to construct and understand imperative programs---programs with assignment commands. Since the assignment command reassigns values to variables, the assignment can have unexpected effects in distant portions of the program. Syntax

In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be correctly structured document or fragment in that language. This applies both to programming languages, where the document represents source code, and markup languages, where the...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Syntax and Semantics Essay
  • Semantics Essay
  • Syntax Essay
  • Semantics Essay
  • semantic Essay
  • semantics Essay
  • Syntax Research Paper
  • Essay about Semantics and Demonstrate Lesson

Become a StudyMode Member

Sign Up - It's Free