Static Semantics meaning?
Asked Answered
M

4

15

What does term "static semantics" mean in programming?

What is relationship between static semantics, semantics and dynamic semantics?

I know that semantics stands for checking if written code (without syntax errors) has any meaning.

Micrography answered 4/11, 2016 at 19:38 Comment(0)
U
29

Semantics is about meaning. It includes:

  • the static semantics, which is the part that can be ascertained at compile time, including data typing, whether all variables are declared, which declaration applies to which variable in the case of scoping, what their type is, whether functions and methods are called with correct calling sequences, whether assignments are type-compatible, etc., and

  • dynamic semantics, which is what actually happens when the program is executed.

Source: Frank de Remer, Compiler Construction course, University of California, Santz Cruz, 1979.

Underclothes answered 4/11, 2016 at 20:30 Comment(1)
Great response! Thanks.Micrography
S
5

Static properties of a program are those that the compiler can detect at compile time.

Only Static Semantic errors can be detected by the compiler at compile time.

Dynamic Semantic errors can only be detected upon execution, not by the compiler prior to execution.

Sun answered 6/1, 2021 at 1:23 Comment(0)
O
0

Static semantics

Principles

  • The program is not evaluated, i.e. the semantics don't directly guide the semantic algorithm's flow (which follows the program's structure instead)
  • Should terminate on every program
  • Must not depend on external events (such as IO, system errors, etc)
  • The algorithm should not need to visit the same node in the AST twice (or more than n times, for n fixed for the algorithm)
  • The output tells you something about how the program is defined, not what it does

Application

  • Type checking
  • Warnings / coding suggestions
  • Optimizing
  • Compiling

Dynamic semantics

Principles

  • The program is evaluated - this can mean for example that semantics of control flow instructions affect the way the semantic algorithm is evaluated itself
  • Can loop, halting problem can be undecidable
  • Can depend on arbitrary real-world events
  • It may be necessary to evaluate the same part of the AST indefinite number of times
  • The output tells you the results of the implemented algorithm

Application

  • Well, running programs
  • Different dynamic semantics can be used to describe runtime in different environments (such as test / prod / 1987 washing machine chip)

Of course dependent types throw it all into one sack and shake violently. Don't stick to these hunches very tightly, as it can get blurry sometimes.

Are constexpr semantics static or dynamic? - one could ask...

Oriana answered 6/1, 2023 at 15:50 Comment(0)
A
-4

Static semantics: It means that your programming statement should not have a possibility of generating more than one results based on grammar rules.

Artistic answered 2/3, 2020 at 0:40 Comment(1)
It means nothing of the sort. Grammar rules are about syntax, not semantics. Don't post guesswork here.Underclothes

© 2022 - 2024 — McMap. All rights reserved.