4
== ʸˡ�˴ؤ������С������Ȥ���ߴ�
6
* (1.2.5) �桼���������ɤ�Ϣ�뤹����������ե��������
7
��ᤳ��Ǥ��륳���ɤ����Ϣ�뤷�ޤ���
8
* (1.1.6) �������ǥ��쥯�ƥ��� options ���ɲä���ޤ�����
9
* (1.1.5) ͽ��� token �ΰ�̣���ѹ��ˤʤ�ޤ�����
10
* (0.14) �롼��κǸ�Υ��ߥ�����ά��ǽ�ˤʤ�ޤ�����
11
�ޤ���token prechigh �ʤɤ�ͽ���Ǥʤ��ʤ�ޤ�����
12
* (10.2) prepare �� header �� driver �� footer �ˤʤ�ޤ�����
13
���Ϥ��ΤޤޤǤ�Ȥ��ޤ�����2.0 ������б����ޤ���
14
* (0.10) class ���б����� end ���ʤ��ʤ�ޤ�����
15
* (0.9) ���������Υԥꥪ����������� { �� } �ǰϤ�褦�ˤ��ޤ�����
19
�ȥåץ�٥�ϡ���§���ȥ桼��������������ʬ�����ޤ���
20
�桼�������������ϥ��饹����θ����ʤ���Ф����ޤ���
24
ʸˡ�ե�����ˤϡ������㳰������ơ��ۤȤ�ɤɤ��ˤǤ⥳���Ȥ�
25
���Ȥ��Ǥ��ޤ��������Ȥϡ�Ruby�� #.....(����) ��������ȡ�
26
C�� /*......*/ ���������Ȥ����Ȥ��Ǥ��ޤ���
30
��§���ϰʲ��Τ褦�ʷ��Ƥ��ޤ���
32
class ���饹̾ [< �����ѡ����饹]
42
"���饹̾"�Ϥ������������ѡ������饹��̾���Ǥ���
43
����Ϥ��Τޤ�Ruby�Υ��饹̾�ˤʤ�ޤ���
45
�ޤ� M::C �Τ褦�ˡ�::�פ�Ȥä�̾����Ȥ��ȡ����饹�����
46
�⥸�塼�� M ����˥ͥ��Ȥ����ޤ����Ĥޤ� class M::C �ʤ��
49
class C < Racc::Parser
56
����ˡ�Ruby ��Ʊ����ʸ�ǥ����ѡ����饹�����Ǥ��ޤ���
57
���������λ����ȥѡ�����ư��˽���ʱƶ���Ϳ����Τǡ�
58
�ä�ɬ�פ��ʤ��¤���ꤷ�ƤϤ����ޤ�����Ͼ���γ�ĥ��
59
������Ѱդ�����Τǡ������ꤹ��ɬ�����Ϥ��ޤꤢ��ޤ���
63
racc ����������ѡ���������Ǥ���ʸˡ�Ҥ��ޤ���
64
ʸˡ�ϡ�ͽ��� rule �� end �δ֤ˡ��ʲ��Τ褦�ʽǽޤ���
66
�ȡ�����: �ȡ�������¤� ���������
68
�ȡ�����: �ȡ�������¤� ���������
69
| �ȡ�������¤� ���������
70
| �ȡ�������¤� ���������
73
���������� { } �ǰϤߤޤ������������Ǥ� Ruby ��ʸ�ϤۤȤ��
74
�Ȥ��ޤ������������������б��Ǥ����б����Ƥ��ʤ���Τϰʲ��ΤȤ��ꡣ
77
* =begin ... =end ��������
79
* �����ޤ�� % �α黻�����̤˱黻�ҤΤޤ��˥��ڡ���������Ƥ��������ʤ�
81
���Τ�����˴ؤ��Ƥϴ������б��Ϥޤ�̵���Ǥ����������Ƥ���������
83
���դ���($$)�ϡ����ץ����ˤ�ä��֤����������ޤ����ޤ��ǥե���ȤǤ�
84
���������ѿ� result (���Υǥե�����ͤ� val[0])�� �����ͤ�ɽ�������������
85
�֥��å���ȴ�������� result ���ͤ������ͤˤʤ�ޤ����ޤ�������Ū�� return
86
���֤������⤳���ͤˤʤ�ޤ���������options �� no_result_var ����ꤷ��
87
��硢�����ͤϥ��������֥��å��κǸ��ʸ���ͤˤʤ�ޤ� (Ruby �Υ�åɤ�
90
�ɤ���ξ��Ǥ⥢�������Ͼ�ά�Ǥ�����ά�������κ����ͤϾ�� val[0] �Ǥ���
92
�ʲ���ʸˡ���Ҥ����Τ���ᤷ�ޤ���
109
precrule # ����Ͼ�ιԤ�³��
115
�����������Ǥ����̤ʰ�̣���ä��ѿ��������Ĥ��Ȥ��ޤ���
116
���Τ褦���ѿ���ʲ��˼����ޤ�����̤���� yacc �Ǥ�ɽ���Ǥ���
120
���դ��͡�����ͤ� val[0] �Ǥ���
124
���դε�����ͤ�����Ruby ������ʤΤ���������ǥå����ϥ�������Ϥޤ�ޤ���
125
����������������ΤǼ�ͳ���ѹ�������ΤƤ��ꤷ�ƹ����ޤ���
127
* _values (...,$-2,$-1,$0)
129
�ͥ����å���Racc �������ȤäƤ��륪�֥������Ȥ����Τޤ��Ϥ���ޤ���
130
�����ѿ��ΰ�̣���狼��Ͱʳ���<em>���Ф�</em>�ѹ����ƤϤ����ޤ���
132
�ޤ��������������̤ʷ����ˡ���ᤳ�ߥ��������Ȥ�����Τ�����ޤ���
133
����ϥȡ������������ι����ʤȤ����˵��Ҥ��뤳�Ȥ��Ǥ��ޤ���
134
�ʲ�����ᤳ�ߥ�������������ޤ���
136
target: A B { puts 'test test' } C D { normal action }
138
���Τ褦�˵��Ҥ���� A B �Ф��������� puts ���¹Ԥ���ޤ���
139
�ޤ�����ᤳ�ߥ��������Ϥ��켫�Τ��ͤ�����ޤ����Ĥޤꡢ�ʲ�����ˤ�����
141
target: A { result = 1 } B { p val[1] }
143
�Ǹ�ˤ��� p val[1] ����ᤳ�ߥ����������� 1 ��ɽ�����ޤ���
146
��̣Ū�ˤϡ���ᤳ�ߥ��������϶��ε�§�������ü������ɲä��뤳�Ȥ�
147
����Ʊ��Ư���ޤ����Ĥޤꡢ�����ϼ��Υ����ɤȴ�����Ʊ����̣�Ǥ���
149
target : A nonterm B { p val[1] }
150
nonterm : /* ���� */ { result = 1 }
155
����ȡ������ǥ��եȡ��Ը����ͤ������ä��Ȥ������Υȡ������
156
�黻��ͥ���̤����ꤷ�Ƥ���Ⱦ��ͤ��äǤ����礬����ޤ���
157
���Τ褦�ʤ�ΤȤ����ä�ͭ̾�ʤΤϿ����α黻�Ҥ� if...else ��ʸ�Ǥ���
159
ͥ���̤Dz��Ǥ���ʸˡ�ϡ����ޤ�ʸˡ�ߤ����Ƥ���
160
ͥ���̤ʤ��Ǥ�Ʊ�����̤����뤳�Ȥ��Ǥ��ޤ��������������Ƥ���
161
����ͥ���̤����ꤷ�Ʋ�褹��ۤ���ʸˡ���ñ�ˤǤ��ޤ���
163
���եȡ��Ը����ͤ������ä��Ȥ���Racc �Ϥޤ����ε�§�˽�̤�����
164
����Ƥ��뤫Ĵ�٤ޤ�����§�ν�̤ϡ����ε�§�ǰ��֤������ˤ���
165
��ü�ȡ������ͥ���̤Ǥ������Ȥ���
167
target: TERM_A nonterm_a TERM_B nonterm_b
169
�Τ褦�ʵ�§�ν�̤�TERM_B��ͥ���̤ˤʤ�ޤ����⤷TERM_B��
170
ͥ���̤����ꤵ��Ƥ��ʤ��ä��顢ͥ���̤Ǿ��ͤ��褹�뤳�Ȥ�
171
�Ǥ��ʤ���Ƚ�Ǥ�����Shift/Reduce conflict�פ���𤷤ޤ���
173
�黻�Ҥ�ͥ���̤ϤĤ��Τ褦�˽�������ޤ���
182
prechigh �˶ᤤ�Ԥˤ���ۤ�ͥ���̤ι⤤�ȡ�����Ǥ����岼��ޤ뤴��
183
�������ޤˤ��� preclow...prechigh �ν��֤˽��Ȥ�Ǥ��ޤ���left
184
�ʤɤ�ɬ���Ԥκǽ�ˤʤ���Ф����ޤ���
186
left right nonassoc �Ϥ��줾��ַ�����פ�ɽ���ޤ���������ˤ�äơ�
187
Ʊ����̤α黻�Ҥε�§�����ͤ������˥��եȴԸ��Τɤ����Ȥ뤫��
196
�ˤʤ�Τ������ (left) �Ǥ�����§�黻�����̤���Ǥ���
201
�ˤʤ�Τ������ (right) �Ǥ��������Υ������Ȥ����� right �Ǥ���
202
�ޤ����Τ褦�˱黻�Ҥ��Ťʤ�Τϥ��顼�Ǥ����硢���� (nonassoc) �Ǥ���
203
C ����� ++ ��ñ��Υޥ��ʥ��ʤɤ�����ˤ�����ޤ���
205
�Ȥ����ǡ����������Ȥ����̾�ϴԸ����뵬§�κǸ�Υȡ�����̤�
206
����ΤǤ��������뵬§�˸¤äƤ��Υȡ�����Ȥϰ㤦��̤ˤ��������Ȥ�
207
����ޤ����㤨�����ȿž�Υޥ��ʥ��ϰ������Υޥ��ʥ�����̤�⤯
208
���ʤ��Ȥ����ޤ����Τ褦�ʾ�� yacc �Ǥ� %prec ��Ȥ��ޤ���
209
racc �Ǥϥ������뵭���Ȥä�Ʊ�����Ȥ�Ǥ��ޤ���
219
| '-' exp = UMINUS # ����������̤�夲��
221
���Τ褦�˵��Ҥ���ȡ�'-' exp �ε�§�ν�̤� UMINUS �ν�̤ˤʤ�ޤ���
222
�������뤳�Ȥ����ȿž�� '-' �� '*' �����̤��⤯�ʤ�Τǡ�
227
�ȡ�����(��ü����)�ΤĤŤ��ְ㤨��Ȥ����ΤϤ褯���뤳�ȤǤ�����
228
ȯ������ΤϤʤ��ʤ�����ΤǤ���1.1.5 ����ϥȡ����������Ū��
229
������뤳�Ȥǡ�����ˤʤ��ȡ����� / ����ˤ�������ȡ�������Ф���
230
�ٹ𤬽Ф�褦�ˤʤ�ޤ�����yacc �� %token �Ȼ��Ƥ��ޤ�������ΰ㤤��
231
racc �Ǥ�ɬ�ܤǤϤʤ��������⥨�顼�ˤʤ餺�ٹ�������Ȥ������Ǥ���
233
�ȡ���������ϰʲ��Τ褦�˽ޤ���
238
�ȡ�����Υꥹ�Ȥ�ʣ���Ԥˤ錄�äƽ뤳�Ȥ����ܤ��Ƥ���������
239
racc �Ǥϰ��̤ˡ�ͽ���פϹԤ���Ƭ���褿������ͽ���Ȥߤʤ����Τ�
240
prechigh �ʤɤ⥷��ܥ�Ȥ��ƻȤ��ޤ�����������ʥ����ͳ���� end ������
241
�ɤ���äƤ�ͽ���ˤʤäƤ��ޤ��ޤ���
245
racc �Υ��ޥ�ɥ饤�ץ����ΰ�����ե�������˥ǥե������
246
�Ȥ��Ƶ��Ҥ��뤳�Ȥ��Ǥ��ޤ���
248
options ���ץ���� ���ץ���� ��
254
���Υ��������ƤӽФ����ά����
261
���줾�� no_ ��Ƭ�ˤĤ��뤳�Ȥǰ�̣��ȿž�Ǥ��ޤ���
265
���Ѥˤʤ�ѡ����Ϥ����Ƥ�̵���� shift/reduce conflict ��ޤߤޤ���
266
������ʸˡ�ե��������ܿͤϤ�����ΤäƤ��뤫�餤���Ǥ�����
267
�桼����ʸˡ�ե����������������ˡ�conflict�פ�ɽ�����줿��
268
�¤˻פ��Ǥ��礦�����Τ褦�ʾ�硢�ʲ��Τ褦�˽Ƥ�����
269
shift/reduce conflict �Υ�å������������Ǥ��ޤ���
273
���ξ�� shift/reduce conflict �ϤԤä��껰�ĤǤʤ���Ф����ޤ���
274
���ĤǤʤ����Ϥ�Ϥ�ɽ�����Фޤ� (�����Ǥ�Фޤ�)��
275
�ޤ� reduce/reduce conflict ��ɽ���������Ǥ��ޤ���
279
�ȡ�����ܥ��ɽ���ͤϡ��ǥե���ȤǤ�
281
* ʸˡ�桢������Ǥ����ޤ�Ƥ��ʤ���� (RULE�Ȥ�XEND�Ȥ�)
282
������̾����ʸ����� intern ���������륷��ܥ� (1.4 �Ǥ� Fixnum)
283
* ������Ǥ����ޤ�Ƥ�����(':'�Ȥ�'.'�Ȥ�)
286
�ȤʤäƤ��ޤ��������Ȥ���¾�η����Υ�����ʤ����Ǥ�¸�ߤ�����ʤɤϡ�
287
����ˤ��碌�ʤ���Фʤ餺�����ΤޤޤǤ����ؤǤ������Τ褦�ʾ��ˤϡ�
288
convert ���ä��뤳�Ȥǡ��ȡ�����ܥ��ɽ���ͤ��Ѥ��뤳�Ȥ��Ǥ��ޤ���
292
PLUS 'PlusClass' #�� PlusClass
293
MIN 'MinusClass' #�� MinusClass
296
�ǥե���ȤǤϥȡ�����ܥ� PLUS ���Ф��Ƥϥȡ�����ܥ��ͤ�
297
:PLUS �Ǥ�������Τ褦�ʵ��Ҥ�������� PlusClass �ˤʤ�ޤ���
298
�Ѵ�����ͤ� false��nil �ʳ��ʤ�ʤ�Ǥ�Ȥ��ޤ���
300
�Ѵ�����ͤȤ���ʸ�����Ȥ��Ȥ��ϡ����Τ褦�˰������Ťͤ�ɬ�פ�����ޤ���
303
PLUS '"plus"' #�� "plus"
306
�ޤ�����'�פ�ȤäƤ��������줿 Ruby �Υ����ɾ�Ǥϡ�"�פˤʤ�Τ�
307
���դ��Ƥ����������Хå�����å���ˤ�륯�����Ȥ�ͭ���Ǥ������Хå�
308
����å���Ͼä����ˤ��ΤޤĤ�ޤ���
310
PLUS '"plus\n"' #�� "plus\n"
311
MIN "\"minus#{val}\"" #�� \"minus#{val}\"
316
�ѡ�����Ĥ��뤿��ˤϡ��ɤε�§���ֺǽ�Ρ�§�����Ȥ������Ȥ� Racc �ˤ�������
317
���ʤ���Ф����ޤ����������Ū�˽Τ��������ȵ�§�Ǥ����������ȵ�§��
322
start �ϹԤκǽ�ˤ��ʤ���Ф����ޤ����Τ褦�˽ȡ��ե������
323
���ֺǽ�˽ФƤ��� real_target �ε�§�����ȵ�§�Ȥ��ƻȤ��ޤ���
324
��ά�������ϡ��ե�����κǽ�ε�§���������ȵ�§�ˤʤ�ޤ������̤�
325
�ǽ�ε�§����־�ˤ����ۤ����䤹�����狼��䤹���ʤ�ޤ����顢
326
���ε�ˡ�Ϥ��ޤ�Ĥ���ɬ�פϤʤ��Ǥ��礦��
330
�桼���������ɤϡ��ѡ������饹�����ޤ��ե�����ˡ�
331
����������¾�ˤ⥳���ɤ�ޤ�����˻Ȥ��ޤ������Τ褦�ʤ�Τ�
332
���ޤ����˱����ƻ���¸�ߤ����ѡ������饹�����������
333
header�����饹�������(����Ƭ)�� inner������θ夬 footer �Ǥ���
334
�桼�������ɤȤ��ƽ���Τ��������ä����ˤ��Τޤ�Ϣ�뤵��ޤ���
336
�桼�������������νϰʲ����̤�Ǥ���
347
�Ԥ���Ƭ����ͤİʾ�Ϣ³������-��(�ޥ��ʥ�)������ȥ桼���������ɤ�
348
�ߤʤ���ޤ������̻Ҥϰ�Ĥ�ñ��ǡ����Τ��Ȥˤϡ�=�װʳ��ʤ鲿��
351
= Racc Grammar File Reference
355
== Class Block and User Code Block
357
There's two block on toplevel.
358
one is 'class' block, another is 'user code' block. 'user code' block MUST
359
places after 'class' block.
363
You can insert comment about all places. Two style comment can be used,
364
Ruby style (#.....) and C style (/*......*/) .
368
The class block is formed like this:
372
[token declearations]
373
[expected number of S/R conflict]
375
[semantic value convertion]
380
CLASS_NAME is a name of parser class.
381
This is the name of generating parser class.
383
If CLASS_NAME includes '::', Racc outputs module clause.
384
For example, writing "class M::C" causes creating the code bellow:
396
The grammar block discripts grammar which is able
397
to be understood by parser. Syntax is:
399
(token): (token) (token) (token).... (action)
401
(token): (token) (token) (token).... (action)
402
| (token) (token) (token).... (action)
403
| (token) (token) (token).... (action)
405
(action) is an action which is executed when its (token)s are found.
406
(action) is a ruby code block, which is surrounded by braces:
411
Note that you cannot use '%' string, here document, '%r' regexp in action.
413
Actions can be omitted.
414
When it is omitted, '' (empty string) is used.
416
A return value of action is a value of left side value ($$).
417
It is value of result, or returned value by "return" statement.
419
Here is an example of whole grammar block.
422
goal: definition ruls source { result = val }
424
definition: /* none */ { result = [] }
425
| definition startdesig { result[0] = val[1] }
427
precrule # this line continue from upper line
432
startdesig: START TOKEN
434
You can use following special local variables in action.
438
The value of left-hand side (lhs). A default value is val[0].
442
An array of value of right-hand side (rhs).
444
* _values (...$-2,$-1,$0)
447
DO NOT MODIFY this stack unless you know what you are doing.
449
== Operator Precedance
451
This function is equal to '%prec' in yacc.
452
To designate this block:
461
`right' is yacc's %right, `left' is yacc's %left.
463
`=' + (symbol) means yacc's %prec:
474
| '-' exp =UMINUS # equals to "%prec UMINUS"
481
Racc has bison's "expect" directive.
491
This directive declears "expected" number of shift/reduce conflict.
492
If "expected" number is equal to real number of conflicts,
493
racc does not print confliction warning message.
497
By declaring tokens, you can avoid many meanless bugs.
498
If decleared token does not exist/existing token does not decleared,
499
Racc output warnings. Declearation syntax is:
501
token TOKEN_NAME AND_IS_THIS
502
ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
507
You can write options for racc command in your racc file.
509
options OPTION OPTION ...
515
omit empty action call or not.
519
use/does not use local variable "result"
521
You can use 'no_' prefix to invert its meanings.
523
== Converting Token Symbol
525
Token symbols are, as default,
527
* naked token string in racc file (TOK, XFILE, this_is_token, ...)
528
--> symbol (:TOK, :XFILE, :this_is_token, ...)
529
* quoted string (':', '.', '(', ...)
530
--> same string (':', '.', '(', ...)
532
You can change this default by "convert" block.
536
PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
537
MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
540
We can use almost all ruby value can be used by token symbol,
541
except 'false' and 'nil'. These are causes unexpected parse error.
543
If you want to use String as token symbol, special care is required.
547
class '"cls"' # in code, "cls"
548
PLUS '"plus\n"' # in code, "plus\n"
549
MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
555
'%start' in yacc. This changes start rule.
559
This statement will not be used forever, I think.
563
"User Code Block" is a Ruby source code which is copied to output.
564
There are three user code block, "header" "inner" and "footer".
566
Format of user code is like this:
578
If four '-' exist on line head,
579
racc treat it as beginning of user code block.
580
A name of user code must be one word.