1 / 17


Application. Note that “ | ” is synonymous with “ U ” in regular expressions. Why have different representation formalisms for the same class of languages? Convenience of expression

Download Presentation


An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.


Presentation Transcript

  1. Application Note that “|” is synonymous with “U” in regular expressions. L5Appl

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

  3. Example RE difficult L5Appl

  4. 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 L5Appl

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

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

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

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

  9. 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/ L5Appl

  10. 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.com • N:\tkprasad\cs466\HW.txt • file:///N:/tkprasad/cs466/HW.txt • ftp://www.cs.wright.edu • ftp://tkprasad@www.cs.wright.edu/ completeness L5Appl

  11. Ambiguity in Grammars L5Appl

  12. E E E E E E E E E E - - - - x x x x x x Parse/derivation trees for x - x - x Ambiguity: Two parse trees for x-x-x Two Interpretations: x, -x L5Appl

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

  14. 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. Operator Associativity and Precedences : Examples L5Appl

  15. Dangling Else Problem Grammar: • if B1 thenif B2 then S1 else S2 • vs • if B1 thenif B2 then S1else S2 Ambiguity: L5Appl

  16. Inherently ambiguous CFL • A context-free language that does not have an unambiguous context-free grammar is called an inherently ambiguous context-free language. L5Appl

  17. Ambiguous Context-Free Grammar L5Appl

More Related