;; ---------------------------------------------------------------------------
;; ~/events/actions.events
;; ---------------------------------------------------------------------------

;; These events describe the parsing actions.
;; A parsing table consists of an action table and a goto table

(defn mk-Tables (Actiontab Gototab)
  (cons Actiontab Gototab))

(defn sel-Actiontab (tables)
  (car tables))

(defn sel-Gototab (tables)
  (cdr tables))

;; An action is a tag, which is either 'shift, 'reduce or 'error, the state to
;; shift to, the label of a reduction, the left hand side of a reduction and
;; the size of the reduction. It is a union type of the different components.

(add-shell mk-Action Empty-Action is-Action
	   ((sel-action-tag   (none-of)        zero)
	    (sel-state-shift  (one-of numberp) zero)
	    (sel-label-reduce (one-of numberp) zero)
	    (sel-lhs-reduce   (none-of)        zero)
	    (sel-size-reduce  (one-of numberp) zero)))

;; I construct actions with the following functions.

(defn mk-shift-action (state)
  (mk-action 'SHIFT state 0 0 0))

(defn mk-reduce-action (label lhs size)
  (mk-action 'REDUCE 0 label lhs size))

(defn mk-error-action ()
  (mk-action 'ERROR 0 0 0 0))

;; For look-up a selector is needed, which is a symbol and a state.

(defn mk-Selector (State Symbol)
  (list State Symbol))

(defn action-lookup (terminal state actiontab) 
  (let ((key (mk-selector state terminal)))
    (cdr (assoc key actiontab))))

(defn goto-lookup (lhs state gototab) 
  (let ((key (mk-selector state lhs)))
    (cdr (assoc key gototab))))

