depager 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/bin/depager +1 -0
- data/data/depager/misc/depager-mode.el +35 -24
- data/data/depager/pre-setup.rb +3 -0
- data/examples/Rakefile +36 -0
- data/examples/c89/c89.dr +496 -0
- data/examples/c89/c89.tab.rb +2197 -0
- data/examples/c89/test.c89 +10 -0
- data/{data/depager/sample → examples}/extension/paction.dr +0 -0
- data/{data/depager/sample → examples}/extension/pactiontest.dr +0 -0
- data/{data/depager/sample → examples}/pl0d/pl0ds.dr +0 -0
- data/examples/pl0d/pl0ds.tab.rb +1702 -0
- data/{data/depager/sample/pl0d/pl0test.pl0 → examples/pl0d/test.pl0ds} +0 -0
- data/{data/depager/sample → examples}/sample_calc/calc.action.dr +0 -0
- data/examples/sample_calc/calc.action.tab.rb +283 -0
- data/{data/depager/sample → examples}/sample_calc/calc.astdf.dr +0 -0
- data/examples/sample_calc/calc.astdf.tab.rb +476 -0
- data/{data/depager/sample → examples}/sample_calc/calc.astl.action.dr +0 -0
- data/examples/sample_calc/calc.astl.action.tab.rb +593 -0
- data/{data/depager/sample → examples}/sample_calc/calc.astl.dr +0 -0
- data/examples/sample_calc/calc.astl.tab.rb +501 -0
- data/{data/depager/sample → examples}/sample_calc/calc.atree.dr +0 -0
- data/examples/sample_calc/calc.atree.tab.rb +277 -0
- data/{data/depager/sample → examples}/sample_calc/calc.cst.dr +0 -0
- data/examples/sample_calc/calc.cst.tab.rb +478 -0
- data/{data/depager/sample → examples}/sample_calc/calc.dr +0 -0
- data/{data/depager/sample → examples}/sample_calc/calc.lex.dr +0 -0
- data/examples/sample_calc/calc.lex.tab.rb +192 -0
- data/{data/depager/sample → examples}/sample_calc/calc.nvaction.dr +0 -0
- data/examples/sample_calc/calc.nvaction.tab.rb +291 -0
- data/examples/sample_calc/calc.tab.rb +183 -0
- data/{data/depager/sample → examples}/sample_calc/calc_prec.nvaction.dr +0 -0
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +257 -0
- data/examples/sample_calc/test.calc +1 -0
- data/{data/depager/sample/slex_test/slextest1.dr → examples/slex_test/divreg.slex.dr} +3 -11
- data/examples/slex_test/divreg.slex.tab.rb +227 -0
- data/{data/depager/sample/slex_test/slextest2.dr → examples/slex_test/ljoin.slex.dr} +10 -7
- data/examples/slex_test/ljoin.slex.tab.rb +277 -0
- data/examples/slex_test/test.divreg +1 -0
- data/examples/slex_test/test.ljoin +3 -0
- data/lib/depager.rb +194 -127
- data/lib/depager/Rakefile +8 -4
- data/lib/depager/ast_base.dr +3 -3
- data/lib/depager/ast_base.rb +197 -144
- data/lib/depager/atree.rb +55 -36
- data/lib/depager/cst.dr +6 -4
- data/lib/depager/cst.rb +69 -49
- data/lib/depager/grammar.rb +136 -0
- data/lib/depager/lex.dr +22 -8
- data/lib/depager/lex.rb +94 -53
- data/lib/depager/lr.rb +101 -167
- data/lib/depager/parse_action.rb +1 -1
- data/lib/depager/parser.rb +34 -7
- data/lib/depager/slex.dr +76 -36
- data/lib/depager/slex.rb +345 -151
- data/lib/depager/srp.rb +3 -2
- data/lib/depager/template/extension_lalr_slave.erb +1 -1
- data/lib/depager/template/single_lalr_parser.erb +1 -1
- data/lib/depager/utils.rb +2 -1
- data/lib/depager/version.rb +2 -2
- metadata +42 -28
- data/Manifest.txt +0 -52
- data/lib/depager/psrtmpl.rb +0 -33
data/ChangeLog
CHANGED
data/bin/depager
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
; depager-mode.el
|
2
2
|
;; original is racc-mode.el
|
3
3
|
;; modified for Depager by M
|
4
4
|
;;
|
@@ -37,6 +37,9 @@
|
|
37
37
|
|
38
38
|
(require 'derived)
|
39
39
|
|
40
|
+
(defconst depager-begin-rule-re "^[ \t]*#begin-rule[ \t]*$")
|
41
|
+
(defconst depager-end-rule-re "^[ \t]*#end-rule[ \t]*$")
|
42
|
+
|
40
43
|
(define-derived-mode depager-mode ruby-mode "Depager"
|
41
44
|
"Major mode for Depager editing."
|
42
45
|
(interactive)
|
@@ -56,44 +59,51 @@
|
|
56
59
|
(depager-indent-command))
|
57
60
|
|
58
61
|
(defun depager-indent-line (&optional flag)
|
59
|
-
(if (or (string-match
|
60
|
-
(string-match
|
62
|
+
(if (or (string-match depager-begin-rule-re (current-line))
|
63
|
+
(string-match depager-end-rule-re (current-line)))
|
61
64
|
(depager-indent-to 0)
|
62
65
|
(if (point-in-rule)
|
63
|
-
(
|
66
|
+
(progn ;(message "in-rule")
|
67
|
+
(depager-indent-to (depager-calculate-indent)))
|
64
68
|
(if (point-before-rule)
|
65
|
-
(
|
66
|
-
|
69
|
+
(progn ;(message "befor-rule")
|
70
|
+
(depager-indent-to (depager-calculate-indent-before-rule)))
|
71
|
+
(progn ;(message "other")
|
72
|
+
(ruby-indent-line t))))))
|
67
73
|
|
68
74
|
(defun beginning-of-rule ()
|
69
75
|
(beginning-of-buffer)
|
70
|
-
(re-search-forward
|
76
|
+
(re-search-forward depager-begin-rule-re)
|
71
77
|
(beginning-of-line))
|
72
78
|
|
73
79
|
(defun end-of-rule ()
|
74
80
|
(beginning-of-buffer)
|
75
|
-
(re-search-forward
|
81
|
+
(re-search-forward depager-end-rule-re)
|
76
82
|
(end-of-line))
|
77
83
|
|
78
84
|
(defun point-in-rule ()
|
79
85
|
(save-excursion
|
80
|
-
(let (
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
(let ((backward-begin-rule
|
87
|
+
(re-search-backward-without-moving-point depager-begin-rule-re))
|
88
|
+
(backward-end-rule
|
89
|
+
(re-search-backward-without-moving-point depager-end-rule-re))
|
90
|
+
(forward-end-rule
|
91
|
+
(re-search-forward-without-moving-point depager-end-rule-re)))
|
92
|
+
(progn ;(message "%S %S" backward-begin-rule forward-end-rule)
|
93
|
+
(or (and backward-begin-rule
|
94
|
+
backward-end-rule
|
95
|
+
forward-end-rule
|
96
|
+
(< backward-end-rule backward-begin-rule)
|
97
|
+
(< backward-begin-rule forward-end-rule))
|
98
|
+
(and backward-begin-rule
|
99
|
+
(not backward-end-rule)
|
100
|
+
forward-end-rule
|
101
|
+
(< backward-begin-rule forward-end-rule)))))))
|
92
102
|
|
93
103
|
(defun point-before-rule ()
|
94
104
|
(save-excursion
|
95
105
|
(and (not (point-in-rule))
|
96
|
-
(re-search-forward-without-moving-point
|
106
|
+
(re-search-forward-without-moving-point depager-begin-rule-re))))
|
97
107
|
|
98
108
|
(defun point-in-p ()
|
99
109
|
(save-excursion
|
@@ -115,7 +125,7 @@
|
|
115
125
|
(defun match-token-line (str)
|
116
126
|
(or (string-match "^[ \t]*|[ \t]*"
|
117
127
|
str)
|
118
|
-
(string-match "[ \t]*:[ \t]*\\(#.*\\)?\n$"
|
128
|
+
(string-match "^[ \t]*[a-zA-Z0-9\-_]+[ \t]*:[ \t]*\\(#.*\\)?\n$"
|
119
129
|
str)
|
120
130
|
(string-match "^[ \t]*=>[ \t]*"
|
121
131
|
str)
|
@@ -128,7 +138,7 @@
|
|
128
138
|
(forward-line -1)
|
129
139
|
(while (string-match "^[ \t]*\n$" (current-line))
|
130
140
|
(forward-line -1))
|
131
|
-
(string-match "[ \t]*:[ \t]*\\(#.*\\)?$"
|
141
|
+
(string-match "^[ \t]*[a-zA-Z0-9\-_]+[ \t]*:[ \t]*\\(#.*\\)?$"
|
132
142
|
(current-line))))
|
133
143
|
(and (point-in-rule)
|
134
144
|
(or (match-token-line (current-line))
|
@@ -174,7 +184,8 @@
|
|
174
184
|
|
175
185
|
(defun depager-calculate-indent-before-rule ()
|
176
186
|
(cond ((or (string-match "^%.*{[ \t]*$" (current-line))
|
177
|
-
(string-match "^%}[ \t]*$" (current-line))
|
187
|
+
(string-match "^%}[ \t]*$" (current-line))
|
188
|
+
(string-match "^%%[ \t]*$" (current-line)))
|
178
189
|
0)
|
179
190
|
((point-in-p)
|
180
191
|
(ruby-calculate-indent (max (save-excursion
|
data/examples/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Dir.chdir(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
DIRS = ['pl0d', 'sample_calc', 'slex_test', 'c89']
|
6
|
+
SRC = DIRS.map{|d| Dir["#{d}/*.dr"] }.flatten
|
7
|
+
OBJ = SRC.map{|i| i.sub(/\.dr$/, '.tab.rb')}
|
8
|
+
CLEAN.include(OBJ)
|
9
|
+
|
10
|
+
LIBDIR = "../lib"
|
11
|
+
BINDIR = "../bin"
|
12
|
+
|
13
|
+
SRC.each do |fn|
|
14
|
+
fn.match(/^([^\/]+)\/([^.]+)(\..+)?\.dr$/)
|
15
|
+
dir = $1
|
16
|
+
base = $2
|
17
|
+
dst = "#{dir}/#{$2}#{$3}.tab.rb"
|
18
|
+
exts = $3 && $3.split('.')[1 .. -1]
|
19
|
+
depends = exts ? exts.map{|i| "#{LIBDIR}/depager/#{i}.rb" } : []
|
20
|
+
depends = depends.unshift fn
|
21
|
+
test_ext = base.split('_')[0]
|
22
|
+
|
23
|
+
# puts %!#{dst} =>\n #{depends.join("\n ")}!
|
24
|
+
file dst => depends do
|
25
|
+
sh "ruby -I#{LIBDIR} #{BINDIR}/depager -g -o #{dst} #{fn}"
|
26
|
+
# raise unless $! == 0
|
27
|
+
Dir["#{dir}/*.#{test_ext}"].each do |t|
|
28
|
+
sh "ruby -I#{LIBDIR} #{dst} < #{t}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => OBJ
|
34
|
+
DIRS.each do |d|
|
35
|
+
task d => OBJ.select{|i| i =~ /^#{d}\// }
|
36
|
+
end
|
data/examples/c89/c89.dr
ADDED
@@ -0,0 +1,496 @@
|
|
1
|
+
%class CParser
|
2
|
+
# from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html and
|
3
|
+
# http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
|
4
|
+
%extend Lexer ('depager/lex.rb')
|
5
|
+
#%decorate ShiftReducePrinter ('depager/srp.rb')
|
6
|
+
%inner{
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
@keywords = {
|
10
|
+
"auto" => :AUTO,
|
11
|
+
"break" => :BREAK,
|
12
|
+
"case" => :CASE,
|
13
|
+
"char" => :CHAR,
|
14
|
+
"const" => :CONST,
|
15
|
+
"continue" => :CONTINUE,
|
16
|
+
"default" => :DEFAULT,
|
17
|
+
"do" => :DO,
|
18
|
+
"double" => :DOUBLE,
|
19
|
+
"else" => :ELSE,
|
20
|
+
"enum" => :ENUM,
|
21
|
+
"extern" => :EXTERN,
|
22
|
+
"float" => :FLOAT,
|
23
|
+
"for" => :FOR,
|
24
|
+
"goto" => :GOTO,
|
25
|
+
"if" => :IF,
|
26
|
+
"int" => :INT,
|
27
|
+
"long" => :LONG,
|
28
|
+
"register" => :REGISTER,
|
29
|
+
"return" => :RETURN,
|
30
|
+
"short" => :SHORT,
|
31
|
+
"signed" => :SIGNED,
|
32
|
+
"sizeof" => :SIZEOF,
|
33
|
+
"static" => :STATIC,
|
34
|
+
"struct" => :STRUCT,
|
35
|
+
"switch" => :SWITCH,
|
36
|
+
"typedef" => :TYPEDEF,
|
37
|
+
"union" => :UNION,
|
38
|
+
"unsigned" => :UNSIGNED,
|
39
|
+
"void" => :VOID,
|
40
|
+
"volatile" => :VOLATILE,
|
41
|
+
"while" => :WHILE,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
%}
|
45
|
+
%%
|
46
|
+
%LEX{
|
47
|
+
/#.*\n/ { @line0 =~ /^#/ || raise }
|
48
|
+
'/*'
|
49
|
+
{
|
50
|
+
begin
|
51
|
+
break if @line =~ /\*\//
|
52
|
+
end while @line = getline
|
53
|
+
@line = $'
|
54
|
+
}
|
55
|
+
/\/\/[^\n]*/ { }
|
56
|
+
|
57
|
+
/[a-zA-Z_][a-zA-Z0-9_]*/ { yield _Token(@keywords[$&] || :IDENTIFIER) }
|
58
|
+
/0[xX][A-F]+/ { yield _Token(:CONSTANT) }
|
59
|
+
/0[0-9]+/ { yield _Token(:CONSTANT) }
|
60
|
+
/[0-9]+/ { yield _Token(:CONSTANT) }
|
61
|
+
/[0-9]+/ { yield _Token(:CONSTANT) }
|
62
|
+
/[0-9]*\.[0-9]+/ { yield _Token(:CONSTANT) }
|
63
|
+
/"(\\.|[^"\\])*"/ { yield _Token(:STRING_LITERAL) }
|
64
|
+
|
65
|
+
'...' { yield _Token(:ELLIPSIS) }
|
66
|
+
'>>=' { yield _Token(:RIGHT_ASSIGN) }
|
67
|
+
'<<=' { yield _Token(:LEFT_ASSIGN) }
|
68
|
+
'+=' { yield _Token(:ADD_ASSIGN) }
|
69
|
+
'-=' { yield _Token(:SUB_ASSIGN) }
|
70
|
+
'*=' { yield _Token(:MUL_ASSIGN) }
|
71
|
+
'/=' { yield _Token(:DIV_ASSIGN) }
|
72
|
+
'%=' { yield _Token(:MOD_ASSIGN) }
|
73
|
+
'&=' { yield _Token(:AND_ASSIGN) }
|
74
|
+
'^=' { yield _Token(:XOR_ASSIGN) }
|
75
|
+
'|=' { yield _Token(:OR_ASSIGN) }
|
76
|
+
'>>' { yield _Token(:RIGHT_OP) }
|
77
|
+
'<<' { yield _Token(:LEFT_OP) }
|
78
|
+
'++' { yield _Token(:INC_OP) }
|
79
|
+
'--' { yield _Token(:DEC_OP) }
|
80
|
+
'->' { yield _Token(:PTR_OP) }
|
81
|
+
'&&' { yield _Token(:AND_OP) }
|
82
|
+
'||' { yield _Token(:OR_OP) }
|
83
|
+
'<=' { yield _Token(:LE_OP) }
|
84
|
+
'>=' { yield _Token(:GE_OP) }
|
85
|
+
'==' { yield _Token(:EQ_OP) }
|
86
|
+
'!=' { yield _Token(:NE_OP) }
|
87
|
+
|
88
|
+
/[ \t\v\n\f]/ { }
|
89
|
+
/./ { yield _Token($&) }
|
90
|
+
%}
|
91
|
+
|
92
|
+
#begin-rule
|
93
|
+
translation_unit
|
94
|
+
: external_declaration
|
95
|
+
| translation_unit external_declaration
|
96
|
+
;
|
97
|
+
|
98
|
+
external_declaration
|
99
|
+
: function_definition
|
100
|
+
| declaration
|
101
|
+
;
|
102
|
+
|
103
|
+
function_definition
|
104
|
+
: declaration_specifiers declarator declaration_list compound_statement
|
105
|
+
| declaration_specifiers declarator compound_statement
|
106
|
+
| declarator declaration_list compound_statement
|
107
|
+
| declarator compound_statement
|
108
|
+
;
|
109
|
+
|
110
|
+
primary_expression
|
111
|
+
: IDENTIFIER
|
112
|
+
| CONSTANT
|
113
|
+
| STRING_LITERAL
|
114
|
+
| '(' expression ')'
|
115
|
+
;
|
116
|
+
|
117
|
+
postfix_expression
|
118
|
+
: primary_expression
|
119
|
+
| postfix_expression '[' expression ']'
|
120
|
+
| postfix_expression '(' ')'
|
121
|
+
| postfix_expression '(' argument_expression_list ')'
|
122
|
+
| postfix_expression '.' IDENTIFIER
|
123
|
+
| postfix_expression PTR_OP IDENTIFIER
|
124
|
+
| postfix_expression INC_OP
|
125
|
+
| postfix_expression DEC_OP
|
126
|
+
;
|
127
|
+
|
128
|
+
argument_expression_list
|
129
|
+
: assignment_expression
|
130
|
+
| argument_expression_list ',' assignment_expression
|
131
|
+
;
|
132
|
+
|
133
|
+
unary_expression
|
134
|
+
: postfix_expression
|
135
|
+
| INC_OP unary_expression
|
136
|
+
| DEC_OP unary_expression
|
137
|
+
| unary_operator cast_expression
|
138
|
+
| SIZEOF unary_expression
|
139
|
+
| SIZEOF '(' type_name ')'
|
140
|
+
;
|
141
|
+
|
142
|
+
unary_operator
|
143
|
+
: '&'
|
144
|
+
| '*'
|
145
|
+
| '+'
|
146
|
+
| '-'
|
147
|
+
| '~'
|
148
|
+
| '!'
|
149
|
+
;
|
150
|
+
|
151
|
+
cast_expression
|
152
|
+
: unary_expression
|
153
|
+
| '(' type_name ')' cast_expression
|
154
|
+
;
|
155
|
+
|
156
|
+
multiplicative_expression
|
157
|
+
: cast_expression
|
158
|
+
| multiplicative_expression '*' cast_expression
|
159
|
+
| multiplicative_expression '/' cast_expression
|
160
|
+
| multiplicative_expression '%' cast_expression
|
161
|
+
;
|
162
|
+
|
163
|
+
additive_expression
|
164
|
+
: multiplicative_expression
|
165
|
+
| additive_expression '+' multiplicative_expression
|
166
|
+
| additive_expression '-' multiplicative_expression
|
167
|
+
;
|
168
|
+
|
169
|
+
shift_expression
|
170
|
+
: additive_expression
|
171
|
+
| shift_expression LEFT_OP additive_expression
|
172
|
+
| shift_expression RIGHT_OP additive_expression
|
173
|
+
;
|
174
|
+
|
175
|
+
relational_expression
|
176
|
+
: shift_expression
|
177
|
+
| relational_expression '<' shift_expression
|
178
|
+
| relational_expression '>' shift_expression
|
179
|
+
| relational_expression LE_OP shift_expression
|
180
|
+
| relational_expression GE_OP shift_expression
|
181
|
+
;
|
182
|
+
|
183
|
+
equality_expression
|
184
|
+
: relational_expression
|
185
|
+
| equality_expression EQ_OP relational_expression
|
186
|
+
| equality_expression NE_OP relational_expression
|
187
|
+
;
|
188
|
+
|
189
|
+
and_expression
|
190
|
+
: equality_expression
|
191
|
+
| and_expression '&' equality_expression
|
192
|
+
;
|
193
|
+
|
194
|
+
exclusive_or_expression
|
195
|
+
: and_expression
|
196
|
+
| exclusive_or_expression '^' and_expression
|
197
|
+
;
|
198
|
+
|
199
|
+
inclusive_or_expression
|
200
|
+
: exclusive_or_expression
|
201
|
+
| inclusive_or_expression '|' exclusive_or_expression
|
202
|
+
;
|
203
|
+
|
204
|
+
logical_and_expression
|
205
|
+
: inclusive_or_expression
|
206
|
+
| logical_and_expression AND_OP inclusive_or_expression
|
207
|
+
;
|
208
|
+
|
209
|
+
logical_or_expression
|
210
|
+
: logical_and_expression
|
211
|
+
| logical_or_expression OR_OP logical_and_expression
|
212
|
+
;
|
213
|
+
|
214
|
+
conditional_expression
|
215
|
+
: logical_or_expression
|
216
|
+
| logical_or_expression '?' expression ':' conditional_expression
|
217
|
+
;
|
218
|
+
|
219
|
+
assignment_expression
|
220
|
+
: conditional_expression
|
221
|
+
| unary_expression assignment_operator assignment_expression
|
222
|
+
;
|
223
|
+
|
224
|
+
assignment_operator
|
225
|
+
: '='
|
226
|
+
| MUL_ASSIGN
|
227
|
+
| DIV_ASSIGN
|
228
|
+
| MOD_ASSIGN
|
229
|
+
| ADD_ASSIGN
|
230
|
+
| SUB_ASSIGN
|
231
|
+
| LEFT_ASSIGN
|
232
|
+
| RIGHT_ASSIGN
|
233
|
+
| AND_ASSIGN
|
234
|
+
| XOR_ASSIGN
|
235
|
+
| OR_ASSIGN
|
236
|
+
;
|
237
|
+
|
238
|
+
expression
|
239
|
+
: assignment_expression
|
240
|
+
| expression ',' assignment_expression
|
241
|
+
;
|
242
|
+
|
243
|
+
constant_expression
|
244
|
+
: conditional_expression
|
245
|
+
;
|
246
|
+
|
247
|
+
declaration
|
248
|
+
: declaration_specifiers ';'
|
249
|
+
| declaration_specifiers init_declarator_list ';'
|
250
|
+
;
|
251
|
+
|
252
|
+
declaration_specifiers
|
253
|
+
: storage_class_specifier
|
254
|
+
| storage_class_specifier declaration_specifiers
|
255
|
+
| type_specifier
|
256
|
+
| type_specifier declaration_specifiers
|
257
|
+
| type_qualifier
|
258
|
+
| type_qualifier declaration_specifiers
|
259
|
+
;
|
260
|
+
|
261
|
+
init_declarator_list
|
262
|
+
: init_declarator
|
263
|
+
| init_declarator_list ',' init_declarator
|
264
|
+
;
|
265
|
+
|
266
|
+
init_declarator
|
267
|
+
: declarator
|
268
|
+
| declarator '=' initializer
|
269
|
+
;
|
270
|
+
|
271
|
+
storage_class_specifier
|
272
|
+
: TYPEDEF
|
273
|
+
| EXTERN
|
274
|
+
| STATIC
|
275
|
+
| AUTO
|
276
|
+
| REGISTER
|
277
|
+
;
|
278
|
+
|
279
|
+
type_specifier
|
280
|
+
: VOID
|
281
|
+
| CHAR
|
282
|
+
| SHORT
|
283
|
+
| INT
|
284
|
+
| LONG
|
285
|
+
| FLOAT
|
286
|
+
| DOUBLE
|
287
|
+
| SIGNED
|
288
|
+
| UNSIGNED
|
289
|
+
| struct_or_union_specifier
|
290
|
+
| enum_specifier
|
291
|
+
| TYPE_NAME
|
292
|
+
;
|
293
|
+
|
294
|
+
struct_or_union_specifier
|
295
|
+
: struct_or_union IDENTIFIER '{' struct_declaration_list '}'
|
296
|
+
| struct_or_union '{' struct_declaration_list '}'
|
297
|
+
| struct_or_union IDENTIFIER
|
298
|
+
;
|
299
|
+
|
300
|
+
struct_or_union
|
301
|
+
: STRUCT
|
302
|
+
| UNION
|
303
|
+
;
|
304
|
+
|
305
|
+
struct_declaration_list
|
306
|
+
: struct_declaration
|
307
|
+
| struct_declaration_list struct_declaration
|
308
|
+
;
|
309
|
+
|
310
|
+
struct_declaration
|
311
|
+
: specifier_qualifier_list struct_declarator_list ';'
|
312
|
+
;
|
313
|
+
|
314
|
+
specifier_qualifier_list
|
315
|
+
: type_specifier specifier_qualifier_list
|
316
|
+
| type_specifier
|
317
|
+
| type_qualifier specifier_qualifier_list
|
318
|
+
| type_qualifier
|
319
|
+
;
|
320
|
+
|
321
|
+
struct_declarator_list
|
322
|
+
: struct_declarator
|
323
|
+
| struct_declarator_list ',' struct_declarator
|
324
|
+
;
|
325
|
+
|
326
|
+
struct_declarator
|
327
|
+
: declarator
|
328
|
+
| ':' constant_expression
|
329
|
+
| declarator ':' constant_expression
|
330
|
+
;
|
331
|
+
|
332
|
+
enum_specifier
|
333
|
+
: ENUM '{' enumerator_list '}'
|
334
|
+
| ENUM IDENTIFIER '{' enumerator_list '}'
|
335
|
+
| ENUM IDENTIFIER
|
336
|
+
;
|
337
|
+
|
338
|
+
enumerator_list
|
339
|
+
: enumerator
|
340
|
+
| enumerator_list ',' enumerator
|
341
|
+
;
|
342
|
+
|
343
|
+
enumerator
|
344
|
+
: IDENTIFIER
|
345
|
+
| IDENTIFIER '=' constant_expression
|
346
|
+
;
|
347
|
+
|
348
|
+
type_qualifier
|
349
|
+
: CONST
|
350
|
+
| VOLATILE
|
351
|
+
;
|
352
|
+
|
353
|
+
declarator
|
354
|
+
: pointer direct_declarator
|
355
|
+
| direct_declarator
|
356
|
+
;
|
357
|
+
|
358
|
+
direct_declarator
|
359
|
+
: IDENTIFIER
|
360
|
+
| '(' declarator ')'
|
361
|
+
| direct_declarator '[' constant_expression ']'
|
362
|
+
| direct_declarator '[' ']'
|
363
|
+
| direct_declarator '(' parameter_type_list ')'
|
364
|
+
| direct_declarator '(' identifier_list ')'
|
365
|
+
| direct_declarator '(' ')'
|
366
|
+
;
|
367
|
+
|
368
|
+
pointer
|
369
|
+
: '*'
|
370
|
+
| '*' type_qualifier_list
|
371
|
+
| '*' pointer
|
372
|
+
| '*' type_qualifier_list pointer
|
373
|
+
;
|
374
|
+
|
375
|
+
type_qualifier_list
|
376
|
+
: type_qualifier
|
377
|
+
| type_qualifier_list type_qualifier
|
378
|
+
;
|
379
|
+
|
380
|
+
|
381
|
+
parameter_type_list
|
382
|
+
: parameter_list
|
383
|
+
| parameter_list ',' ELLIPSIS
|
384
|
+
;
|
385
|
+
|
386
|
+
parameter_list
|
387
|
+
: parameter_declaration
|
388
|
+
| parameter_list ',' parameter_declaration
|
389
|
+
;
|
390
|
+
|
391
|
+
parameter_declaration
|
392
|
+
: declaration_specifiers declarator
|
393
|
+
| declaration_specifiers abstract_declarator
|
394
|
+
| declaration_specifiers
|
395
|
+
;
|
396
|
+
|
397
|
+
identifier_list
|
398
|
+
: IDENTIFIER
|
399
|
+
| identifier_list ',' IDENTIFIER
|
400
|
+
;
|
401
|
+
|
402
|
+
type_name
|
403
|
+
: specifier_qualifier_list
|
404
|
+
| specifier_qualifier_list abstract_declarator
|
405
|
+
;
|
406
|
+
|
407
|
+
abstract_declarator
|
408
|
+
: pointer
|
409
|
+
| direct_abstract_declarator
|
410
|
+
| pointer direct_abstract_declarator
|
411
|
+
;
|
412
|
+
|
413
|
+
direct_abstract_declarator
|
414
|
+
: '(' abstract_declarator ')'
|
415
|
+
| '[' ']'
|
416
|
+
| '[' constant_expression ']'
|
417
|
+
| direct_abstract_declarator '[' ']'
|
418
|
+
| direct_abstract_declarator '[' constant_expression ']'
|
419
|
+
| '(' ')'
|
420
|
+
| '(' parameter_type_list ')'
|
421
|
+
| direct_abstract_declarator '(' ')'
|
422
|
+
| direct_abstract_declarator '(' parameter_type_list ')'
|
423
|
+
;
|
424
|
+
|
425
|
+
initializer
|
426
|
+
: assignment_expression
|
427
|
+
| '{' initializer_list '}'
|
428
|
+
| '{' initializer_list ',' '}'
|
429
|
+
;
|
430
|
+
|
431
|
+
initializer_list
|
432
|
+
: initializer
|
433
|
+
| initializer_list ',' initializer
|
434
|
+
;
|
435
|
+
|
436
|
+
statement
|
437
|
+
: labeled_statement
|
438
|
+
| compound_statement
|
439
|
+
| expression_statement
|
440
|
+
| selection_statement
|
441
|
+
| iteration_statement
|
442
|
+
| jump_statement
|
443
|
+
;
|
444
|
+
|
445
|
+
labeled_statement
|
446
|
+
: IDENTIFIER ':' statement
|
447
|
+
| CASE constant_expression ':' statement
|
448
|
+
| DEFAULT ':' statement
|
449
|
+
;
|
450
|
+
|
451
|
+
compound_statement
|
452
|
+
: '{' '}'
|
453
|
+
| '{' statement_list '}'
|
454
|
+
| '{' declaration_list '}'
|
455
|
+
| '{' declaration_list statement_list '}'
|
456
|
+
;
|
457
|
+
|
458
|
+
declaration_list
|
459
|
+
: declaration
|
460
|
+
| declaration_list declaration
|
461
|
+
;
|
462
|
+
|
463
|
+
statement_list
|
464
|
+
: statement
|
465
|
+
| statement_list statement
|
466
|
+
;
|
467
|
+
|
468
|
+
expression_statement
|
469
|
+
: ';'
|
470
|
+
| expression ';'
|
471
|
+
;
|
472
|
+
|
473
|
+
selection_statement
|
474
|
+
: IF '(' expression ')' statement
|
475
|
+
| IF '(' expression ')' statement ELSE statement
|
476
|
+
| SWITCH '(' expression ')' statement
|
477
|
+
;
|
478
|
+
|
479
|
+
iteration_statement
|
480
|
+
: WHILE '(' expression ')' statement
|
481
|
+
| DO statement WHILE '(' expression ')' ';'
|
482
|
+
| FOR '(' expression_statement expression_statement ')' statement
|
483
|
+
| FOR '(' expression_statement expression_statement expression ')' statement
|
484
|
+
;
|
485
|
+
|
486
|
+
jump_statement
|
487
|
+
: GOTO IDENTIFIER ';'
|
488
|
+
| CONTINUE ';'
|
489
|
+
| BREAK ';'
|
490
|
+
| RETURN ';'
|
491
|
+
| RETURN expression ';'
|
492
|
+
;
|
493
|
+
#end-rule
|
494
|
+
%%
|
495
|
+
p = CParser::createDecoratedParser
|
496
|
+
p.yyparse(STDIN)
|