syntax

syntax - COP4020 Programming Languages Syntax analysis...

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

View Full Document Right Arrow Icon
COP4020 Programming Languages Syntax analysis Prof. Xin Yuan
Background image of page 1

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

View Full DocumentRight Arrow Icon
COP4020 Spring 2011 2 02/20/12 Overview Syntax analysis overview Grammar and context-free grammar Grammar derivations Parse trees
Background image of page 2
Syntax analysis Syntax analysis is done by the parser. Detects whether the program is written following the grammar rules and reports syntax errors. Produces a parse tree from which intermediate code can be generated. Source program Lexical analyzer token Request for token parser Rest of front end Symbol table Int. code Parse tree
Background image of page 3

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

View Full DocumentRight Arrow Icon
The syntax of a programming language is described by a context-free grammar (Backus-Naur Form (BNF)). Similar to the languages specified by regular expressions, but more general. A grammar gives a precise syntactic specification of a language. From some classes of grammars, tools exist that can automatically construct an efficient parser. These tools can also detect syntactic ambiguities and other problems automatically. A compiler based on a grammatical description of a language is more easily maintained and updated .
Background image of page 4
Grammars A grammar has four components G=(N, T, P, S): T is a finite set of tokens ( terminal symbols) N is a finite set of nonterminals P is a finite set of productions of the form . Where and S is a special nonterminal that is a designated start symbol COP4020 Spring 2011 5 02/20/12 β α→ * ) ( * ) ( T N N T N α * ) ( T N
Background image of page 5

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

View Full DocumentRight Arrow Icon
Language recognized by a grammar We say aAb derives awb in one step”, denoted as aAb=>awb ”, if A->w is a production and a and b are arbitrary strings of terminal or nonterminal symbols. We say a1 derives am if a1=>a2=>…=>am , written as a1=>am The languages L(G) defined by G are the set of strings of the terminals w such that S=>w. COP4020 Spring 2011 6 02/20/12 * *
Background image of page 6
A->aA A->bA A->a A->b G=(N, T, P, S) N=? T=? P=? S=? What is the language recognized by this grammer? COP4020 Spring 2011
Background image of page 7

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

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

This note was uploaded on 02/20/2012 for the course COP 4020 taught by Professor Engelen during the Spring '11 term at FSU.

Page1 / 21

syntax - COP4020 Programming Languages Syntax analysis...

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

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