Mathematica 9 is now available

Wolfram Library Archive

All Collections Articles Books Conference Proceedings
Courseware Demos MathSource Technical Notes
Title Downloads

Context-Free Grammars

Charles Wells
Organization: Case Western Reserve University
Department: Department of Mathematics
Old MathSource #

Revision date


The Mathematica notebook, ContextFreeGrammar.nb, contains a command AcceptQ that takes a context-free grammar and a string as arguments and determines whether the string is generated by the grammar. As a side effect, it prints successively a list of strings that derive to the given string in n steps. It stops and accepts when it finds the start symbol in that list. If it comes up with the empty list, it rejects.

*Applied Mathematics > Computer Science

context-free grammars, context free grammars, parser, backward exhaustive search, forward breadth first search, derivation tree, formal languages, rewrite
Downloads Download Wolfram CDF Player

ContextFreeGrammar.nb (9.1 KB) - Mathematica notebook

Files specific to Mathematica 2.2 version:
Download (5.7 KB) - Mathematica notebook