330Syntax - UNIVERSITY OF SOUTH CAROLINA Department of...

Info iconThis preview shows pages 1–10. 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

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: UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 2: Syntax (Slides based on Tucker and Noonan) Fall 2010 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 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 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 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 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 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. 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering BNF History In Java: <IfThenStat> ::= if (<Expr>) <Stat> <IfThenElseStat> ::= if (<Expr>) <StatNoShortIf> else <Stat> UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering...
View Full Document

Page1 / 76

330Syntax - UNIVERSITY OF SOUTH CAROLINA Department of...

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