Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Cs466(Prasad)L5Appl1 Application Note that “ | ” is synonymous with “ U ” in regular expressions."— Presentation transcript:

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

2 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.

3 cs466(Prasad)L5Appl3 Example RE difficult

4 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

5 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.

6 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)

7 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

8 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.

9 cs466(Prasad)L5Appl9 Some URLs LEX/YACC/FLEX/Bison: http://dinosaur.compilertools.net/ BNF for Java http://cui.unige.ch/db-research/Enseignement/analyseinfo/JAVA/BNFindex.html XML http://cm.bell-labs.com/cm/cs/who/wadler/xml/

10 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? http://www.google.com/ soundness –Programmer’s concern: What are all syntactically legal URLs? (The following “URLs” work in several browsers!) http://yahoo.com, yahoo.comhttp://yahoo.com N:\tkprasad\cs466\HW.txt file:///N:/tkprasad/cs466/HW.txt ftp://www.cs.wright.edu ftp://tkprasad@www.cs.wright.edu/ completeness

11 cs466(Prasad)L5Appl11 Ambiguity in Grammars

12 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

13 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:

14 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 + 1 + 2 * 3 = 1 + (2 * 3) 1 + 2 * 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.

15 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:

16 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.

17 cs466(Prasad)L5Appl17 Ambiguous Context-Free Grammar


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

Similar presentations


Ads by Google