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