AST - Click to edit Master subtitle style CS784(PM)...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style CS784(PM) Abstract Syntax CS784(PM) Different Levels of Syntax • Lexical syntax – Basic symbols (names, values, operators, etc.) • Concrete syntax – Rules for writing expressions, statements, programs – Input to compilers/interpreters • Abstract syntax – “Internal” representation – Captures semantics CS784(PM) 22 CS784(PM) 33 Overview Parse-expression Unparse- expression Interpreter Concrete Syntax Abstract Syntax Results CS784(PM) CS784(PM) Concrete vs. Abstract Syntax • Expressions with common meaning (should) have the same abstract syntax . – C: a+b*c • Assumes certain operator precedence (why?) – Forth: bc*a+ (reverse Polish) This expression tree represents the meaning of expression Not the same as parse tree (why?) Does the value depend on traversal order? abc*+ (or is this it?) CS784(PM) 44 CS784(PM) 55 Parse tree vs. AST + exp r 1 2 + 3 exp r exp r ( ) ( ) exp r exp r 1 2 + 3 + exp r exp r CS784(PM) CS784(PM) 66 Abstract Syntax Tree • More useful representation of syntax tree – Less clutter – Actual level of detail depends on your design • Basis for semantic analysis • Later annotated with various information – Type information – Computed values CS784(PM) CS784(PM) 77 Compilation in a Nutshell Source code (character stream) Lexical analysis Parsing Token stream Abstract syntax tree (AST) Semantic Analysis if (b == 0) a = b; if ( b ) a = b ; = = if = = b = a b if = = int b int 0 = int a lvalue int b boolean Decorated AST int ; ; CS784(PM) CS784(PM) λ-expressions <exp> ::= <identifier> | ( lambda (<identifier> ) <exp>) | (<exp> <exp>) • Compare with Scheme S-expressions....
View Full Document

This note was uploaded on 06/02/2011 for the course CS 784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 28

AST - Click to edit Master subtitle style CS784(PM)...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online