Compiler/lexical analyzer: Difference between revisions

m
Read symbols into the lex-symbols package.
m (Read from stdin instead of from a file.)
m (Read symbols into the lex-symbols package.)
Line 1,631:
 
(in-package #:lexical-analyzer)
 
(defconstant +lex-symbols-package+ (or (find-package :lex-symbols)
(make-package :lex-symbols)))
 
(defclass counting-character-input-stream (fundamental-character-input-stream)
Line 1,711 ⟶ 1,714:
(defun id->keyword (id line column)
(case id
(lex-symbols::|if| (make-token :name :keyword-if :line line :column column))
(lex-symbols::|else| (make-token :name :keyword-else :line line :column column))
(lex-symbols::|while| (make-token :name :keyword-while :line line :column column))
(lex-symbols::|print| (make-token :name :keyword-print :line line :column column))
(lex-symbols::|putc| (make-token :name :keyword-putc :line line :column column))
(t nil)))
 
(defun handle-identifier (stream char)
Line 1,824 ⟶ 1,827:
(defun lex (stream)
(loop with *readtable* = (make-lexer-readtable)
with *package* = +lex-symbols-package+
with eof = (gensym)
with counting-stream = (make-instance 'counting-character-input-stream :stream stream)
68

edits