Source

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 ast-node ()
  ((value :initform () :initarg :value :accessor value-of)
   (children :initform () :initarg :children :accessor children)))

(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 
	  :documentation "The parser uses a stack, where each entry is a list of length 2.  The 1st item is number indicating the state
          (this value in the entry on the top of the stack represents the current state of the parser).  The 2nd item is a token
          or value (terminology is still messy).  This token or value is itself a 2-item list, with the first item being
          a symbol in the grammar corresponding to that node that is on the stack (could be a token from a lexer, or a non-terminal
          after reductions have occurred).  The 2nd item is the actual AST node built by the lexer and parser as parsing progresses. ")))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.