Free Essay

Context Free Grammer vs Regular Grammer

In:

Submitted By kwright21
Words 522
Pages 3
Kellye Wright-Haynes

CMPS 300

Dr. Kokoly

Context-Free Grammars

A context-free grammar (CFG) is a set of recursive rewriting rules (or productions) used to generate patterns of strings.
A CFG consists of the following components: • a set of terminal symbols, which are the characters of the alphabet that appear in the strings generated by the grammar. • a set of nonterminal symbols, which are placeholders for patterns of terminal symbols that can be generated by the nonterminal symbols. • a set of productions, which are rules for replacing (or rewriting) nonterminal symbols (on the left side of the production) in a string with other nonterminal or terminal symbols (on the right side of the production). • a start symbol, which is a special nonterminal symbol that appears in the initial string generated by the grammar.
To generate a string of terminal symbols from a CFG, we: • Begin with a string consisting of the start symbol; • Apply one of the productions with the start symbol on the left hand size, replacing the start symbol with the right hand side of the production; • Repeat the process of selecting nonterminal symbols in the string, and replacing them with the right hand side of some corresponding production, until all nonterminals have been replaced by terminal symbols.

Regular Grammar
The regular grammars describe exactly all regular languages and are in that sense equivalent to finite state automata and regular expressions. Moreover, the right regular grammars by themselves are also equivalent to the regular languages, as are the left regular grammars.
Every regular grammar is a context-free grammar.
Every context-free grammar can be easily rewritten into a form in which only a combination of left regular and right regular rules is used. Therefore, such grammars can express all context-free languages. Regular grammars, which use either left-regular or right-regular rules but not both, can only express a smaller set of languages, called the regular languages. In that sense they are equivalent with finite state automata and regular expressions. (for illustration: the paradigmatic context-free language with strings of the form aibi is generated by the grammar G with N = {S, A}, Σ = {a, b}, P with the rules S → aA A → Sb S → ε and S being the start symbol. Note that this grammar has both left-regular and right-regular rules and is therefore not regular any more.)
Some textbooks and articles disallow empty production rules, and assume that the empty string is not present in languages.

CFGs vs Regular Expressions

Context-free grammars are strictly more powerful than regular expressions. • Any language that can be generated using regular expressions can be generated by a context-free grammar. • There are languages that can be generated by a context-free grammar that cannot be generated by any regular expression.
As a corollary, CFGs are strictly more powerful than DFAs and NDFAs.
The proof is in two parts: • Given a regular expression R , we can generate a CFG G such that L(R) == L(G). • We can define a grammar G for which there there is no FA F such that L(F) == L(G).

Similar Documents

Free Essay

Bhjjnkj

...COMPILER DESIGN LECTURE NOTES UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing: A preprocessor may allow a user to define macros that are short hands for longer constructs. 2. File inclusion: A preprocessor may include header files into the program text. 3. Rational preprocessor: these preprocessors augment older languages with more modern flow-of-control and data structuring facilities. 4. Language Extensions: These preprocessor attempts to add capabilities to the language by certain amounts to build-in macro 1.3 COMPILER Compiler is a translator program that translates a program written in (HLL) the source program and translate it into an equivalent program in (MLL) the target program. As an important part of a compiler is error showing to the programmer. Source pgm Compiler Error msg target pgm Department of CSE -2- Executing a program written n HLL programming language is basically of two parts. the source program must first be compiled translated into a object program. Then the results object program is loaded into a memory executed. Source pgm Compiler obj pgm Obj pgm input Obj pgm opj pgm output 1.4 ASSEMBLER: programmers found it difficult to write or read programs in machine language. They begin to use a mnemonic (symbols) for each machine instruction, which they would subsequently translate into machine language. Such...

Words: 14721 - Pages: 59

Free Essay

Phsychology

...Educational Psychology: Developing Learners This is a protected document. Please enter your ANGEL username and password. Username: Password: Login Need assistance logging in? Click here! If you experience any technical difficulty or have any technical questions, please contact technical support during the following hours: M-F, 6am-12am MST or Sat-Sun, 7am-12am MST by phone at (800) 800-9776 ext. 7200 or submit a ticket online by visiting http://help.gcu.edu. Doc ID: 1009-0001-191D-0000191E DEVELOPING LEARNERS JEANNE ELLIS ORMROD Professor Emerita, University of Northern Colorado EIGHTH EDITION ISBN 1-256-96292-9 Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City São Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Educational Psychology: Developing Learners, Eighth Edition, by Jeanne Ellis Ormrod. Published by Pearson. Copyright © 2014 by Pearson Education, Inc. Vice President and Editorial Director: Jeffery W.  Johnston Vice President and Publisher: Kevin Davis Editorial Assistant: Lauren Carlson Development Editor: Christina Robb Vice President, Director of Marketing: Margaret Waples Marketing Manager: Joanna Sabella Senior Managing Editor: Pamela D. Bennett Project Manager: Kerry Rubadue Senior Operations Supervisor: Matthew Ottenweller Senior Art Director: Diane Lorenzo Text Designer: Candace Rowley Cover Designer:...

Words: 244561 - Pages: 979

Premium Essay

Body Language

