Lect 1.2 Lang Specification

Lect 1.2 Lang Specification - Lecture 1.2 Language...

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: Lecture 1.2 Language Specification • Language Specification • Grammars – basic elements – application – Example: grammar for a calculator language • BNF and EBNF • Syntax Diagrams • Ambiguity in Grammar References: – Louden, Chapter 4 Language Specification 2 Topics • Language Specification – syntax – semantics • Grammars – basic elements – application – Example: grammar for a calculator language • BNF and EBNF • Syntax Diagrams • Ambiguity in Grammar Language Specification 3 Why do we need a language specification? • Language specification is useful for: – describing a language – verification of validity of programs • Needed by – Language designers – Language implementers – Language users • I not stupid. • We loves to eat durians. • He are my best friend. • He tryed to bought a ticket. Language Specification 4 Language Specification • Description of language broken into: – syntax – semantics • The syntax is a set of rules that determines which constructs are correctly formed programs – EBNF used in rest of lectures to describe language syntax e.g. if A =< B is a syntax error in the C language Language Specification 5 Language Specification (cont’d) • The semantics is the description of the way a syntactically correct program is interpreted e.g. if (A <= B) checks if A is less than or equal to B. Language Specification 6 Grammar • A syntax of a language is described by a grammar • A grammar is a set of rules that defines all valid constructs accepted in the language • Basic elements of a grammar: – set of terminal symbols – set of nonterminal symbols – set of productions – goal symbol (aka distinguished symbol or start symbol ) Language Specification 7 An Example S → np vp np → pro | det noun vp → verb np pro → He | She | I … verb → likes | hates | prefer … det → the | a | an … noun → dog | cat | cow … He likes the dog pro verb det noun np vp np S non-terminal symbols terminal symbols productions goal symbol Language Specification 8 Basic Elements of a Grammar • Terminal symbols – These are atomic (nondivisible) symbols that can be combined to form valid constructs in the language. • Nonterminal symbols – These symbols are not included in the language itself, but are symbols used to represent intermediate definitions within the language as defined by productions. Language Specification 9 Basic Elements of a Grammar (cont’d) • Productions – A production (or rule ) is a definition of a nonterminal symbol. – Form: x ::= y where ::= denotes ‘is defined as’ x is a nonterminal symbol and y is a sequence of symbols each of which can be either terminal or nonterminal....
View Full Document

Page1 / 44

Lect 1.2 Lang Specification - Lecture 1.2 Language...

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