Syntax என்பது ஒரு programming language-ல் program statements எப்படி எழுதப்பட வேண்டும் என்பதை define செய்யும் ……
SYNTAX
Syntax என்பது ஒரு programming language-ல் program statements எப்படி எழுதப்பட வேண்டும் என்பதை define செய்யும் formal grammatical rules. Simple Tamil: Programming language-ன் grammar தான் Syntax. English-ல் sentence எழுத grammar rules இருப்ப…
1. SYNTAX என்றால் என்ன?…
Programming language-ல்: Keywords Identifiers Operators Symbols Expres……
இதில் syntax rules: if keywor……
SIMPLE REAL-LIFE COMPARISON
English: Raja eats an apple. Grammar correct. Raja apple an eats. Words இருக்கின்றன. ஆனால் grammatical arrang……
SYNTAX vs SEMANTICS
மிகவும் important distinction. Code……
Syntax correct. Semantics: Current x ……
LEXICAL STRUCTURE AND SYNTAX
Programming language syntax-ஐ புரிந்து கொள்ள இரண்டு levels important: Lexical Structure ↓ Syntax Structure Le……
TOKEN
Programming language-ன் small……
int total = 100; Tokens: int total = 100 ; Classific……
TYPES OF TOKENS
C++-ல் commonly: Tokens | +-- Keywords +-- ……
KEYWORDS
Language predefined reserved words. Examples: int if else for while return clas……
IDENTIFIERS
Variables, functions, classes ……
Function: int add()…
Class: class Student…
IDENTIFIER SYNTAX RULES
C++ identifier பொதுவாக: Letter அல்லது underscore மூலம் start ஆகலாம். Digits later வரலாம். Spaces இர……
LITERALS
Program-ல் directly written fixed values. Examples: 10 Integer lit……
OPERATORS
Operations represent செய்யும்……
&& ||…
Here: = → assignment operator…
- → arithmetic operator…
PUNCTUATORS
Programming syntax structure define செய்ய உதவும் symbols. Examples: ; ……
{} block.…
EXPRESSION SYNTAX
Operands மற்றும் operators-ன்……
a + b Valid expression. Anoth……
OPERAND
Operator operation செய்யும் v……
- → Operator…
b → Operand…
STATEMENT SYNTAX
Programming language-ல் ஒரு c……
DECLARATION SYNTAX
C++ variable declaration: data_type variable_nam……
ASSIGNMENT SYNTAX
IF STATEMENT SYNTAX
IF-ELSE SYNTAX
FOR LOOP SYNTAX
WHILE LOOP SYNTAX
int i = 1;…
FUNCTION SYNTAX
General: return_type function_name(parameters) { statements; return value; } int add(int a,……
CLASS SYNTAX
Class definition முடிவில்: }; semic……
SYNTAX ERROR
Programming language grammatical r……
Missing: ; Compiler syntax er……
COMMON C++ SYNTAX ERRORS
Missing semicolon Missing braces Missing parentheses In……
MISSING SEMICOLON
Wrong: int x = 10 Correct: in……
MISSING PARENTHESIS
MISSING BRACE
Closing: } missing.…
UNCLOSED STRING
CASE SENSITIVITY
C++ case-sensitive language. int total = 10; and: in……
FORMAL SYNTAX
Programming language syntax natural-language explanation மட்டும் அல்ல. Mathematical / formal……
GRAMMAR
Programming language-ல் valid sentences/program structures உருவாக்கும் fo……
TERMINAL SYMBOL
Grammar-ல் further replace செய்ய முடியாத actual……
NON-TERMINAL SYMBOL
Grammar structure represent செய்யும் variable-like ……
PRODUCTION RULE
ஒரு non-terminal எப்படி expan……
::= +…
ஒரு expression மற்றொரு expres……
BNF
BNF = Backus-Naur Form Programming la……
::= definition ::= 0 | 1 | 2 | 3 | 4 | ……
BNF SIMPLE EXAMPLE
Suppose identifier: ::= | |…
Identifier: letter மட்டும் இருக்கலாம் o……
EXPRESSION GRAMMAR
::= + | ::= * | ::= identifier | number This gr……
DERIVATION
Grammar production rules பயன்படுத்தி start symbol-இலிருந்து v……
LEFTMOST DERIVATION
ஒவ்வொரு step-லும் leftmost non-terminal முத……
RIGHTMOST DERIVATION
Rightmost non-terminal முதலில் replace செய்த……
PARSE TREE
Grammar மூலம் program/string எப்படி derive செய……
a + b Parse tree: Expr / | \ ……
COMPLEX EXPRESSION PARSE TREE
Expression: a + b * c Correct……
a + (b * c) Multiplication fi……
PARSING
Input tokens grammar rules follow செய்கிறதா என்று analyze செய்யும் ……
LEXICAL ANALYZER
Source program characters-ஐ t……
int x = 10; Lexical analyzer output conce……
PARSER
Tokens valid grammar structure-ல் இருக்கிறதா என்று ch……
LEXICAL ANALYSIS vs SYNTAX ANALYSIS
SCANNER
Lexical analyzer-க்கு another……
Exam MCQ-க்கு important.…
PARSER ERROR
int, =, x, 10, ; எல்லாம் recognizable tokens. ஆனால் grammar order w……
CONTEXT-FREE GRAMMAR
Programming language syntax பெரும்பாலும்: Contex……
CFG COMPONENTS
Context-Free Grammar mathemat……
TRB / NET / SETக்கு இது முக்க……
START SYMBOL
Grammar derivation தொடங்கும் speci……
META-LANGUAGE
Programming language syntax describe செய்ய பயன்படுத்தப்படும் language/notati……
EBNF
EBNF = Extended Backus-Naur Form BNF-ன் extended versi……
EBNF COMMON SYMBOL IDEAS
Notation standard-ஐ பொறுத்து symbols vary செய்யலாம், ……
= { | }…
First letter + zero or more l……
ABSTRACT SYNTAX
Programming language syntax இரண்டு levels-ல் பார்க்கப்படு……
a + b; Includes: parentheses ……
ABSTRACT SYNTAX
Program-ன் essential structural meaning மட்டும் repre……
AST
Expression: a + b * c AST: + / \ a * ……
PARSE TREE vs AST
AMBIGUOUS GRAMMAR
ஒரே input string-க்கு ஒன்றுக்கு மேற்பட்ட parse trees கிடைத்தால் grammar: Ambiguous Grammar என்று அழைக்கப்படும……
1. WHY AMBIGUITY IS A PROBLEM?…
Compiler-க்கு: Which interpretation is correct? என்று ambiguity வரும். Programming langua……
OPERATOR PRECEDENCE
எந்த operator first evaluate ……
2 + 3 * 4…
- precedence greater than +.…
Therefore: 3 * 4 = 12 2 + 12 ……
ASSOCIATIVITY
Same precedence operators multiple இருந்தால் evaluation/grouping ……
LEFT ASSOCIATIVE
Grouping: a - b - c as: (a - ……
RIGHT ASSOCIATIVE
Assignment operators commonly……
a = (b = (c = 10))…
PRECEDENCE vs ASSOCIATIVITY
SYNTAX DIAGRAM / RAILROAD DIAGRAM
Grammar rules graphically represe……
Start → if → (condition) → statement → End P……
STATIC SYNTAX
சில language rules pure context-free grammar மட்டும் கொண்டு முழுமையாக express செய்ய முடியாது. Examples: Varia……
SYNTAX AND COMPILER
Compiler flow: Source Program ↓ Lexical Analysis ↓ Tokens ↓ Syntax Analysis ↓ Par……
SYNTAX ANALYZER
Another name: Parser Therefor……
COMPILER ERROR STAGES
int x = ; Syntax error.…
y declared இல்லையெனில் name/semantic analysis error. int x ……
C++ BASIC SYNTAX
using namespace std; → Namesp……
{ } → Block…
return 0; → Return statement…
BLOCK STRUCTURE
Statements { } braces-க்குள் ……
Both statements belong to sam……
SEMICOLON RULE
C++-ல் many statements: ; மூல……
But control block header afte……
இதன் closing brace பிறகு normal……
semicolon required.…
WHITESPACE
Spaces, tabs, newlines many contexts-ல் tokens separate செய்ய உதவும். ……
COMMENTS AND SYNTAX
C++ comments: Single line: // comment Multi-line: /* comment */ Comments……
FREE-FORM LANGUAGE
C++ largely free-form languag……
Statements fixed columns-ல் எ……
syntactically possible. Reada……
preferred.…
SYNTAX DESIGN GOALS
Programming language syntax நல்லதாக இருக்க வேண்டுமெனில்……
READABILITY
condition clear. Complex/unusu……
WRITABILITY
Syntax programmer-க்கு code easy-ஆக ……
Both valid; concise forms wri……
SYNTACTIC SUGAR
Language-ல் already possible operation-ஐ easier/convenient syntax மூல……
Syntactic sugar generally new fundamental compu……
CONCRETE EXAMPLE OF SYNTAX CHECKING
Compiler front-end: Step 1 Characters: i n t t o t a l ... Step 2 Tokens: int total = a + 10 ; Step 3 Parser ……
Characters ↓ Lexical Analyzer ↓ Tokens ↓……
= Rules defining the structure/form of valid programs. Grammar = Formal set of rules describing synt……
Confuse செய்ய வேண்டாம்: Syntax ≠ Semantics Token ≠ Character Lexical Analyzer ……
S → Syntax → Structure G → Grammar → Rules T → Token → Tiny meaningful unit P → Par……
1. The grammatical structure ……
Answer: Syntax…
1. Programming language synta……
Answer: Grammar…
BNF stands for:
Answer: Backus-Naur Form…
Smallest meaningful lexical unit:
Answer: Token…
Syntax analyzer is also called:
Answer: Parser…
Lexical analyzer is also called:
Answer: Scanner…
A tree representing grammatical structure:
Answer: Parse Tree…
1. If one sentence has more t……
Answer: Ambiguous…
CFG is represented by:
Answer: G = (V, T, P, S)…
Operator priority is called:
Answer: Precedence…
Syntax specifies:…
Which formalism is widely use……
BNF stands for:…
Which compiler phase converts……
Which compiler component chec……
A grammar with more than one ……
Which is a non-terminal?…
::= in BNF means:…
Which determines whether * or……
Which of the following is the……
2 Marks - Define Syntax Syntax is the set of formal grammatical rules that specifies the structure and form o……
Programming Language ↓ Characters ↓ Lexical Analysis ↓ Tokens ……
| +-- Tokens +-- Grammar +-- Terminals +-- Non-terminals +-- Productions +-- BNF +-- EBNF +-- Derivation +-- ……