...Allan and Barbara Pease are the internationally renowned experts in human relations and body language, whose 20 million book sales worldwide have turned them into household names. People's body language reveals that what they say is often very different from what they think or feel. It is a scientific fact that people's gestures give away their true intentions. Every day we are confronted by hundreds of different signals that can mean anything from 'That's a great idea' to 'You must be kidding'. And we are all sending out these signals whether we realise it or not. Now, in this authoritative guide written with great humour and insight, you can learn the secrets of body language to give you more confidence and control in any situation — from negotiating a deal to finding the right partner. Discover the techniques that will show you how to interpret gestures, read the underlying thoughts and emotions — and reach the right conclusions. Front cover photo supplied courtesy of Shufunotomo Co., Ltd. 2-9 Kanda Surugadai, Chiyoda-Ku, Tokyo, Japan Allan Pease is the world's foremost expert on body language. His book Why Men Don't Listen And Women Can't Read Maps co-authored with wife Barbara, has sold over 10 million copies in 48 languages since its release. Allan travels the world lecturing on human communication, has written 8 other bestselling books and appeared in his own television series which attracted over 100 million viewers. Barbara Pease is CEO of Pease International which...

Words: 96880 - Pages: 388

Free Essay

Story of Success

...Outliers THE S T O R Y OF S U C C E S S MALCOLM G LAD W E L L # 1 bestselling author of The Tipping Point and Blink $27.99 $ 3 0 . 9 9 in C a n a d a Why d o s o m e p e o p l e succeed far more than others? T h e r e is a story that is usually told a b o u t extremely successful p e o p l e , a story that focuses o n intelligence a n d ambition. In Outliers Malcolm Gladwell a r g u e s that the true story o f s u c c e s s is very different, a n d that if we want to u n d e r s t a n d h o w s o m e p e o p l e thrive, we s h o u l d s p e n d m o r e time l o o k i n g around them — at s u c h things as their family, their birthplace, or even their birth d a t e . T h e story o f s u c c e s s is m o r e c o m p l e x — a n d a lot m o r e interesting — than it initially a p p e a r s . Outliers e x p l a i n s w h a t the B e a t l e s a n d Bill G a t e s have in c o m m o n , the e x t r a o r d i n a r y s u c c e s s o f A s i a n s at m a t h , the h i d d e n a d v a n t a g e s o f star athletes, why all t o p N e w York lawyers have the s a m e r é s u m é , a n d the r e a s o n y o u ' v e never h e a r d o f the w o r l d ' s s m a r t e s t m a n — all in terms o f g e n ­ eration, family, c u l t u r e , a n d c l a s s . It matters w h a t year y o u were b o r n if y o u want to b e a S i l i c o n Valley billionaire, G l a d w e l l a r g u e s , a n d it matters w h e r e y o u w e r e b o r n if y o u want to b e a s u c ­ cessful p i l o t . T...

Words: 86962 - Pages: 348

Premium Essay

Bbm Is Here

...Praise for Succeeding with Agile “Understanding the mechanics of an agile process is just not enough. Mike Cohn has compiled a superb and comprehensive collection of advice that will help individuals and teams with the intricate task of adopting and adapting agile processes to fit their specific challenges. This book will become the definitive handbook for agile teams.” —Colin Bird, Global Head of Agile, EMC Consulting “Mike Cohn’s experience working with so many different organizations in the adoption of agile methods shines through with practical approaches and valuable insights. If you really want agile methods to stick, this is the book to read.” —Jeff Honious,Vice President, Innovation, Reed Elsevier “Mike Cohn has done it again. Succeeding with Agile is based on his experience, and all of our experience, with agile to date. He covers from the earliest days of the project up to maturity and offers advice for the individual, the team, and the enterprise. No matter where you are in the agile cycle, this book has something for you!” —Ron Jeffries, www.XProgramming.com “If you want to start or take the next step in agile software development, this book is for you. It discusses issues, great solutions, and helpful guidelines when scaling up in agile projects. We used the guidelines from this book extensively when we introduced agile in a large, FDA-regulated department.” —Christ Vriens, Department Head of MiPlaza, part of Philips Research “If making the move to agile has always...

Words: 194469 - Pages: 778

Free Essay

Drahgdrha

...Web  Video  Texts  Audio  Projects  About  Account  TVNews  OpenLibrary | | | | Home | American Libraries | Canadian Libraries | Universal Library | Community Texts | Project Gutenberg | Children's Library | Biodiversity Heritage Library | Additional Collections | Search:    Advanced Search | Anonymous User (login or join us) | Upload | Full text of "Natya Shastra of Bharata Muni Volume 1"THE NATYASASTRA A Treatise on Hindu Dramaturgy and Histrionics Ascribed to B ii A R A T A - M r X I Vol. I. ( Chapters I-XXVII ) Completely translated jor the jirst tune from the original Sanskrit tuttri «u Introduction and Various Notes M .U'OMOH A N liHOS H M.A., Pn. I). <OaU 2 Viu i95y CALCUTTA THE RoyiL ISIAJtC SOCIETY OF BENGAL Dedicated to the memory of thom great scholars of India. and the West mho by their indefatigable study and. ingenious interpretation of her Religion, Philosophy, Literature and Arts, have demon- strated the high ealiie of India- s culture to the World at large and ham helped her towa.nls a reawakening and political alteration., and who by their discovery of the Universal aspect of this culture have made patent India's spiritual kinship with the other ancient nations of the World and ham paved the way for an ultimate triumph of Internationalism. PREFACE The preparation 'of an annotated English translation of the Natya&stra entrusted...

Words: 220089 - Pages: 881