Download presentation
Presentation is loading. Please wait.
Published byLanny Sanjaya Modified over 5 years ago
1
Lesson Objectives Aims Understand Syntax Analysis
2
All languages (human and programming) have rules.
Syntax All languages (human and programming) have rules. Unlike English, for example, computers are totally unforgiving of bad grammar “You’re a moron” “Your a moron” My a moron what?!
3
Syntax Syntax is the grammar of a programming language It is a set of rules that lines of code must adhere to in order to be “syntactically correct” If a line of code does not adhere to any known rule, a syntax error is generated
4
Example
5
dimm chunder As Integer
Syntax Error How does the compiler know this is a spelling error?? dimm chunder As Integer How would this line of code be interpreted?
6
The syntax analyser will check for two things:
Spelling errors Whether a token stream is valid and matches a given rule
7
The syntax analyser will use rules that are based on some form of logic
One such method is Backus Naur Form This is a method of tightly defining atomic rules that cannot be misinterpreted They are also recursive in nature
8
Once syntax has been verified, an Abstract Syntax Tree is produced
Why: Unambiguous (tightly defined) data structure Can only be read in one way Removes any uncertainty about operator precedence
9
2 * 3 + 4…. Which happens first?
10
Task Find out and make notes on: BNF – why is it used? BNF – how are numbers represented (recursively(what is recursion??)) AST – what does a simple AST look like? What about for a common statement such as IF?
11
Review/Success Criteria
You should know: What Syntax is What role the syntax analysis stage plays in compilation What will generate a syntax error What an AST is What BNF is and why it is useful in syntax parsing
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.