L2Syn - Computer Language Engineering How to give...

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

View Full Document Right Arrow Icon
cs480(Prasad) L2Syntax 1 Computer Language Engineering Computer Language Engineering • How to give instructions to a computer? Programming Languages. • How to make the computer carryout the instructions efficiently? Compilers. cs480(Prasad) L2Syntax 2 Anatomy of a Compiler Intermediate Code Optimizer Code Generator Optimized Intermediate Representation Assembly code Intermediate Code Generator Intermediate Representation Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Token Stream Parse Tree Program (character stream) cs480(Prasad) L2Syntax 3 What is a Lexical Analyzer? • Examples of Token • Operators = + - > ( { := == <> •Keywo rd s if while for int double • Numeric literals 43 6.035 -3.6e10 0x13F3A • Character literals ‘a’ ‘~’ ‘\’’ • String literals “3.142” “Fall” “\”\” = empty” • Examples of non-token • White space space(‘ ’) tab(‘\t’) end-of-line(‘\n’) • Comments /*this is not a token*/ Source program text Tokens cs480(Prasad) L2Syntax 4 Lexical Analyzer in Action • Partition input program text into sequence of tokens, attaching corresponding attributes. – E.g., C-lexeme “015” token NUM attribute 13 • Eliminate white space and comments f for o r v a r 1 = 1 0 v a r 1 < = ID(“var1”) eq_op Num(10)
Background image of page 1

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

View Full DocumentRight Arrow Icon
cs480(Prasad) L2Syntax 5 Syntax and Semantics of a programming language? •Syn t ax – What is the structure of the program? – Textual representation. • Formally defined using context-free grammars (Backus-Naur Formalism) • Semantics – What is the meaning of a program? • Harder to give a mathematical definition. cs480(Prasad) L2Syntax 6 Input to and output of a parser - ( ) 123.3 23.6 + minus_op left_paren_op num(123.3) plus_op num(23.6) right_paren_op Token Stream Parse Tree Input: - (123.3 + 23.6) Syntax Analyzer (Parser) cs480(Prasad) L2Syntax
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 6

L2Syn - Computer Language Engineering How to give...

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

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