Cs466(Prasad)L5Appl1 Application Note that “ | ” is synonymous with “ U ” in regular expressions.

Slides:



Advertisements
Similar presentations
ISBN Chapter 3 Describing Syntax and Semantics.
Advertisements

176 Formal Languages and Applications: We know that Pascal programming language is defined in terms of a CFG. All the other programming languages are context-free.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Context-Free Grammars Lecture 7
104 Closure Properties of Regular Languages Regular languages are closed under many set operations. Let L 1 and L 2 be regular languages. (1) L 1  L 2.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Compilers and Syntax.
Chapter 3: Formal Translation Models
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 4: Syntax Specification COMP 144 Programming Language Concepts Spring 2002 Felix.
Specifying Languages CS 480/680 – Comparative Languages.
COP4020 Programming Languages
Winter 2003/4Pls – syntax – Catriel Beeri1 SYNTAX Syntax: form, structure The syntax of a pl: The set of its well-formed programs The rules that define.
1 Chapter 3 Context-Free Grammars and Parsing. 2 Parsing: Syntax Analysis decides which part of the incoming token stream should be grouped together.
Markup Languages & XML - BY VISHAL KAMTAM VENKATESH.
1 Scanning Aaron Bloomfield CS 415 Fall Parsing & Scanning In real compilers the recognizer is split into two phases –Scanner: translate input.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Syntactic Analysis Dr. Hyunyoung Lee.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
1-1 1 Syntax  Informal vs formal specification  Regular expressions  Backus Naur Form (BNF)  Extended Backus Naur Form (EBNF)  Case study: Calc syntax.
Introduction to GAIGS XML Scripting Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006.
Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Machine-independent code improvement Target code generation Machine-specific.
Compiler Construction1 COMP Compiler Construction Lecturer: Dr. Arthur Cater Teaching Assistant:
1 Chapter 3 Describing Syntax and Semantics. 3.1 Introduction Providing a concise yet understandable description of a programming language is difficult.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
CS 331, Principles of Programming Languages Chapter 2.
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Grammars CPSC 5135.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
COMP 3438 – Part II - Lecture 2: Lexical Analysis (I) Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ. 1.
ISBN Chapter 3 Describing Syntax and Semantics.
CONTEXT FREE GRAMMAR presented by Mahender reddy.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
1 Syntax Specification (Sections ) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos at UNC.
Parsing Introduction Syntactic Analysis I. Parsing Introduction 2 The Role of the Parser The Syntactic Analyzer, or Parser, is the heart of the front.
作者 : 陳鍾誠 單位 : 金門技術學院資管系 URL : 日期 : 2016/6/4 程式語言的語法 Grammar.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
CPS 506 Comparative Programming Languages Syntax Specification.
D Goforth COSC Translating High Level Languages.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
CS 331, Principles of Programming Languages Chapter 2.
Syntax Analysis – Part I EECS 483 – Lecture 4 University of Michigan Monday, September 17, 2006.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
2-1. LEX & YACC. 2 Overview  Syntax  What its program looks like –Context-free grammar, BNF  Syntax-directed translation –A grammar-oriented compiling.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
Mid-Terms Exam Scope and Introduction. Format Grades: 100 points -> 20% in the final grade Multiple Choice Questions –8 questions, 7 points each Short.
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions: Context-Free Grammars and Languages Autumn 2011 CSE 3111.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Last Chapter Review Source code characters combination lexemes tokens pattern Non-Formalization Description Formalization Description Regular Expression.
5. Context-Free Grammars and Languages
Chapter 3 – Describing Syntax
Context-Free Languages & Grammars (CFLs & CFGs)
Introduction to Parsing (adapted from CS 164 at Berkeley)
Lexical Analysis (Sections )
CSE 3302 Programming Languages
5. Context-Free Grammars and Languages
Review: Compiler Phases:
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
High-Level Programming Language
Presentation transcript:

