1. Phil Hargett
  2. HH-Parse


HH-Parse / types.lisp

(in-package :hh-parse )
;; =====================================================================================================================
;; Helpers
;; =====================================================================================================================

(defun make-lines ()
  (make-array 0 :element-type 'source-code-line :adjustable t)

;; =====================================================================================================================
;; Types
;; =====================================================================================================================

;; Source code
(defclass source-code-line ()
  ((parser :initform nil :initarg :parser :accessor parser-of
	   :documentation "Parser positioned at end of the line")
   (text :initform "" :initarg :text :accessor text-of)))

(defclass source-code-position ()
  ((line :initform 0 :initarg :line :accessor line-at)
   (column :initform 0 :initarg :column :accessor column-at))
  (:documentation "Represents a location within a file"))

(defclass source-code-file ()
  ((lines :initform (make-lines) :accessor lines-of)
   (position :initform (make-instance 'source-code-position) :accessor current-position))
  (:documentation "Represents the state of a file being edited or parsed"))

;; Grammar

(defclass production ()
  ((rule-name :initarg :rule :accessor rule-name)
   (reduction :initform #'list-terms :initarg :reduction :accessor reduction)
   (rhs :initarg :rhs)))

(defclass lr1-item ()
  ((position :initarg :position)
   (lookahead :initarg :lookahead )
   (production :initarg :production)))

(defclass lr1-state ()
  ((items :initarg :items :accessor items)
   (exits :initform (make-hash-table) :accessor exits
	  :documentation "Contains a mapping between symbols and integers representing the next state 
                          after encountering the symbol")))

(defclass lr-parse-table ()
  ((number-of-states :initarg :states :accessor number-of-states)
   (entries :initform (make-hash-table :test #'equal) :accessor entries))) 

(defclass lalr1-grammar ()
  ((specification :initarg :specification :accessor specification)
   (states :initarg :states :accessor states)
   (actions :initarg :actions :accessor actions)
   (gotos :initarg :gotos :accessor gotos)))

;; Lexer

(defclass lexer ()
  ((source :initform (make-instance 'source-code-file) :initarg :source :accessor source)
   (position :initform (make-instance 'source-code-position) :initarg :position :accessor parse-position)
   (state :initform :any :accessor state)))

;; Parser

(defclass lalr1-parser ()
  ((grammar :initarg :grammar :accessor grammar)
   (lexer :initarg :lexer :accessor lexer)
   (stack :initform () :accessor stack)))