[Overview] [Previous] [Next]

BNF examples

<loop statement> ::= <while loop> | <for loop>

<while loop> ::= while ( <condition> ) <statement>

<for loop> ::= for ( <expression> ; <expression>; 		<expression> ) <statement>

<assignment statement> ::=
	<variable> = <expression>

Recursion is used frequently:
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

<integer> ::= <digit> | <integer> <digit>

<letter> ::= <lowercase letter> | <uppercase letter>

<lowercase letter> ::=
	a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z

<name> ::= <letter> | <name> <letter>
	| <name> <digit>

It's hard to set limits:
<small number> ::= <digit> | <digit> <digit>
	| <digit> <digit> <digit>
	| <digit> <digit> <digit> <digit>
	| <digit> <digit> <digit> <digit> <digit>

Copyright © 1996 by David Matuszek
Last modified Feb 2, 1996