Regular vs Context Free Grammars

后端 未结 8 1388
我寻月下人不归
我寻月下人不归 2020-11-30 16:44

I\'m studying for my computing languages test, and there\'s one idea I\'m having problems wrapping my head around.

I understood that regular grammars<

8条回答
  •  無奈伤痛
    2020-11-30 17:31

    Regular grammar is either right or left linear, whereas context free grammar is basically any combination of terminals and non-terminals. Hence you can see that regular grammar is a subset of context-free grammar.

    So for a palindrome for instance, is of the form,

    S->ABA
    A->something
    B->something
    

    You can clearly see that palindromes cannot be expressed in regular grammar since it needs to be either right or left linear and as such cannot have a non-terminal on both side.

    Since regular grammars are non-ambiguous, there is only one production rule for a given non-terminal, whereas there can be more than one in the case of a context-free grammar.

提交回复
热议问题