1

I have just learned that Regular Grammars have their corresponding Finite State Acceptors which will correspond to Regular Expressions.

Is there an equivalent conversion with Context Free Grammars? As far as I know Context Free Grammars can be represented by Push Down Automata which in turn would correspond to what?

Thanks to anyone who would clear my mind off of this.

Jer Yango
  • 582
  • 2
  • 8
  • 22

4 Answers4

2

From Wikipedia Context Free Grammar:

a popular notation for context-free grammars is Backus–Naur Form

…just as regexes are a notation for regular grammars.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Indeed, BNF is probably the equivalent. Can it also become a regex though? @Tim mentioned it can still be regex in a way. – Jer Yango Feb 02 '14 at 17:36
  • 1
    Well, some context-free grammars are also regular, so at least these would be representable as regexes :-) What Tim mentioned are not "theoretical" regular expressions from computer science, but the implementations of regex engines which often have features beyond regular languages - up to recursion which indeed makes them match any context-free language. However, as complexity increases, regexes become unusable, and depending on the information that is to be extracted a stack-based parser usually the better choice – Bergi Feb 02 '14 at 17:55
2

Actually, the answer could still be "Regex".

Modern regex dialects, specifically those that support recursion (like PHP, Perl, .NET, JGSoft and others) can handle context-free languages perfectly.

Community
  • 1
  • 1
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
0

Modern programming languages themselves are for the most part described by context free grammars. Although theoretically phrase structured grammars are the most powerful (English is an example), it has been found that for solving problems with computers context free grammars in combination with a powerful memory model (variables) are sufficient. The programs that accept these context free languages are the modern language parsers.

Some example language BNF

Given the BNF is context free, a parser can be generated automatically, the original and most famous example is of course Yacc others have been created since with Bison being invented for the creation of gcc. There are now a host of parser generators whose output is a parser written in one of the popular languages.

Community
  • 1
  • 1
waTeim
  • 9,095
  • 2
  • 37
  • 40
0

There's a problem with the phrasing of the question, in that it refers to grammars instead of to languages.

A Regular Language is one that can be defined over sets with the operations of union, concatenation, and closure. Both Regular Expressions and Regular Grammars are convenient ways to represent Regular Languages.

The thing with Context Free Language is that it is defined as the language accepted by a Context Free Grammar, so the answer to the OP's question is within the language category definition itself.

Apalala
  • 9,017
  • 3
  • 30
  • 48