Presentation is loading. Please wait.

Presentation is loading. Please wait.

C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.

Similar presentations


Presentation on theme: "C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan."— Presentation transcript:

1 C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan

2 Abstract Syntax: Abstract syntax is a device for identifying the essential syntactic elements of a program without describing their concrete construction. In other words, the underlying meaning not a particular language’s form of the element. C/C++ While (i<n) { i = i + 1; } Pascal While i<n do begin i := i + 1; end

3 Abstract Syntax Definition: Much like BNF we describe abstract syntax using rules with a left hand side and a right hand side: Lhs = Rhs Individual components on the Rhs are separated by semicolons (;). Loop = Expression test; Statement body

4 Abstract Syntax for Expression, Assignment, and Loop Figure 2.15 For Jay’s abstract syntax definition see Appendix B

5 Abstract Syntax Trees:  An abstract syntax tree (AST) describes the elements of a program stripped down to the essentials.  ASTs are often used as the internal, intermediate representational form of a compiler.  Optimizations can be performed prior to code generation by manipulating the AST.  Multiple languages may be implemented using a common backend by parsing to an AST representation.

6 (a) Structure of a Binary Node. (b) Abstract Syntax Tree for the Expression x+2*y Figure 2.16

7 Tying it all together:  Lexical analysis turns a program’s text into a token stream.  Concrete syntactical analysis checks the program and its elements for syntactic (structural) correctness.  Abstract syntactic analysis reduces the program’s elements to their semantics (meaning) resulting in an abstract syntax tree.  The algorithm that translates a token stream into an AST is called a parser.

8 Next time… Recursive Descent Parsing


Download ppt "C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan."

Similar presentations


Ads by Google