{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

syntax - COP4020 Programming Languages Syntax analysis Prof...

Info icon This preview shows pages 1–7. Sign up to view the full content.

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

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

View Full Document Right Arrow Icon
COP4020 Spring 2011 2 02/20/12 Overview Syntax analysis overview Grammar and context-free grammar Grammar derivations Parse trees
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
Image of page 3

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

View Full Document Right 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 .
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 β
Image of page 5

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

View Full Document Right 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.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern