# Size of a context-free grammar

Is there a formal definition for a size of a context-free grammar? The only definition I have seen so far is on this wiki page:

The size of a grammar is the sum of the sizes of its production rules, where the size of a rule is one plus the length of its right-hand side.

So, how does one define the size of a production rule's RHS?

For example, if I define my CFG as:

S : A
A : 'a' B | A
B : 'b'


What is the size of the production rule A?

• You gave a definition, apply it. Size of A is: 5. – saadtaame Apr 10 '13 at 16:50
• That would mean the length of a production rule's RHS is the number of symbols? Is there a formal definition for this? – Naveneetha Vasudevan Apr 10 '13 at 17:01
• There are several different definitions for the size of a grammar. The exact definition you use depends on your application. What's your application? (If it's homework, please ask your instructor for the definition that they expect.) – Yuval Filmus Apr 10 '13 at 17:03
• What do you want to use the size for? That way we can help you find an appropriate definition. – saadtaame Apr 10 '13 at 17:04
• Actually $A$ is LHS for two rules, one with RHS $aB$ (size 2, so size of the rule is 3) and one with RHS $A$ (RHS size 1, rule: size 2). – frafl Apr 10 '13 at 17:26