• Networking
  • Programming
  • DBMS
  • Operating System
  • Internet
  • Hardware
  • Software

Tech Differences

Know the Technical Differences

Difference Between Syntax and Semantics

Syntax and Semantics are very significant terms relating to any programming language. The syntax in a programming language involves the set of permitted phrases of a language whereas semantics expresses the associated meaning of those phrases.

There are some relationships between syntax and semantics where each semantic element is linked to at least one syntactic rendition and the other one assures that each syntactic representation has a distinctive meaning.

Content: Syntax Vs Semantics

    1. Comparison Chart
    2. Definition
    3. Key Differences
    4. Conclusion

Comparison Chart

Basis for comparisonSyntaxSemantics
BasicPermitted phrases of a language.Interpretation of the phrases.
ErrorsHandled at the compile time.Confronted at runtime.
RelationSyntactic interpretation must have some distinctive meaning.Semantic component is associated with a syntactic representation.

Definition of Syntax

The Syntax of a programming language is used to signify the structure of programs without considering their meaning. It basically emphasizes the structure, layout of a program with their appearance. It involves a collection of rules which validates the sequence of symbols and instruction used in a program. The pragmatic and computation model figures these syntactic components of a programming language. The tools evolved for the specification of the syntax of the programming languages are regular, context-free and attribute grammars.

However, what is the use of grammar in this aspect? The Grammars generally are the rewriting rules whose purpose is to recognize and generate the programs. Grammar does not rely on the computation model instead used in the description of the structure of the language. The grammar contains a finite set of grammatical categories (such as noun phrase, verb phrase, article, noun, etc), solitary words (elements of the alphabets) and the well-formed rules to specify the order within which components of the grammatical categories should appear.

Syntax analysis is a task performed by a compiler which examines whether the program has a proper associated derivation tree or not.

The syntax of a programming language can be interpreted using the following formal and informal techniques:

  • Lexical syntax for defining the rules for basic symbols involving identifiers, literals, punctuators and operators.
  • Concrete syntax specifies the real representation of the programs with the help of lexical symbols like its alphabet.
  • Abstract syntax conveys only the vital program information.

Types of grammars

  • Context-free grammar is prevalently used to figure out the whole language structure.
  • Regular expressions describe the lexical units (tokens) of a programming language.
  • Attribute grammars specify the context-sensitive part of the language.

Definition of Semantics

Semantics term in a programming language is used to figure out the relationship among the syntax and the model of computation. It emphasizes the interpretation of a program so that the programmer could understand it in an easy way or predict the outcome of program execution. An approach known as syntax-directed semantics is used to map syntactical constructs to the computational model with the help of a function.

The programming language semantics can be described by the various techniques – Algebraic semantics, Axiomatic semantics, Operational semantics, Denotational semantics, and Translation semantics.

  • Algebraic semantics interprets the program by defining an algebra.
  • Axiomatic semantics determine the meaning of a program by building assertions about an association that detain at each point in the execution of the program (i.e. implicitly).
  • Operational semantics compares the languages to the abstract machine, and the program is then evaluated as a sequence of the state transitions.
  • Denotational semantics expresses the meaning of the program in the form of a set of functions operating on the program state.
  • Translational semantics focuses on the methods used for translating a program into another language.

Key Differences Between Syntax and Semantics

  1. Syntax refers to the structure of a program written in a programming language. On the other hand, semantics describes the relationship between the sense of the program and the computational model.
  2. Syntactic errors are handled at the compile time. As against, semantic errors are difficult to find and encounters at the runtime.
  3. For example, in c++ a variable “s” is declared as “int s;”, to initialize it we must use an integer value. Instead of using integer we have initialized it with “Seven”. This declaration and initialization is syntactically correct but semantically incorrect because “Seven” does not represent integer form.

Conclusion

The syntax of a programming language is a collection of rules to specify the structure or form of code whereas semantics refers to the interpretation of the code or the associated meaning of the symbols, characters or any part of a program.

Related Differences:

  1. Difference Between Top-down and Bottom-up Parsing
  2. Difference Between Compiler and Interpreter
  3. Difference Between C++ and Java
  4. Difference Between Compiler and Assembler
  5. Difference Between High-Level Language and Low-Level Language

Comments

  1. rafia says

    July 5, 2018 at 12:59 pm

    very helpful website

    Reply
  2. anas says

    September 22, 2018 at 5:23 pm

    Nice one, i really appreciate your effort of making things vividly and straightforward in this particular sit.

    keep it up, and Multiple Thanks.

    Reply
  3. Fred says

    October 20, 2019 at 6:07 am

    very helpful, now i just learn a lot on this website.

    Reply
  4. Zahra says

    November 30, 2020 at 5:46 am

    an awesome and informing website indeed really appreciated.

    Reply
  5. Victor Mudanga says

    January 12, 2021 at 7:22 am

    thank you this was really helpful

    Reply
  6. Nimesh says

    December 21, 2021 at 7:40 am

    Great and was really helpful. Thanks alot for sharing

    Reply
  7. Martin Masule Kasokonya says

    June 8, 2022 at 8:33 am

    It is helping to read read this given information. It simplifies the difference between Syntax and Semantics. I mostly enjoyed reading the definitions of both syntax and semantics. Good work!

    Reply
  8. Martins says

    January 19, 2023 at 8:47 pm

    Thanks alot

    Reply

Leave a Reply Cancel reply

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

Top 10 Differences

  • Difference Between OLTP and OLAP
  • Difference Between while and do-while Loop
  • Difference Between Guided and Unguided Media
  • Difference Between Preemptive and Non-Preemptive Scheduling in OS
  • Difference Between LAN, MAN and WAN
  • Difference Between if-else and switch
  • Difference Between dispose() and finalize() in C#
  • Difference Between for and while loop
  • Difference Between View and Materialized View
  • Difference Between Server-side Scripting and Client-side Scripting

Recent Addition

  • Difference Between Unit Testing and Integration Testing
  • 4G Vs 5G
  • Raster Vs Vector Images
  • JPEG Vs TIFF
  • RJ11 Vs RJ12

Categories

  • DBMS
  • Hardware
  • Internet
  • Networking
  • Operating System
  • Programming
  • Software

Copyright © 2023 · Tech Differences · Contact Us · About Us · Privacy