File tree Expand file tree Collapse file tree 2 files changed +30
-21
lines changed Expand file tree Collapse file tree 2 files changed +30
-21
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,30 @@ pub fn compile(
219
219
augmented_start_nt .productions.push (production )
220
220
production
221
221
})
222
+
223
+ // fix prec for productions
224
+ for prod in productions {
225
+ match prod .prec {
226
+ Some (_ ) => ()
227
+ None => {
228
+ let rightmost_term = prod .rhs.rev_iter ().find_first (fn (x ) { x is T (_ ) })
229
+ match rightmost_term {
230
+ Some (T (terminal )) => {
231
+ let term = get_terminal_by_name (terminal .name)
232
+ prod .prec = match term .prec {
233
+ Some ((prec , _ )) => Some (prec )
234
+ None => None
235
+ }
236
+ }
237
+ Some (NT (_ )) => panic ()
238
+ None => ()
239
+ }
240
+ }
241
+ }
242
+ }
243
+ // for prod in productions {
244
+ // println(prod)
245
+ // }
222
246
let grammar : @grm .Grammar = { terminals , nonterminals , productions , starts }
223
247
let automaton = @lr1 .Automaton ::build (grammar , user_eoi = input_mode is Pull )
224
248
let errors = @lr1 .resolve_conflicts (automaton .conflicts)
Original file line number Diff line number Diff line change @@ -312,27 +312,12 @@ pub fn elaborate(
312
312
}
313
313
Some (prec )
314
314
}
315
- None => {
316
- /// FROM ocamlyacc's manual
317
- // > Tokens and rules have precedences.
318
- // > By default, the precedence of a rule is the precedence of its rightmost terminal.
319
- // I don't what "rightmost terminal" means, but I guess it means the last terminal in the rule.
320
- // So, I'll use the precedence of the last terminal in the rule.
321
- let mut last_prec = None
322
- for item in items .rev_iter () {
323
- match item .term {
324
- Token (token ) => {
325
- last_prec = match token .prec {
326
- None => None
327
- Some ((prec , _assoc )) => Some (prec )
328
- }
329
- break
330
- }
331
- Param (_ ) | RuleCall (_ ) => ()
332
- }
333
- }
334
- last_prec
335
- }
315
+ None =>
316
+ // The prec should be determined by the rightmost terminal
317
+ // in the rule. But the items of rule may be modified later, So
318
+ // we will set it to None for now, and delay the decision
319
+ // at building lr1 grammar.
320
+ None
336
321
}
337
322
let clause = Clause ::{
338
323
items ,
You can’t perform that action at this time.
0 commit comments