racc 1.7.1 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDL +22 -0
- data/COPYING +56 -22
- data/ChangeLog +3 -3
- data/README.ja.rdoc +2 -38
- data/README.rdoc +8 -27
- data/TODO +1 -1
- data/bin/racc +32 -32
- data/doc/en/grammar.en.rdoc +99 -107
- data/doc/en/grammar2.en.rdoc +1 -1
- data/doc/ja/command.ja.html +5 -0
- data/doc/ja/grammar.ja.rdoc +1 -1
- data/doc/ja/parser.ja.rdoc +1 -1
- data/ext/racc/cparse/cparse.c +26 -47
- data/ext/racc/cparse/extconf.rb +3 -4
- data/lib/racc/grammar.rb +82 -5
- data/lib/racc/grammarfileparser.rb +119 -13
- data/lib/racc/info.rb +2 -1
- data/lib/racc/parser-text.rb +6 -20
- data/lib/racc/parser.rb +6 -8
- data/lib/racc/parserfilegenerator.rb +6 -3
- data/lib/racc/state.rb +7 -3
- data/lib/racc/statetransitiontable.rb +1 -1
- data/lib/racc/static.rb +5 -5
- data/lib/racc.rb +6 -6
- metadata +7 -8
- data/doc/en/NEWS.en.rdoc +0 -282
- data/doc/ja/NEWS.ja.rdoc +0 -307
- data/ext/racc/MANIFEST +0 -4
data/doc/en/grammar.en.rdoc
CHANGED
@@ -15,48 +15,47 @@ supported: Ruby style (`# ...`) and C style (`/* ... */`).
|
|
15
15
|
== Class Block
|
16
16
|
|
17
17
|
The class block is formed like this:
|
18
|
-
|
19
|
-
class CLASS_NAME
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rule
|
27
|
-
|
28
|
-
|
18
|
+
|
19
|
+
class CLASS_NAME
|
20
|
+
[precedence table]
|
21
|
+
[token declarations]
|
22
|
+
[expected number of S/R conflict]
|
23
|
+
[options]
|
24
|
+
[semantic value conversion]
|
25
|
+
[start rule]
|
26
|
+
rule
|
27
|
+
GRAMMARS
|
28
|
+
|
29
29
|
CLASS_NAME is a name of parser class.
|
30
30
|
This is the name of generating parser class.
|
31
31
|
|
32
32
|
If CLASS_NAME includes '::', Racc outputs module clause.
|
33
|
-
For example, writing "class M::C" causes creating the code
|
34
|
-
|
35
|
-
module M
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
For example, writing "class M::C" causes creating the code below:
|
34
|
+
|
35
|
+
module M
|
36
|
+
class C
|
37
|
+
:
|
38
|
+
:
|
39
|
+
end
|
39
40
|
end
|
40
|
-
end
|
41
|
-
--
|
42
41
|
|
43
42
|
== Grammar Block
|
44
43
|
|
45
44
|
The grammar block describes the grammar
|
46
45
|
to be understood by parser. Syntax is:
|
47
|
-
--
|
48
|
-
(token): (token) (token) (token).... (action)
|
49
46
|
|
50
|
-
(token): (token) (token) (token).... (action)
|
51
|
-
|
52
|
-
|
53
|
-
|
47
|
+
(token): (token) (token) (token).... (action)
|
48
|
+
|
49
|
+
(token): (token) (token) (token).... (action)
|
50
|
+
| (token) (token) (token).... (action)
|
51
|
+
| (token) (token) (token).... (action)
|
52
|
+
|
54
53
|
(action) is an action which is executed when its (token)s are found.
|
55
54
|
(action) is a ruby code block, which is surrounded by braces:
|
56
|
-
|
57
|
-
{ print val[0]
|
58
|
-
|
59
|
-
|
55
|
+
|
56
|
+
{ print val[0]
|
57
|
+
puts val[1] }
|
58
|
+
|
60
59
|
Note that you cannot use '%' string, here document, '%r' regexp in action.
|
61
60
|
|
62
61
|
Actions can be omitted.
|
@@ -66,20 +65,20 @@ A return value of action is a value of left side value ($$).
|
|
66
65
|
It is value of result, or returned value by "return" statement.
|
67
66
|
|
68
67
|
Here is an example of whole grammar block.
|
69
|
-
|
70
|
-
rule
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
68
|
+
|
69
|
+
rule
|
70
|
+
goal: definition rules source { result = val }
|
71
|
+
|
72
|
+
definition: /* none */ { result = [] }
|
73
|
+
| definition startdesig { result[0] = val[1] }
|
74
|
+
| definition
|
75
|
+
precrule # this line continue from upper line
|
76
|
+
{
|
77
|
+
result[1] = val[1]
|
78
|
+
}
|
79
|
+
|
80
|
+
startdesig: START TOKEN
|
81
|
+
|
83
82
|
You can use following special local variables in action.
|
84
83
|
|
85
84
|
* result ($$)
|
@@ -99,45 +98,43 @@ DO NOT MODIFY this stack unless you know what you are doing.
|
|
99
98
|
|
100
99
|
This function is equal to '%prec' in yacc.
|
101
100
|
To designate this block:
|
102
|
-
|
103
|
-
prechigh
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
preclow
|
109
|
-
|
101
|
+
|
102
|
+
prechigh
|
103
|
+
nonassoc '++'
|
104
|
+
left '*' '/'
|
105
|
+
left '+' '-'
|
106
|
+
right '='
|
107
|
+
preclow
|
108
|
+
|
110
109
|
`right' is yacc's %right, `left' is yacc's %left.
|
111
110
|
|
112
111
|
`=' + (symbol) means yacc's %prec:
|
113
|
-
|
114
|
-
prechigh
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
preclow
|
119
|
-
|
120
|
-
rule
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
--
|
112
|
+
|
113
|
+
prechigh
|
114
|
+
nonassoc UMINUS
|
115
|
+
left '*' '/'
|
116
|
+
left '+' '-'
|
117
|
+
preclow
|
118
|
+
|
119
|
+
rule
|
120
|
+
exp: exp '*' exp
|
121
|
+
| exp '-' exp
|
122
|
+
| '-' exp =UMINUS # equals to "%prec UMINUS"
|
123
|
+
:
|
124
|
+
:
|
127
125
|
|
128
126
|
== expect
|
129
127
|
|
130
128
|
Racc supports Bison's "expect" directive to declare the expected
|
131
129
|
number of shift/reduce conflicts.
|
132
|
-
--
|
133
|
-
class MyParser
|
134
|
-
rule
|
135
|
-
expect 3
|
136
|
-
:
|
137
|
-
:
|
138
|
-
--
|
139
|
-
Then warnings are issued only when the effective number of conflicts differs.
|
140
130
|
|
131
|
+
class MyParser
|
132
|
+
expect 3
|
133
|
+
rule
|
134
|
+
:
|
135
|
+
:
|
136
|
+
|
137
|
+
Then warnings are issued only when the effective number of conflicts differs.
|
141
138
|
|
142
139
|
== Declaring Tokens
|
143
140
|
|
@@ -145,17 +142,16 @@ Declaring tokens avoids many bugs.
|
|
145
142
|
|
146
143
|
Racc outputs warnings for declared tokens that do not exist, or existing tokens not declared.
|
147
144
|
The syntax is:
|
148
|
-
|
149
|
-
token TOKEN_NAME AND_IS_THIS
|
150
|
-
|
151
|
-
--
|
145
|
+
|
146
|
+
token TOKEN_NAME AND_IS_THIS
|
147
|
+
ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
|
152
148
|
|
153
149
|
== Options
|
154
150
|
|
155
151
|
You can write options for racc command in your racc file.
|
156
|
-
|
157
|
-
options OPTION OPTION ...
|
158
|
-
|
152
|
+
|
153
|
+
options OPTION OPTION ...
|
154
|
+
|
159
155
|
Options are:
|
160
156
|
|
161
157
|
* omit_action_call
|
@@ -179,32 +175,29 @@ Token symbols are, as default,
|
|
179
175
|
|
180
176
|
You can change this default using a "convert" block.
|
181
177
|
Here is an example:
|
182
|
-
|
183
|
-
convert
|
184
|
-
|
185
|
-
|
186
|
-
end
|
187
|
-
|
178
|
+
|
179
|
+
convert
|
180
|
+
PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
|
181
|
+
MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
|
182
|
+
end
|
183
|
+
|
188
184
|
We can use almost all ruby value can be used by token symbol,
|
189
185
|
except 'false' and 'nil'. These are causes unexpected parse error.
|
190
186
|
|
191
187
|
If you want to use String as token symbol, special care is required.
|
192
188
|
For example:
|
193
|
-
|
194
|
-
convert
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
199
|
-
--
|
189
|
+
|
190
|
+
convert
|
191
|
+
class '"cls"' # in code, "cls"
|
192
|
+
PLUS '"plus\n"' # in code, "plus\n"
|
193
|
+
MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
|
194
|
+
end
|
200
195
|
|
201
196
|
== Start Rule
|
202
197
|
|
203
198
|
'%start' in yacc. This changes the start symbol.
|
204
|
-
--
|
205
|
-
start real_target
|
206
|
-
--
|
207
199
|
|
200
|
+
start real_target
|
208
201
|
|
209
202
|
== User Code Block
|
210
203
|
|
@@ -213,14 +206,13 @@ There are three user code blocks, "header" "inner" and "footer".
|
|
213
206
|
|
214
207
|
User code blocks are introduced by four '-' at the beginning of a line,
|
215
208
|
followed by a single-word name:
|
216
|
-
|
217
|
-
---- header
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
---- inner
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
--
|
209
|
+
|
210
|
+
---- header
|
211
|
+
ruby statement
|
212
|
+
ruby statement
|
213
|
+
ruby statement
|
214
|
+
|
215
|
+
---- inner
|
216
|
+
ruby statement
|
217
|
+
:
|
218
|
+
:
|
data/doc/en/grammar2.en.rdoc
CHANGED
data/doc/ja/command.ja.html
CHANGED
@@ -6,6 +6,7 @@ racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
|
|
6
6
|
[-O<var>filename</var>] [--log-file=<var>filename</var>]
|
7
7
|
[-g] [--debug]
|
8
8
|
[-E] [--embedded]
|
9
|
+
[-F] [--frozen]
|
9
10
|
[-l] [--no-line-convert]
|
10
11
|
[-c] [--line-convert-all]
|
11
12
|
[-a] [--no-omit-actions]
|
@@ -50,6 +51,10 @@ Ruby のパスを使用します。
|
|
50
51
|
ランタイムルーチンをすべて含んだコードを生成します。
|
51
52
|
つまり、このオプションをつけて生成したコードは Ruby さえあれば動きます。
|
52
53
|
</dd>
|
54
|
+
<dt>-F, --frozen
|
55
|
+
<dd>
|
56
|
+
Add frozen_string_literals: true.
|
57
|
+
</dd>
|
53
58
|
<dt>-C, --check-only
|
54
59
|
<dd>
|
55
60
|
(文法ファイルの) 文法のチェックだけをして終了します。
|
data/doc/ja/grammar.ja.rdoc
CHANGED
data/doc/ja/parser.ja.rdoc
CHANGED
data/ext/racc/cparse/cparse.c
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
Important Constants
|
23
23
|
----------------------------------------------------------------------- */
|
24
24
|
|
25
|
-
#define RACC_VERSION
|
25
|
+
#define RACC_VERSION STRINGIZE(RACC_INFO_VERSION)
|
26
26
|
|
27
27
|
#define DEFAULT_TOKEN -1
|
28
28
|
#define ERROR_TOKEN 1
|
@@ -70,12 +70,8 @@ static ID id_d_e_pop;
|
|
70
70
|
# define LONG2NUM(i) INT2NUM(i)
|
71
71
|
#endif
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
#endif
|
76
|
-
|
77
|
-
static ID value_to_id _((VALUE v));
|
78
|
-
static inline long num_to_long _((VALUE n));
|
73
|
+
static ID value_to_id(VALUE v);
|
74
|
+
static inline long num_to_long(VALUE n);
|
79
75
|
|
80
76
|
static ID
|
81
77
|
value_to_id(VALUE v)
|
@@ -99,8 +95,8 @@ num_to_long(VALUE n)
|
|
99
95
|
Parser Stack Interfaces
|
100
96
|
----------------------------------------------------------------------- */
|
101
97
|
|
102
|
-
static VALUE get_stack_tail
|
103
|
-
static void cut_stack_tail
|
98
|
+
static VALUE get_stack_tail(VALUE stack, long len);
|
99
|
+
static void cut_stack_tail(VALUE stack, long len);
|
104
100
|
|
105
101
|
static VALUE
|
106
102
|
get_stack_tail(VALUE stack, long len)
|
@@ -189,27 +185,27 @@ struct cparse_params {
|
|
189
185
|
Parser Main Routines
|
190
186
|
----------------------------------------------------------------------- */
|
191
187
|
|
192
|
-
static VALUE racc_cparse
|
193
|
-
static VALUE racc_yyparse
|
194
|
-
|
195
|
-
|
196
|
-
static void call_lexer
|
197
|
-
static VALUE lexer_i
|
198
|
-
|
199
|
-
static VALUE assert_array
|
200
|
-
static long assert_integer
|
201
|
-
static VALUE assert_hash
|
202
|
-
static VALUE initialize_params
|
203
|
-
|
204
|
-
static void cparse_params_mark
|
205
|
-
static size_t cparse_params_memsize
|
206
|
-
|
207
|
-
static void parse_main
|
208
|
-
|
209
|
-
static void extract_user_token
|
210
|
-
|
211
|
-
static void shift
|
212
|
-
static int reduce
|
188
|
+
static VALUE racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug);
|
189
|
+
static VALUE racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid,
|
190
|
+
VALUE arg, VALUE sysdebug);
|
191
|
+
|
192
|
+
static void call_lexer(struct cparse_params *v);
|
193
|
+
static VALUE lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data));
|
194
|
+
|
195
|
+
static VALUE assert_array(VALUE a);
|
196
|
+
static long assert_integer(VALUE n);
|
197
|
+
static VALUE assert_hash(VALUE h);
|
198
|
+
static VALUE initialize_params(VALUE vparams, VALUE parser, VALUE arg,
|
199
|
+
VALUE lexer, VALUE lexmid);
|
200
|
+
static void cparse_params_mark(void *ptr);
|
201
|
+
static size_t cparse_params_memsize(const void *ptr);
|
202
|
+
|
203
|
+
static void parse_main(struct cparse_params *v,
|
204
|
+
VALUE tok, VALUE val, int resume);
|
205
|
+
static void extract_user_token(struct cparse_params *v,
|
206
|
+
VALUE block_args, VALUE *tok, VALUE *val);
|
207
|
+
static void shift(struct cparse_params* v, long act, VALUE tok, VALUE val);
|
208
|
+
static int reduce(struct cparse_params* v, long act);
|
213
209
|
static rb_block_call_func reduce0;
|
214
210
|
|
215
211
|
#ifdef DEBUG
|
@@ -278,28 +274,11 @@ racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
|
|
278
274
|
return v->retval;
|
279
275
|
}
|
280
276
|
|
281
|
-
#ifdef HAVE_RB_BLOCK_CALL
|
282
277
|
static void
|
283
278
|
call_lexer(struct cparse_params *v)
|
284
279
|
{
|
285
280
|
rb_block_call(v->lexer, v->lexmid, 0, NULL, lexer_i, v->value_v);
|
286
281
|
}
|
287
|
-
#else
|
288
|
-
static VALUE
|
289
|
-
lexer_iter(VALUE data)
|
290
|
-
{
|
291
|
-
struct cparse_params *v = rb_check_typeddata(data, &cparse_params_type);
|
292
|
-
|
293
|
-
rb_funcall(v->lexer, v->lexmid, 0);
|
294
|
-
return Qnil;
|
295
|
-
}
|
296
|
-
|
297
|
-
static void
|
298
|
-
call_lexer(struct cparse_params *v)
|
299
|
-
{
|
300
|
-
rb_iterate(lexer_iter, v->value_v, lexer_i, v->value_v);
|
301
|
-
}
|
302
|
-
#endif
|
303
282
|
|
304
283
|
static VALUE
|
305
284
|
lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
|
data/ext/racc/cparse/extconf.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
|
4
4
|
require 'mkmf'
|
5
|
+
require_relative '../../../lib/racc/info'
|
5
6
|
|
6
|
-
|
7
|
-
have_func('rb_ary_subseq')
|
8
|
-
|
7
|
+
$defs << "-D""RACC_INFO_VERSION=#{Racc::VERSION}"
|
9
8
|
create_makefile 'racc/cparse'
|
data/lib/racc/grammar.rb
CHANGED
@@ -10,11 +10,11 @@
|
|
10
10
|
#
|
11
11
|
#++
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
require_relative 'compat'
|
14
|
+
require_relative 'iset'
|
15
|
+
require_relative 'sourcetext'
|
16
|
+
require_relative 'logfilegenerator'
|
17
|
+
require_relative 'exception'
|
18
18
|
require 'forwardable'
|
19
19
|
|
20
20
|
module Racc
|
@@ -27,6 +27,7 @@ module Racc
|
|
27
27
|
@rules = [] # :: [Rule]
|
28
28
|
@start = nil
|
29
29
|
@n_expected_srconflicts = nil
|
30
|
+
@error_on_expect_mismatch = nil
|
30
31
|
@prec_table = []
|
31
32
|
@prec_table_closed = false
|
32
33
|
@closed = false
|
@@ -36,6 +37,7 @@ module Racc
|
|
36
37
|
attr_reader :start
|
37
38
|
attr_reader :symboltable
|
38
39
|
attr_accessor :n_expected_srconflicts
|
40
|
+
attr_accessor :error_on_expect_mismatch
|
39
41
|
|
40
42
|
def [](x)
|
41
43
|
@rules[x]
|
@@ -787,6 +789,81 @@ module Racc
|
|
787
789
|
end
|
788
790
|
|
789
791
|
|
792
|
+
class OptionMark
|
793
|
+
def initialize(lineno)
|
794
|
+
@lineno = lineno
|
795
|
+
end
|
796
|
+
|
797
|
+
def name
|
798
|
+
'?'
|
799
|
+
end
|
800
|
+
|
801
|
+
alias inspect name
|
802
|
+
|
803
|
+
attr_reader :lineno
|
804
|
+
end
|
805
|
+
|
806
|
+
|
807
|
+
class ManyMark
|
808
|
+
def initialize(lineno)
|
809
|
+
@lineno = lineno
|
810
|
+
end
|
811
|
+
|
812
|
+
def name
|
813
|
+
'*'
|
814
|
+
end
|
815
|
+
|
816
|
+
alias inspect name
|
817
|
+
|
818
|
+
attr_reader :lineno
|
819
|
+
end
|
820
|
+
|
821
|
+
|
822
|
+
class Many1Mark
|
823
|
+
def initialize(lineno)
|
824
|
+
@lineno = lineno
|
825
|
+
end
|
826
|
+
|
827
|
+
def name
|
828
|
+
'+'
|
829
|
+
end
|
830
|
+
|
831
|
+
alias inspect name
|
832
|
+
|
833
|
+
attr_reader :lineno
|
834
|
+
end
|
835
|
+
|
836
|
+
|
837
|
+
class GroupStartMark
|
838
|
+
def initialize(lineno)
|
839
|
+
@lineno = lineno
|
840
|
+
end
|
841
|
+
|
842
|
+
def name
|
843
|
+
'('
|
844
|
+
end
|
845
|
+
|
846
|
+
alias inspect name
|
847
|
+
|
848
|
+
attr_reader :lineno
|
849
|
+
end
|
850
|
+
|
851
|
+
|
852
|
+
class GroupEndMark
|
853
|
+
def initialize(lineno)
|
854
|
+
@lineno = lineno
|
855
|
+
end
|
856
|
+
|
857
|
+
def name
|
858
|
+
')'
|
859
|
+
end
|
860
|
+
|
861
|
+
alias inspect name
|
862
|
+
|
863
|
+
attr_reader :lineno
|
864
|
+
end
|
865
|
+
|
866
|
+
|
790
867
|
class Prec
|
791
868
|
def initialize(symbol, lineno)
|
792
869
|
@symbol = symbol
|