SYNTAX
IT2-Lecture 2
Syntax
• Form in which programs are written
• Correct symbols and correct use of
the symbols
Basic ingredients of the syntax of the
language
• Character Set
• Also called the alphabet
• Set of symbols use in PL
• It’s a practice for a PL to use standard such as the
ASCII set
• Example:
• Machine Language – 0 and 1 (2 characters)
• Algol-60 – 52 small and capital letters, 10 digit and 52
special character ( a total of 114 characters.
Basic ingredients of the syntax of the
language
• Identifiers
• Use to name the data object, procedure, and keywords
• Must consider rules such as length, valid characters,
and case sensitivity
• Example:
• In C identifiers must not exceed to 32 characters
• In Java identifiers are case sensitive
• In BASIC identifiers can be a capital followed by
Basic ingredients of the syntax of the
language
• Operator Symbols
• Used to represent primitive operations in the PL
• Example:
• +, -, *, /, %, =, ==, etc. in Java
• .EQ. for FORTRAN
• ADD to add in COBOL
Basic ingredients of the syntax of the
language
• Keywords and Reserved Words
• Keywords are special words that are used as part of the syntax
• Example:
• begin and end in PASCAL
• do and if in C
• Reserved words are special words that has a special
meaning in the PL
• Example:
• void in C
• true and false in Java
Basic ingredients of the syntax of the
language
• Comments and Noise Words
• Comments are words that are ignored during
compilation or interpretation
• Example:
• { and } in Pascal
• // in C++
• /* */ in C
• /** */ in Java
Basic ingredients of the syntax of the
language
• Delimiter and Bracket
• A delimiter is a syntactic elements that is used to mark
the start and end of some constructs
• Example:
• ; in C++ and Java
• : in BASIC
• A Bracket are used to enclose a group of statement
• Example:
• { and } in C++
Basic ingredients of the syntax of the
language
• Expression
• Basic syntactic elements that are used in most
statement
• Used to indicate condition and to evaluate values
assigned to variables
• Example:
• 4 == 4 (which result to true)
• a=b+c;
• if(a>b) a=a-b; else a=a+b;
Basic ingredients of the syntax of the
language
• Statement
• smallest components of the program that contains
executable code
• usually contains expression
• may be simple or compound
• Example:
• cout<<“Hello, C++ Program”;