-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriginal_PolyGen-Refman_EN.html
2341 lines (2334 loc) · 97 KB
/
original_PolyGen-Refman_EN.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 for Windows version 5.2.0">
<title>HOWTO-grm</title>
<meta http-equiv="content-type" content=
"text/html; charset=utf-8">
</head>
<body style="width: 90%; margin: 2em auto; font-size: 20px">
<h1 align="center">HOWTO-grm</h1>
<h1 align="center"></h1>
<h1 align="center"><small>id est</small></h1>
<h1 align="center"></h1>
<h1 align="center">How to write a PolyGen grammar</h1>
<h2><br></h2>
<h2>Index</h2><b>1.0</b> <a href=
"#1.0_Cos%E8_una_grammatica">What is a grammar?</a><br>
<br>
<b> 1.0.1</b> <a href=
"#1.0.1_Sottoproduzioni">Subproductions</a><br>
<b> 1.0.2</b> <a href=
"#1.0.2_Sottoproduzioni_opzionali">Optional
subproductions</a><br>
<b> 1.0.3</b> <a href=
"#1.0.3_Commenti">Comments</a><br>
<br>
<br>
<b>2.0</b> <a href="#2.0_Caratteristiche_avanzate">Advanced
features</a><br>
<b> </b><b><br></b> <b>
</b><b>2.0.1</b> <a href=
"#2.0.1_Concatenazione">Concatenation</a><br>
<b> </b><b>2.0.2</b> <a href=
"#2.0.2_Epsilon">Epsilon</a><br>
<b> </b><b>2.0.3</b> <a href=
"#2.0.3_Controllo_della_probabilit%E0_di_una">Controlling the
probability of a production</a><br>
<b> </b><b>2.0.4</b> <a href=
"#2.0.4_Unfolding">Unfolding</a><br>
<br>
<b>2.0.4.1</b> <a href=
"#2.0.4.1_Di_simboli_non_terminali">Non-terminal symbols</a><br>
<b> 2.0.4.2</b> <a href=
"#2.0.4.2_Di_sottoproduzioni">Subproductions<br></a>
<b> </b>
<b>2.0.4.3</b> <a href=
"#2.0.4.3_Di_sottoproduzioni_opzionali">Optional
subproductions</a><br>
<b>2.0.4.4</b> <a href=
"#2.0.4.4_Di_sottoproduzioni_permutabili">Permutable
subproductions</a><br>
<b>
2.0.4.5</b> <a href="#2.0.4.5_Di_sottoproduzioni_soggette">Deeply
unfolded subproductions</a><br>
<b><br>
2.0.5</b> <a href=
"#2.0.5_Attributi">Attributes</a><br>
<b> <br>
2.0.5.1</b> <a href=
"#2.0.5.1_Etichette_e_selezione">Labels and selection</a><br>
<b> 2.0.5.2</b>
<a href="#2.0.5.2_Selezione_multipla">Multiple selection</a><br>
<br>
<b>2.0.6</b> <a href=
"#2.0.6_Maiuscole">Capitalization</a><br>
<b>2.0.7</b> <a href=
"#2.0.7_Permutazioni">Permutation</a><br>
<b> 2.0.8</b> <a href=
"#2.0.8_Unfolding_in_profondit%E0">Deep unfolding</a><br>
<b> 2.0.9</b> <a href=
"#2.0.9_Folding">Folding</a><br>
<br>
<br>
<b>2.1</b> <a href="#2.1_Tecniche_avanzate">Advanced
techniques</a><br>
<br>
<b> </b><b>2.1.1</b> <a href=
"#2.1.1_Ricorsione">Recursion</a><br>
<b> </b><b>2.1.2</b> <a href=
"#2.1.2_Ragruppamento">Grouping</a><br>
<b> </b><b>2.1.3</b> <a href=
"#2.1.3_Controllo_della_probabilt%E0_di_una">Controlling the
probabilty of an optional subproduction</a><br>
<b> </b><b>2.1.4</b> <a href=
"#2.1.4_Reset_di_una_selezione">Selection reset</a><br>
<br>
<br>
<b>3.0</b> <a href=
"#3.0_Controllo_statico_di_una_grammatica">Static checking of
grammars</a><br>
<br>
<b> </b><b>3.0.1</b> <a href=
"#3.0.1_Errori">Errors</a><br>
<br>
<b> </b><b> </b>
<b> 3.0.1.1</b> <a href=
"#3.0.1.1_Inesistenza_di_simboli_non">Undefined non-terminal
simbols</a><br>
<b> </b><b> </b>
<b> </b><b>3.0.1.2</b> <a href=
"#3.0.1.2_Ricorsioni_cicliche_e">Cyclic recursion and
non-termination</a><br>
<b> </b><b> </b>
<b> </b><b>3.0.1.3</b> <a href=
"#3.0.1.3_Unfolding_ricorsivi">Recursive unfolding</a><br>
<b> </b><b> </b>
<b> </b><b>3.0.1.4</b> <a href=
"#3.0.1.4_Epsilon-produzioni">Epsilon-productions</a><br>
<b>
</b><b>3.0.1.5</b> <a href=
"#3.0.1.5_Ridefinizione_di_simboli_non_terminali">Overriding of
non-terminal symbols</a><br>
<b>
3.0.1.6</b> <a href="#3.0.1.6_Carattere_sconosciuto">Illegal
character</a><br>
<b>
3.0.1.7</b> <a href="#3.0.1.7_Token_inaspettato">Unexpected
token</a><br>
<br>
<b> </b><b>3.0.2</b> <a href=
"#3.0.2_Warning">Warnings</a><br>
<br>
<b>3.0.2.0</b> <a href="#3.0.2.0_Livello_0">Level
0</a><br>
<br>
<b>3.0.2.1</b> <a href="#3.0.2.0_Livello_1">Level 1</a><br>
<br>
<b>
</b><b>3.0.2.1.1</b>
<a href="#3.0.2.1_Inesistenza_del_simbolo_I">Undefined symbol
<code>I</code></a><br>
<b> </b> <b>
</b> <b> </b> <b> 3.0.2.1.2</b> <a href=
"#3.0.2.2_Potenziali_epsilon-produzioni">Potential
epsilon-productions</a><br>
<br>
<b>3.0.2.2</b> <a href="#3.0.2.0_Livello_2">Level 2</a><br>
<b> <br>
3.0.2.2.1</b> <a href=
"#3.0.2.2_Permutazione_inutile">Useless permutation</a><a href=
"file:///home/manta/develop/polygen/0.8.1/ita/HOWTO-grm.html#3.0.2.2.1_Permutazione_inutile"></a><br>
<b>
</b> <b>3.0.2.2.2</b> <a href=
"#3.0.2.2.2_Potenziale_ricorsione_ciclica">Potential cyclic
recursion</a><b><br></b><br>
<br>
<b>4.0</b> <a href="#4.0_Appendice">Appendix</a><br>
<br>
<b> </b><b>4.1.1</b> <a href=
"#4.1.1_Sintassi_concreta">Concrete syntax</a><br>
<b> 4.1.2</b> <a href=
"#4.1.2_Sintassi_astratta">Abstract syntax</a><br>
<b> </b><b>4.1.3</b> <a href=
"#4.1.3_Regole_lessicali">Lexical rules</a><br>
<b> </b><b>4.1.4</b> <a href=
"#4.1.4_Caratteri_escape">Escape sequences</a><br>
<b>4.1.5</b> <a href=
"#4.1.5_Regole_di_traduzione">Translation rules</a><br>
<br>
<br>
<br>
<br>
<h2><a name="1.0_Cosè_una_grammatica" id=
"1.0_Cosè_una_grammatica"></a>1.0 What is a grammar?</h2>A
grammar is an ASCII text file providing the definition of the
syntactical structure and terms used by the program to build
sentences. <i>PolyGen</i> is able to interpret a language
designed for defining <i>type-2</i> grammars (according to
Chomsky classification) consisting in an extension of the <i>BNF
(Backus Naur Form)</i> - a very simple and common form for the
description of the syntax of a language.<br>
<br>
A definition consists in specifying for a given symbol a set of
productions interleaved by a <b>pipe</b> <font color=
"#CC0000"><code>|</code></font> and followed by a
<b>semicolon</b> <b><code><font color=
"#CC0000">;</font></code></b> , which acts as terminator:<br>
<br>
<b><samp>EXAMPLE</samp></b><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the apple <font color="#CC0000">|</font> an
orange <font color="#CC0000">;</font></code><br>
<br>
<br>
<b><samp>PRODUCES<br></samp></b> <code><br>
the apple<br>
an orange<br></code><br>
<br>
<br>
Such definition of symbol <code><font color=
"#996633">S</font></code> (said <b>non-terminal</b>) allows the
generation of symbols <code>the apple</code> as well as <code>an
orange</code> (said <b>terminal</b>).<br>
The probability for the output <code>the apple</code> to be
generated is equal to 1 every 3 times; and the same
for <code>an orange</code>: thus, when 2 productions occur,
we have 1 in 2 chances each; when 5 occur, we have 1 in 5,
etc.<br>
<br>
You're allowed to define several non-terminal symbols and
reference them from any productions, in order to let more complex
sentences be generated:<br>
<br>
<b><samp>EXAMPLE</samp></b><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the <font color="#996633">Animal</font> is
eating a <font color="#996633">Animal</font> <font color=
"#CC0000">;</font><br>
<br>
<font color="#996633">Animale</font> <font color=
"#CC0000">::=</font> cat <font color="#CC0000">|</font> dog
<font color="#CC0000">;</font></code><br>
<br>
<br>
<b><samp>PRODUCES<br></samp></b> <code><br>
the cat is eating a cat<br>
the cat is eating a dog<br>
the dog is eating a cat<br>
the dog is eating a dog</code><br>
<br>
ecc.<br>
<br>
<br>
<small><b>Note:</b> <i>PolyGen</i> uses by default the
non-terminal symbol <code><font color="#996633">S</font></code>
as the starting one: every grammar must therefore define it at
least unless another starting symbol has been specified as
argument to the program.<br></small><br>
By default, a term beginning with a capital letter is considered
as non-terminal (thus bound to a definition) and a term beginning
with a non-capital letter as terminal (a simple word). If you
need then to specify a capital word you must quote it in order to
get the program not to mistake it for a non-terminal symbol:<br>
<br>
<b><samp>EXAMPLE</samp></b><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> a <font color="#996633">Pet</font> called
"Pet" <font color="#CC0000">;</font><br>
<br>
<font color="#996633">Pet</font> <font color="#CC0000">::=</font>
cat <font color="#CC0000">|</font> pig <font color=
"#CC0000">|</font> dog <font color="#CC0000">;</font></code><br>
<br>
<br>
<b><samp>PRODUCES<br></samp></b> <code><br>
a cat called Pet<br>
a pig called Pet<br>
a dog called Pet</code><br>
<br>
<br>
Keep in mind that many characters (punctuation marks,
parentheses, etc), including those interpret as keywords by the
program, must be quoted to be output (see section <a href=
"#4.1.3_Regole_lessicali">4.1.3</a> for complete lexical
rules).<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> "(" <font color="#CC0000">(</font>apple
<font color="#CC0000">|</font> orange<font color=
"#CC0000">)</font> ")" <font color="#CC0000">;</font></code><br>
<br>
<br>
<samp><b>PRODUCES<br></b></samp> <code><br>
( apple )<br>
( orange )</code><br>
<br>
<br>
<br>
<h3><a name="1.0.1_Sottoproduzioni" id=
"1.0.1_Sottoproduzioni"></a> 1.0.1 Subproductions<br></h3>After
the keyword <font color="#CC0000"><code>::=</code></font> in a
definition, a subproduction of any form can be specified between
round brackets:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> an <font color=
"#CC0000">(</font></code><code>apple</code> <code><font color=
"#CC0000">|</font> orange</code><code><font color=
"#CC0000">)</font> is on the <font color=
"#CC0000">(</font></code><code>table</code> <code><font color=
"#CC0000">|</font></code> <code>desk</code><code><font color=
"#CC0000">)</font> <font color="#CC0000">;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>an apple is on the table<br>
an orange is on the table<br>
an apple is on the desk<br>
an orange is on the desk<br></code><br>
<br>
Subproductions are generated as standalone blocks, that is as
they were bound to a non-terminal symbol.<br>
<br>
<h3><a name="1.0.2_Sottoproduzioni_opzionali" id=
"1.0.2_Sottoproduzioni_opzionali"></a> 1.0.2 Optional
subproductions<br></h3>A subproduction specified between square
brakets is considered as optional and is generated 1 every 2
times, i.e. 50% probability:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> an <font color="#CC0000">(</font>apple
<font color="#CC0000">|</font> orange<font color=
"#CC0000">)</font> is on the <font color="#CC0000">(</font>table
<font color="#CC0000">|</font> desk<font color="#CC0000">)</font>
<font color="#CC0000">[</font>in the <font color=
"#CC0000">(</font>living <font color="#CC0000">|</font>
dining<font color="#CC0000">)</font> room<font color="#CC0000">]
;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>an apple is on the table<br>
an apple is on the table in the living room<br>
an apple is on the table in the dining room<br>
an orange is on the table<br>
an orange is on the table in the living room</code><code><br>
<br></code> ecc.<br>
<br>
<br>
Optional subproductions, apart from being generated once every
two times, behave as normal subproductions.<br>
<br>
<br>
<h3><a name="1.0.3_Commenti" id="1.0.3_Commenti"></a> 1.0.3
Comments<br></h3>You can write any kind of text within a pair of
<font color="#CC0000"><code>(*</code></font> and <font color=
"#CC0000"><code>*)</code></font> keywords. Such text will be
completely ignored by <i>PolyGen.</i><br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> apple <font color="#CC0000">|</font> rainge
<font color="#666666">(* | banana *)</font> <font color=
"#CC0000">|</font> mango <font color="#CC0000">;</font><br>
<font color="#666666">(* this is comment too *)</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>apple<br>
orange<br>
mango<br>
<br>
<br>
<br>
<br></code>
<h2><a name="2.0_Caratteristiche_avanzate" id=
"2.0_Caratteristiche_avanzate"></a>2.0 Advanced
features<br></h2><i>PolyGen</i> provides a set of keywords that
raises the language expressivity beyond <i>BNF.</i><br>
<br>
<br>
<h3><a name="2.0.1_Concatenazione" id=
"2.0.1_Concatenazione"></a>2.0.1 Concatenation<br></h3>The
<b>cap</b> <font color="#CC0000"><code>^</code></font> can be
either prefixed or suffixed to as well as infixed in any point
within a production in order to make the program not insert a
white space character in the output string:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> "(" <font color="#CC0000">^ (</font>apple
<font color="#CC0000">|</font> orange<font color="#CC0000">)
^</font> ")" <font color="#CC0000">;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>(apple)<br>
(orange)<br>
<br></code><br>
Concatenation, as a feature, is particularly useful every time
you wish to generate words by assembling syllabes or letters
coming from different productions:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> "I" <font color="#996633">Verb <font color=
"#CC0000">^</font></font> e <font color="#996633">Verb
<font color="#CC0000">^</font></font> <font color=
"#996633">ing</font> <font color="#CC0000">;</font><br>
<br>
<font color="#996633">Verb</font> <font color=
"#CC0000">::=</font> lov <font color="#CC0000">|</font> hat
<font color="#CC0000">;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>I love hating<br>
I love loving<br>
I hate hating<br>
I hate loving</code><code><br>
<br></code><br>
Keep in mind that specifying many caps is perfectly equal to
specifying one only.<br>
<br>
<br>
<br>
<h3><a name="2.0.2_Epsilon" id="2.0.2_Epsilon"></a> 2.0.2
Epsilon<br></h3>The <b>underscore</b> keyword <font color=
"#CC0000"><code>_</code></font> stands for the empty production,
formally called <i>epsilon</i>.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> ball <font color="#CC0000">| _ ;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>ball<br>
<font color="#CC0000">_</font><br></code><br>
<br>
Notice that an epsilon-production is neither the underscore
character itself nor the white space, rather it stands for no
output at all - the empty string, if you prefer. The former
example is perfectly equivalent to the following:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color=
"#CC0000">[</font>palla<font color="#CC0000">] ;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>palla<br>
<font color="#CC0000">_</font><br></code><br>
<br>
That is a grammar generating either <code>a</code> or nothing as
output.<br>
<br>
<br>
<br>
<h3><a name="2.0.3_Controllo_della_probabilità_di_una" id=
"2.0.3_Controllo_della_probabilità_di_una"></a> 2.0.3 Controlling
the probability of a production<br></h3>The <b>plus</b> keyword
<font color="#CC0000"><code>+</code></font> , when prefixed to a
(sub)production (however nested), raises the probability for it
to be generated, in respect to the others of that very series;
simmetrically, the <b>minus</b> keyword <font color=
"#CC0000"><code>-</code></font> lowers it down. Any number
of <font color="#CC0000"><code>+</code></font> and
<font color="#CC0000"><code>-</code></font> keywords may be
specified:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the cat is eating <font color=
"#CC0000">(+</font> an apple <font color="#CC0000">|-</font> an
orange <font color="#CC0000">|</font> some meat <font color=
"#CC0000">|--</font> a lemon<font color="#CC0000">)
;</font><br></code><br>
<br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>the cat is eating an apple<br>
the cat is eating an orange<br>
the cat is eating some meat<br>
the cat is eating a lemon</code> <code><br>
<br>
<br></code><br>
The set of sentences that can be produced is as expected; indeed,
the definition for the non-terminal symbol <code><font color=
"#996633">S</font></code> is internally interpretet as
follows:<br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the cat is eating <font color=
"#CC0000">(</font> an apple <font color="#CC0000">|</font> an
apple <font color="#CC0000">|</font> an apple <font color=
"#CC0000">|</font> an apple<br>
<font color="#CC0000">
|</font> an orange
<font color="#CC0000">|</font> an orange<br>
<font color="#CC0000">
|</font> some meat
<font color="#CC0000">|</font> some meat <font color=
"#CC0000">|</font> some meat<br>
<font color="#CC0000">
|</font> a
lemon<font color="#CC0000">) ;</font><br>
<br></code><br>
as requested, proportion of probabilty raising and lowering
holds: the probability for <code>an apple</code> to be
generated is higher than <code>an orange</code>, which is
higher that <code>some meat</code>, on its turn higher
than <code>a lemon</code>.<br>
<br>
<br>
<br>
<br>
<h3><a name="2.0.4_Unfolding" id="2.0.4_Unfolding"></a> 2.0.4
Unfolding</h3><i>PolyGen</i> provides a powerful unfolding system
which, in general, allows to take a series of productions
(otherwise folded either by a subproduction or a non-terminal
symbol) to the level of the current sequence.<br>
Roughly, you may look at this operation as at the
<i>flattening</i> of a portion of grammar that is performed
before the generation and that may thus affect it just as far as
the probability are concerned, since the transformation does not
alter the source grammar semantics - as the traslation rules in
section <a href="#4.1.5_Regole_di_traduzione">4.1.5</a>
confirm.<br>
<br>
Not every atom though supports unfolding, rather only those which
such operation makes sense for: refer to section <a href=
"#4.1.1_Sintassi_concreta">4.1.1</a> for a syntactical
formalization of such subset.<br>
<br>
<h4><a name="2.0.4.1_Di_simboli_non_terminali" id=
"2.0.4.1_Di_simboli_non_terminali"></a> 2.0.4.1 Non-terminal
symbols</h4>Consider the following scenario:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> ugly cat <font color="#CC0000">|</font> nice
<font color="#996633">Animal</font> <font color=
"#CC0000">;</font><br>
<br>
<font color="#996633">Animal</font> <font color=
"#CC0000">::=</font> dog <font color="#CC0000">|</font> bull
<font color="#CC0000">|</font> pig <font color=
"#CC0000">;</font><br>
<br>
<br></code> <samp><b>PRODUCES</b></samp><br>
<br>
<code>ugly cat<br>
nice dog<br>
nice bull<br>
nice pig<br>
<br></code><br>
Produced output deserves no surprises, still the chance for
<code>ugly cat</code> to be generated is 1 every 2 times, but it
is not the same for <code>nice dog</code>, <code>nice bull</code>
and <code>nice pig</code>, even though a user may find it
reasonable for all them to be generated with the same
probability.<br>
The problem is due to productions <code>ugly cat</code> and
<code>nice <font color="#996633">Animal</font></code> equally
sharing the unit of prabability of <code><font color=
"#996633">S</font></code>: thus the chances for <code>ugly
cat</code> to be generated is equal to the chances
for <code>nice <font color="#996633">Animal</font></code>,
i.e. one among <code>nice dog</code>, <code>nice bull</code>
and <code>nice pig</code>. In the example above the probability
distribution appears as follows:<br>
<br>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#CCCCCC">
<tbody>
<tr>
<td><code>ugly cat</code><br></td>
<td>1/2</td>
</tr>
<tr>
<td><code>nice dog</code><br></td>
<td>1/2 * 1/3 = 1/6</td>
</tr>
<tr>
<td><code>nice bull</code><br></td>
<td>1/2 * 1/3 = 1/6</td>
</tr>
<tr>
<td><code>nice pig</code><br></td>
<td>1/2 * 1/3 = 1/6</td>
</tr>
</tbody>
</table><br>
<br>
As a proof, 1/2 + 1/6 + 1/6 + 1/6 = 1.<br>
<br>
In order to equally redistribute prababilities of subproductions,
the user should write <code><font color="#996633">S</font></code>
this way:<br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> ugly cat <font color="#CC0000">|</font> nice
dog <font color="#CC0000">|</font> nice bull <font color=
"#CC0000">|</font> nice pig <font color=
"#CC0000">;</font></code><br>
<br>
though loosing the original architecture, which used to fold all
animals within a non-terminal symbol, and moreover dramatically
increasing the amount of editing duties.<br>
In order to solve this problem, itself an instance of the
dishomogeneity of probability distribution problem in case of
subproductions, the language offers an operator for
<b>unfolding</b> non-terminal symbols:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> ugly cat <font color="#CC0000">|</font>
nice</code> <code><font color=
"#CC0000">></font></code><code><font color=
"#996633">Animal</font> <font color="#CC0000">;</font><br>
<br>
<font color="#996633">Animal</font> <font color=
"#CC0000">::=</font> dog <font color="#CC0000">|</font> bull
<font color="#CC0000">|</font> pig <font color=
"#CC0000">;</font></code><br>
<br>
<br>
Prefixing the <font color="#CC0000"><code>></code></font>
keyword to a non-terminal symbol, during the preprocessing phase
the program performs the translation above, changing the
probability distribution as follows:<br>
<br>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#CCCCCC">
<tbody>
<tr>
<td><code>ugly cat</code><br></td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice dog</code><br></td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice bull</code><br></td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice pig</code><br></td>
<td>1/4</td>
</tr>
</tbody>
</table><br>
<br>
<br>
<h4><a name="2.0.4.2_Di_sottoproduzioni" id=
"2.0.4.2_Di_sottoproduzioni"></a> 2.0.4.2
Subproductions<br></h4>It is not uncommon to use subproductions
in order to decrease grammar verbosity, e.g. by collecting a set
of phrasal verbs according to the supported preposition.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">(</font>walk</code>
<code><font color="#CC0000">|</font></code>
<code>pass<font color="#CC0000">)</font> through<br>
</code><code><font color="#CC0000">|</font></code>
<code> look at<br>
</code><code><font color="#CC0000">|</font></code>
<code> </code><code><font color=
"#CC0000">(</font></code><code>go </code><code><font color=
"#CC0000">|</font></code>
<code>come </code><code><font color=
"#CC0000">|</font></code>
<code>move </code><code><font color=
"#CC0000">|</font></code>
<code>link </code><code><font color=
"#CC0000">|</font></code> <code>run</code><code><font color=
"#CC0000">)</font></code> <code>to</code> <code><font color=
"#CC0000">;</font></code><br>
<br>
<br>
Grammar architecture and scalability increase, on one side,
while, on the other side, output quality lowers down, since 1
every 3 times <code>look at</code> will be generated for the same
reason discussed in section <a href=
"#2.0.4.1_Di_simboli_non_terminali">2.0.4.1</a>. In order to take
output etherogeneity to the desired level, that is where each
single verb may be produced with the same probability, the user
should avoid round bracket usage at all, so that there would be
no more 3 macro-productions, and should suffix the proper
preposition to each verb.<br>
For this very purpose, any subproduction may be <b>unfolded</b>
analogously to what stated in section <a href=
"#2.0.4.1_Di_simboli_non_terminali">2.0.4.1</a> regarding
non-terminal symbols. The operator <font color=
"#CC0000"><code>></code></font> makes the program delegate to
the preprocessor the unfolding of the following subproduction,
allowing the user to keep the original source architecture
unchanged.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color=
"#CC0000">>(</font>walk</code> <code><font color=
"#CC0000">|</font></code> <code>pass<font color=
"#CC0000">)</font> through<br>
</code><code><font color="#CC0000">|</font></code>
<code> look at<br>
</code><code><font color="#CC0000">|</font></code>
<code> </code><code><font color=
"#CC0000">>(</font></code><code>go </code><code><font color="#CC0000">|</font></code>
<code>come </code><code><font color=
"#CC0000">|</font></code>
<code>move </code><code><font color=
"#CC0000">|</font></code>
<code>link </code><code><font color=
"#CC0000">|</font></code> <code>run</code><code><font color=
"#CC0000">)</font></code> <code>to</code> <code><font color=
"#CC0000">;</font></code><br>
<br>
<br>
is translated into:<br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> walk through</code> <code><font color=
"#CC0000">|</font></code><code>pass through<br>
</code><code><font color="#CC0000">|</font></code>
<code> look at<br>
</code><code><font color="#CC0000">|</font></code>
<code> </code><code>go to</code> <code><font color=
"#CC0000">|</font></code> <code>come to</code> <code><font color=
"#CC0000">|</font></code> <code>move to</code> <code><font color=
"#CC0000">|</font></code> <code>link to</code> <code><font color=
"#CC0000">|</font></code> <code>run</code> <code>to</code>
<code><font color="#CC0000">;</font></code><br>
<br>
<br>
that is what one would expect: a flat series of productions.<br>
<br>
A more complex example could be:<br>
<br>
<code><font color="#996633">Digit</font> <font color=
"#CC0000">::=</font> <font color="#3333FF">z:</font> 0
<font color="#CC0000">|</font> <font color="#3333FF">nz:</font>
<font color="#CC0000">>(</font></code><code>1 <font color=
"#CC0000">|</font> 2 <font color="#CC0000">|</font> 3
<font color="#CC0000">|</font> 4 <font color="#CC0000">|</font> 5
<font color="#CC0000">|</font> 6 <font color="#CC0000">|</font> 7
<font color="#CC0000">|</font> 8 <font color="#CC0000">|</font>
9<font color="#CC0000">) ;</font></code><br>
<br>
is translated into:<br>
<br>
<code><font color="#996633">Digit</font> <font color=
"#CC0000">::=</font> <font color="#3333FF">z:</font> 0
<font color="#CC0000">|</font> <font color=
"#3333FF">nz:</font></code> <code>1 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>2 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>3 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>4 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>5 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>6<br>
<font color=
"#CC0000">| </font></code> <code><font color=
"#3333FF">nz:</font></code> <code>7 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>8 <font color=
"#CC0000">|</font></code> <code><font color=
"#3333FF">nz:</font></code> <code>9 <font color=
"#CC0000">;</font></code><br>
<br>
<br>
<h4><a name="2.0.4.3_Di_sottoproduzioni_opzionali" id=
"2.0.4.3_Di_sottoproduzioni_opzionali"></a> 2.0.4.3 Optional
subproductions</h4>A subproduction in square brackets (see
section <a href="#1.0.2_Sottoproduzioni_opzionali">1.0.2</a>) is
equal to a subproduction in round brackets that produces either
the original content or <b>epsilon</b> (see the example in
section <a href=
"#2.1.3_Controllo_della_probabilt%E0_di_una">2.1.3</a>).<br>
Thus, <b>unfolding</b> an optional subproduction is perfectly
legal and the result is analogous to what said in section
<a href="#2.0.4.2_Di_sottoproduzioni">2.0.4.2</a>.<br>
<br>
<br>
<h4><a name="2.0.4.4_Di_sottoproduzioni_permutabili" id=
"2.0.4.4_Di_sottoproduzioni_permutabili"></a> 2.0.4.4 Permutable
subproductions</h4>As the translation rules in section <a href=
"#4.1.5_Regole_di_traduzione">4.1.5</a> reveal, the unfolding is
performed by the preprocessor after all the permutations (see
section <a href="#2.0.7_Permutazioni">2.0.7</a>) occured: a
permutable subproduction bound to a <font color=
"#CC0000"><code>></code></font> operator is therefore first
permutated, while the <b>unfolding</b> holds and is then
performed at the new position within the sequence.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">>{</font>the
<font color="#CC0000">>(</font>dog <font color=
"#CC0000">|</font> cat<font color="#CC0000">)}</font> and</code>
<code><font color="#CC0000">{</font></code><code>a</code>
<code><font color="#CC0000">(</font></code><code>fish</code>
<code><font color="#CC0000">|</font></code>
<code>bull</code><code><font color="#CC0000">)}</font></code>
<code><font color="#CC0000">;</font></code><br>
<br>
<br>
Pay attention to how the two unfoldings, the former inside the
curly brackets and the latter outside, behave: the translation is
as follows:<br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the dog and a</code> <code><font color=
"#CC0000">(</font></code><code>fish</code> <code><font color=
"#CC0000">|</font></code> <code>bull</code><code><font color=
"#CC0000">)</font></code><br>
<code> </code><code><font color=
"#CC0000">|</font></code> <code> the cat and
a </code><code><font color=
"#CC0000">(</font></code><code>fish</code> <code><font color=
"#CC0000">|</font></code> <code>bull</code><code><font color=
"#CC0000">)</font></code><br>
<code> </code><code><font color=
"#CC0000">|</font></code>
<code> </code>a <code><font color=
"#CC0000">(</font></code><code>fish</code> <code><font color=
"#CC0000">|</font></code> <code>bull</code><code><font color=
"#CC0000">)</font></code> <code>and the dog<br>
</code><code><font color="#CC0000">|</font></code>
<code> </code>a <code><font color=
"#CC0000">(</font></code><code>fish</code> <code><font color=
"#CC0000">|</font></code> <code>bull</code><code><font color=
"#CC0000">)</font></code> <code>and the cat</code>
<code><font color="#CC0000">;</font></code><br>
<br>
<br>
<h4><a name="2.0.4.5_Di_sottoproduzioni_soggette" id=
"2.0.4.5_Di_sottoproduzioni_soggette"></a> 2.0.4.5 Deeply
unfolded subproductions</h4>As stated in section <a href=
"#2.0.8_Unfolding_in_profondit%E0">2.0.8</a>, deep unfolding
leads to a subproduction where everything has been flattened
within.<br>
Though, one may sometimes wish to perform a further
<b>unfolding</b>: of that very subproduction.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> </code> <code><font color=
"#CC0000">> >></font> the</code> <code><font color=
"#CC0000">(</font></code><code>dog</code> <code><font color=
"#CC0000">|</font></code> <code>cat</code><code><font color=
"#CC0000">)</font></code> <code><font color="#CC0000">|</font> a
<font color="#CC0000">(</font>fish <font color="#CC0000">|</font>
bull<font color="#CC0000">) << |</font> an alligator
<font color="#CC0000">;</font></code><br>
<br>
<br>
that is translated into:<br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> the dog</code> <code><font color=
"#CC0000">|</font></code> <code>the cat</code> <code><font color=
"#CC0000">|</font></code> <code>a fish</code> <code><font color=
"#CC0000">|</font></code> <code>a bull</code> <code><font color=
"#CC0000">|</font></code> <code>an alligator</code>
<code><font color="#CC0000">;</font></code><br>
<br>
<br>
<br>
<br>
<h3><a name="2.0.5_Attributi" id="2.0.5_Attributi"></a> 2.0.5
Attributes<br></h3>
<h4><a name="2.0.5.1_Etichette_e_selezione" id=
"2.0.5.1_Etichette_e_selezione"></a> 2.0.5.1 Labels and
selection<br></h4>Any (sub)production, however nested, can be
bound to a label and it is eventually possible to limit
generation to a subset of a series of productions by using the
<b>dot</b> operator.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color=
"#996633">Verb</font><font color="#339999">.inf</font>
<font color="#CC0000">|</font> <font color=
"#996633">Verb</font><font color="#339999">.ing</font>
<font color="#CC0000">;</font><br>
<br>
<font color="#996633">Verb</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">(</font><font color=
"#3333FF">inf:</font> to<font color="#CC0000">) (</font>eat
<font color="#CC0000">|</font> drink <font color=
"#CC0000">|</font> jump<font color="#CC0000">)
(</font><font color="#3333FF">ing:</font> <font color=
"#CC0000">^</font>ing<font color="#CC0000">) ;</font><br>
<br></code><br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>to eat<br>
to drink<br>
to jump<br>
eating<br>
drinking<br>
jumping<br></code> <code><br></code><br>
Selection simply deletes all (sub)productions bound to a label
other than the one selected. More precisely, a selection
propagates the label specified on the right hand of the dot
operator for the whole generation of what stands on the left of
it; during the generation will be considered as valid both those
(sub)productions that are bound to no label and those bound to a
label that has been selected.<br>
Notice therefore that you're allowed to use selection many times
in order to enrich the list of selected labels: such a technique
may be useful for propagating some attributes that are wanted to
affect generation.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">(</font><font color=
"#996633">Conjug</font><font color="#339999">.S</font>
<font color="#CC0000">|</font> <font color=
"#996633">Conjug</font><font color=
"#339999">.P</font><font color="#CC0000">)</font><font color=
"#339999">.sp</font> <font color=
"#CC0000">|</font> </code><code><font color=
"#CC0000">(</font><font color="#996633">Conjug</font><font color=
"#339999">.S</font> <font color="#CC0000">|</font> <font color=
"#996633">Conjug</font><font color=
"#339999">.P</font><font color="#CC0000">)</font><font color=
"#339999">.pp</font></code> <code><font color=
"#CC0000">;</font><br>
<br>
<font color="#996633">Conjug</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">(</font><font color=
"#996633">Pronoun</font> <font color=
"#996633">Verb</font><font color="#CC0000">)</font><font color=
"#339999">.1</font> <font color=
"#CC0000">|</font> </code><code><font color=
"#CC0000">(</font><font color="#996633">Pronoun</font>
<font color="#996633">Verb</font><font color=
"#CC0000">)</font><font color="#339999">.2</font> <font color=
"#CC0000">|</font></code> <code><font color=
"#CC0000">(</font><font color="#996633">Pronoun</font>
<font color="#996633">Verb</font><font color=
"#CC0000">)</font><font color="#339999">.3</font></code>
<code><font color="#CC0000">;</font><br>
<br>
<font color="#996633">Pronoun</font> <font color=
"#CC0000">::=</font> <font color="#3333FF">S:</font> <font color=
"#CC0000">(</font><font color="#3333FF">1:</font> "I"
<font color="#CC0000">|</font> <font color="#3333FF">2:</font>
you <font color="#CC0000">|</font> <font color=
"#3333FF">3:</font> <font color="#CC0000">(</font>he <font color=
"#CC0000">|</font> she <font color="#CC0000">|</font>
it<font color="#CC0000">)</font><font color=
"#CC0000">)</font><br>
<font color="#CC0000">
| </font> <font color=
"#3333FF">P:</font> </code><code><font color=
"#CC0000">(</font><font color="#3333FF">1:</font> we <font color=
"#CC0000">|</font> <font color="#3333FF">2:</font> you
<font color="#CC0000">|</font> <font color="#3333FF">3:</font>
they<font color="#CC0000">)</font></code> <code><font color=
"#CC0000">;</font><br>
<br>
<font color="#996633">Verb</font> <font color=
"#CC0000">::=</font> <font color="#CC0000">(</font><font color=
"#3333FF">pp:</font> <font color="#996633">Be</font><font color=
"#CC0000">)</font> <font color="#CC0000">(</font>eat <font color=
"#CC0000">|</font> drink<font color="#CC0000">)
(</font><font color="#3333FF">sp:</font></code>
<code><font color="#CC0000">(</font><font color=
"#3333FF">S:</font> (<font color="#3333FF">3:</font> <font color=
"#CC0000">^</font>s<font color="#CC0000">))</font> <font color=
"#CC0000">|</font> <font color="#3333FF">pp:</font> <font color=
"#CC0000">^</font>ing<font color="#CC0000">)
;</font></code><code><br>
<br>
<font color="#996633">Be</font> <font color="#CC0000">::=</font>
<font color="#3333FF">S:</font> <font color=
"#CC0000">(</font><font color="#3333FF">1:</font> am <font color=
"#CC0000">|</font> <font color="#3333FF">2:</font> are
<font color="#CC0000">|</font> <font color="#3333FF">3:</font>
is<font color="#CC0000">)</font> <font color="#CC0000">|</font>
<font color="#3333FF">P:</font> are <font color=
"#CC0000">;</font></code><br>
<br>
<br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>I eat<br>