What are context free grammars?I'd say that the files that make up an "instruction" for the drawing program are a linguistic grammar beyond a shadow of a doubt, although not the kind of grammar you would use for anything but a computer. Humans demand a bit more complexity in their grammars. Computers like it stupid.
A context free grammar is a description of a language in a set of rules. Each rule says how a single symbol can be expanded into a sequence of other symbols. Those symbols may, in turn, have rules and can be expanded again. Some symbols are terminals and have no rules. A legal sentence in the described language is a sequence of terminal symbols that can be produced starting with the start symbol of the grammar and proceeding via some sequence of expansions.
The process is considered context free because each expansion of a symbol via some rule can be done independently of any of the expansions of other symbols.
In Context Free, the only two terminals are the shapes CIRCLE and SQUARE. Given a starting shape, the program keeps expanding shapes that have rules until all that is left are terminal shapes, which are then drawn. In essence, the rendered images are legal sentences in the language described by the rules file!
startshape NAUT
rule NAUT {
CIRCLE {s 0.15}
NAUT {y 0.16 r -5 s 0.99}
}
rule NAUT 0.125 {
CIRCLE {s 0.15}
NAUT {y 0.16 r -5 s 0.99}
NAUT {x 0.89 r 185 s 0.257}
}
startshape DEATHSTAR
rule DEATHSTAR 100 {
CIRCLE {
size 0.2
}
DEATHSTAR {
y 0.08
rotate -1
size 1
b 0.000005
}
}
rule DEATHSTAR 0.5 {
DEATHSTAR {
size 0.999
rotate 0.1
}
}
rule DEATHSTAR 0.002 {
DEATHSTAR {
size 0.9
rotate 0.1
}
DEATHSTAR {
size 0.6
rotate 1
}
}
startshape FROND
rule FROND {
SQUARE{}
FROND {y 1}
}
rule FROND 0.15 {
CIRCLE {x 1}
CIRCLE {x -1}
FROND {r 90 s 0.5 b 0.2}
FROND {r -90 s 0.5 b 0.2}
FROND2 {}
}
rule FROND2
{FROND{s 0.85}}
rule FROND2 0.5 {
SQUARE {s 2 b 0.5}
}
rule FROND2 0.05 {
CIRCLE {x -0.5 y -0.5}
FROND {x -0.5 y -0.5 r 45}
}
startshape SQUARES
rule SQUARES {
SQUARE {b 0.8 x 0.1}
SQUARE{b 0 s 1}
SQUARE{b 1 s 0.9}
SQUARES {s 1 y 0.9 r 2}
}
rule SQUARES 0.3 {
SQUARES {s 0.5 x 1 r 90}
SQUARES {}
}
rule SQUARES 0.1 {
SQUARES {s 0.5 x 1 r 45}
SQUARES {}
}
rule SQUARES 0.1 {
SQUARES {s 0.9 x 1 r -90}
SQUARES {}
}
rule SQUARES 0.3 {
CIRCLE {b 0 s 1 r 90}
}« Older "More than 10-million U.S. homes are equipped with... | Alarming Article on Security P... Newer »
This thread has been archived and is closed to new comments
posted by abcde at 11:00 AM on July 7, 2005