Discussion Forum Unit 1
Discussion Forum Unit 1
Hello everyone
Syntax is basically defined as the structure of a program. Every language whether Formal
or natural has general rules concerning the formation of words and sentences and that is exactly
what syntax is. It is the rules that determine what is allowed in the programming environments,
the rules that define the structure of a language.
Whereas Semantics is the meaning of the programs and how they behave. According to
(Eck. 2019)” the semantics of a programming language is the set of rules that determine the
meaning of a program written in that language. A semantically correct program is one that does
what you want it to”
You see, Syntax only cannot make up for the whole program. In order to have a good
functioning program as we like, we also need the Semantics. Both are equally important for the
program in a programming language. Now, let’s talk about the difference between a syntax
error and a semantic error
A syntax error is an error that appears in the script or source code of a program. It is a
grammatical mistake that is sometimes limited to a single character
For example:
code
public class Syntaxerror {
Output
at syntaxerror.Syntaxerror.main(Syntaxerror.java:17)
C:\Users\yunji1\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java
returned: 1
As you can see on the above example, my program faced an error, and that error is that I
have written the‘s’ of string with a small letter instead of a capital letter.
System.out.println("The student age is " + age + "and the student attends" +school);
Output:
run:
Example:
Code
//first example
System.out.println(age);
//second example
int number;
number++
//third example
// Errors in expressions
String s = "...";
int a = 5 - s;// the - operator does not support arguments of type String
With the above examples, you can see the illustrated difference between a syntax and a
semantic error.
References
https://techterms.com/definition/programming_language
Smith College. http://math.hws.edu/javanotes.