You are on page 1of 2

5/10/2020 Context-Free Grammars | Reading 3: Regular Expressions & Grammars | 6.005.

2x Courseware | edX

Course  Readings  Readin…  Contex…

Context-Free Grammars
Context-Free Grammars
In general, a language that can be expressed with our system of grammars is called
context-free. Not all context-free languages are also regular; that is, some grammars
can't be reduced to single nonrecursive productions. Our HTML grammar is context-
free but not regular.

The grammars for most programming languages are also context-free. In general, any
language with nested structure (like nesting parentheses or braces) is context-free but
not regular. That description applies to the Java grammar, shown here in part:

statement ::=
'{' statement* '}'
| 'if' '(' expression ')' statement ('else' statement)?
| 'for' '(' forinit? ';' expression? ';' forupdate? ')' statement
| 'while' '(' expression ')' statement
| 'do' statement 'while' '(' expression ')' ';'
| 'try' '{' statement* '}' ( catches | catches? 'finally' '{' statement*
'}' )
| 'switch' '(' expression ')' '{' switchgroups '}'
| 'synchronized' '(' expression ')' '{' statement* '}'
| 'return' expression? ';'
| 'throw' expression ';'
| 'break' identifier? ';'
| 'continue' identifier? ';'
| expression ';'
| identifier ':' statement
| ';'

https://courses.edx.org/courses/course-v1:MITx+6.005.2x+1T2017/courseware/Readings/03-Regular-Expressions-Grammars/?child=first 1/2
5/10/2020 Context-Free Grammars | Reading 3: Regular Expressions & Grammars | 6.005.2x Courseware | edX

Discussion Hide Discussion


Topic: Reading 3 / Context-Free Grammars

Show all posts by recent activity

There are no posts in this topic yet.

© All Rights Reserved

https://courses.edx.org/courses/course-v1:MITx+6.005.2x+1T2017/courseware/Readings/03-Regular-Expressions-Grammars/?child=first 2/2

You might also like