ID:95457
 
Keywords: dreamcatcher
definitions: definition definitions |

definition: IDENTIFIER NEWLINE definition_contents | IDENTIFIER '/' definition
definition_contents: INDENT definitions DEDENT |


That's a very simple grammar for something approaching the basics of a block structure language. Accepts these sorts of constructs:

a
b
c
d/e
f
h

i
j


See if you can figure out how it works. You read it like this:

definitions: definition definitions |


A 'definitions' is a 'definition' followed by a 'definitions', or it's nothing (':' is assignment, '|' is alternation)

definition: IDENTIFIER NEWLINE definition_contents | IDENTIFIER '/' definition


A 'definition' is an IDENTIFIER followed by NEWLINE followed by 'definition_contents' or an IDENTIFIER followed by the character / followed by a 'definition'.

definition_contents: INDENT definitions DEDENT |


A 'definition_contents' is an INDENT followed by a 'definitions' followed by a DEDENT

Note: Whether this works on tabs or braces or whatever is entirely dependent on the lexer - as long as it returns INDENT and DEDENT tokens when an indent or a dedent happens, it's all good. This also has a NEWLINE occurring before an INDENT and doesn't accept spurious newlines, which is sort of a problem