0% found this document useful (0 votes)
58 views1 page

Syntax and Semantics in CS1102

Syntax rules define what is permitted in a programming language. A program with a syntax error cannot be compiled or run, as it will contain confusing or unclear commands to the computer. Examples of syntax errors include missing a semicolon or not properly closing a string literal. Semantics refer to a language's meaning - a program with semantic errors can run but produce wrong results, due to issues like using incorrect variables, operators, or order of operations. Even syntactically correct programs can have semantic mistakes.

Uploaded by

Xanyk Leo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views1 page

Syntax and Semantics in CS1102

Syntax rules define what is permitted in a programming language. A program with a syntax error cannot be compiled or run, as it will contain confusing or unclear commands to the computer. Examples of syntax errors include missing a semicolon or not properly closing a string literal. Semantics refer to a language's meaning - a program with semantic errors can run but produce wrong results, due to issues like using incorrect variables, operators, or order of operations. Even syntactically correct programs can have semantic mistakes.

Uploaded by

Xanyk Leo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Discussion Unit One for CS1102 Programming

An evaluation of what is permitted and prohibited in the program is done by the


syntax rule, which is a rule of the programming language. A program that has a
syntax error cannot be compiled and cannot run when we attempt to run it. When
using the Java program, the syntax error causes commands to be confusing or
unclear to the computer. If we were to enter a line of code into the program without
including the last semicolon, it would be a nice illustration of a syntax error. The
error can be found and debugged by us as programmers.

The semantics of a computer language refers to its meaning. This means that if the
statement is indeed legitimate, it is read, validated, and then executed. It carries out
your requests. A program with a semantic error can be read and run, but it will
provide the wrong results. Sometimes the evaluation of the semantic error must
occur at runtime since it cannot be performed at compile time. These semantic
mistakes can occur in a variety of ways, such as by using the incorrect variable,
performing operations in the wrong order, or even by using the incorrect operator.
Even if our syntax is correct, if one of our operators is incorrect, the program will
produce an error.

Syntax example:
public class hello{

public static void main(String [] args) {


[Link]("Hello World!
String literal is not properly closed by a double-quote

Semantic example:
int a = "hello";
Type mismatch: cannot convert from String to int

You might also like