cs466(Prasad)L5Appl1 Application Note that “ | ” is synonymous with “ U ” in regular expressions.

cs466(Prasad)L5Appl2 Why have different representation formalisms for the same class of languages? Convenience of expression –For certain languages, a regular grammar may be substantially easier to write than a regular expression (or vice versa). –Regular expression can be mapped to a recognizer in a language containing sequencing, conditional, and while-loop. –Regular grammars can be mapped to finite automaton.

cs466(Prasad)L5Appl3 Example RE difficult

cs466(Prasad)L5Appl4 Example RE difficult Requires simulation of complement using union, concatenation, and Kleene-star operation, which is not straightforward. (Refer to: Finite State Automata results.) complement

cs466(Prasad)L5Appl5 Closure properties –Regular languages are closed under union, concatenation, and Kleene-star, by definition. However, closure under complementation and intersection is not obvious. Robustness of Regular Languages –Various formalisms (such as regular expressions, regular grammars, and finite automata) converge to defining the same collection of languages. “Intrinsic stability” of regular languages.

cs466(Prasad)L5Appl6 Specifying and Automatically Generating Compiler Front-end Lexical Analyzer Syntax Analyzer Back-end Regular Expressions Context-free Grammar Attribute Grammars (Refer to: LEX,FLEX,YACC,BISON)

cs466(Prasad)L5Appl7 Pattern Matching in Scripts and PLs –E.g., Regular expressions in awk, bash, UNIX grep, PERL, Python, Ruby, Java,.NET, etc Document type definition (DTD) in XML (eXtensible Markup Language) –Specifies context-free syntax of a web- document using domain-specific vocabulary. – Document :: cs480.html :::: Language :: HTML :::: Meta-language :: SGML, XML

cs466(Prasad)L5Appl8 Formal specification of Input and Output formats for programs during Software Development and Documentation. –Helpful to the users for clarification in user manuals. –Helpful to the designers in order to make I/O details explicit in a standard way. –Helpful to the developers, the integrators, and the testers for communication and clarification.

cs466(Prasad)L5Appl9 Some URLs LEX/YACC/FLEX/Bison: BNF for Java XML

cs466(Prasad)L5Appl10 Some URLs (Again!) URL for opening a web-page in a Browser –User’s concern: What is the syntax of the URL for Google’s homepage? soundness –Programmer’s concern: What are all syntactically legal URLs? (The following “URLs” work in several browsers!) yahoo.comhttp://yahoo.com N:\tkprasad\cs466\HW.txt file:///N:/tkprasad/cs466/HW.txt ftp:// completeness

cs466(Prasad)L5Appl11 Ambiguity in Grammars

cs466(Prasad)L5Appl12 E EE - EE - xxx E EE - EE - xxx Ambiguity: Two parse trees for x-x-x Two Interpretations: x, -x Parse/derivation trees for x - x - x

cs466(Prasad)L5Appl13 Using associativity information, it is possible to rewrite the grammar. So, the language of expressions with x and – is not inherently ambiguous. Left associative: Right associative:

cs466(Prasad)L5Appl14 Operator Associativity and Precedences : Examples Right associative a = b = 5; a = (b = 5); Left associative cout << 5 << “abc”; (cout << 5)<< “abc”; * has precedence over * 3 = 1 + (2 * 3) * 3 =/= (1 + 2)*3 Associativity and precedence information is typically used to disambiguate non-fully parenthesized expressions containing unary prefix/postfix operators or binary infix operators.

cs466(Prasad)L5Appl15 Dangling Else Problem if B1 then if B2 then S1 else S2 vs if B1 then if B2 then S1 else S2 Grammar: Ambiguity:

cs466(Prasad)L5Appl16 Inherently ambiguous CFL inherently ambiguousA context-free language that does not have an unambiguous context-free grammar is called an inherently ambiguous context-free language.

cs466(Prasad)L5Appl17 Ambiguous Context-Free Grammar