330Ch2 - CSCE 330 Programming Language Structures Chapter...

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

View Full Document Right Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 2: Syntax Fall 2009 Marco Valtorta mgv@cse.sc.edu A language that is simple to parse for the compiler is  also simple to parse for the human programmer.  N. Wirth
Background image of page 1

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

View Full DocumentRight Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Syntax and Semantics Syntax is the set of rules that specify the composition of programs from letters, digits and other characters. Semantics is the set of rules that specify what the result/outcome of a program is. Problems with English language description of Syntax and Semantics: verbosity ambiguity
Background image of page 2
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Contents 2.1  Grammars 2.1.1  Backus-Naur Form 2.1.2  Derivations 2.1.3  Parse Trees 2.1.4  Associativity and Precedence 2.1.5  Ambiguous Grammars 2.2  Extended BNF 2.3  Syntax of a Small Language:  Clite 2.3.1  Lexical Syntax 2.3.2  Concrete Syntax 2.4  Compilers and Interpreters 2.5  Linking Syntax and Semantics 2.5.1  Abstract Syntax 2.5.2  Abstract Syntax Trees 2.5.3  Abstract Syntax of  Clite
Background image of page 3

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

View Full DocumentRight Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Thinking about Syntax The syntax of a programming language is a precise description of all its grammatically correct programs. Precise syntax was first used with Algol 60, and has been used ever since. Three levels: Lexical syntax Concrete syntax Abstract syntax
Background image of page 4
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Levels of Syntax Lexical syntax = all the basic symbols of the language (names, values, operators, etc.) Concrete syntax = rules for writing expressions, statements and programs. Abstract syntax = internal representation of the program, favoring content over form. E.g., C: if ( expr ) . .. discard ( ) Ada: if ( expr ) then discard then
Background image of page 5

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

View Full DocumentRight Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 2.1 Grammars A metalanguage is a language used to define other languages. A grammar is a metalanguage used to define the syntax of a language. Our interest : using grammars to define the syntax of a programming language.
Background image of page 6
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 2.1.1 Backus-Naur Form (BNF) Stylized version of a context-free grammar (cf. Chomsky hierarchy) Sometimes called Backus Normal Form First used to define syntax of Algol 60 Now used to define syntax of most major languages
Background image of page 7

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

View Full DocumentRight Arrow Icon
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering BNF History In Java: <IfThenStat> ::= if (<Expr>) <Stat> <IfThenElseStat> ::= if (<Expr>) <StatNoShortIf> else <Stat>
Background image of page 8
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering BNF Grammar Set of productions : P terminal symbols: T nonterminal symbols: N start symbol: A production has the form where and S N A N ϖ∈ ( N T )* A →ϖ
Background image of page 9

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

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

This note was uploaded on 04/23/2010 for the course QWE asd taught by Professor Asd during the Spring '10 term at University of Karachi.

Page1 / 76

330Ch2 - CSCE 330 Programming Language Structures Chapter...

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

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