Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Wrong handling of non-terminals "prec:" qualifier in LALR generated parsers #58

Open
marcomaggi opened this issue Oct 24, 2013 · 1 comment
Assignees
Labels

Comments

@marcomaggi
Copy link
Owner

When defining a parser with the library (nausicaa parser-tools lalr) and the grammar below:

(define make-parser
  (lalr.lalr-parser
   (lalr.output-value: #t)
   (lalr.expect: 0)
   (lalr.terminals: '(NUM                ;precedence 0
                      (left: ADD SUB)    ;precedence 1
                      (left: MUL DIV)    ;precedence 2
                      (nonassoc: UADD)   ;precedence 3
                      (nonassoc: USUB))) ;precedence 4
   (lalr.rules:
    '((EXPR

       ;;These are the offending rules.
       (ADD EXPR (prec: UADD)) : (list $1 $2)
       (SUB EXPR (prec: USUB)) : (list $1 $2)

       (EXPR ADD EXPR)         : (list $2 $1 $3)
       (EXPR SUB EXPR)         : (list $2 $1 $3)
       (EXPR MUL EXPR)         : (list $2 $1 $3)
       (EXPR DIV EXPR)         : (list $2 $1 $3)
       (NUM)                   : $1)))))

the rules defining the unary + and unary - operators do not handle correctly the prec: qualifier. This results in the sequence:

SUB ONE MUL TWO

to be parsed as (- (* 1 2)) rather than (* (- 1) 2)).

@ghost ghost assigned marcomaggi Oct 24, 2013
@marcomaggi
Copy link
Owner Author

Notice that the same unary operators definition works fine when used in the parser generated by tests/make-lalr-calc.sps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant