Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Grammars in Compiler Design

This seems like a simple question, but I could not find a good explanation of this anywhere. How do you handle nested grammars [cfgs] (aka. grammars referencing other grammars.) For example,

S => Eb
E => cA

Separate Grammar:

A => d

Is this possible? If not, how does one approach dealing with this. For grammars, like variable declaration, is it necessary to simply rewrite the expression grammars associated with the main grammar or can they be referenced from it? If so, how does one integrate this feature into an LL(1) parser properly.

Thanks.

like image 684
ComedicChimera Avatar asked May 27 '26 14:05

ComedicChimera


1 Answers

I believe your question is dealing with the physical separation, in which case you could merge all together to form a complete main grammar.

Conceptually, a grammar with missing rules would be considered incoherent and invalid.

like image 94
Frank C. Avatar answered May 30 '26 05:05

Frank C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!