1999-05-10 20:52:58 +00:00
|
|
|
;;;
|
|
|
|
;;; JavaScript 2.0 lexer
|
|
|
|
;;;
|
1999-11-03 03:59:31 +00:00
|
|
|
;;; Waldemar Horwat (waldemar@acm.org)
|
1999-05-10 20:52:58 +00:00
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
|
|
(progn
|
|
|
|
(defparameter *lw*
|
|
|
|
(generate-world
|
|
|
|
"L"
|
|
|
|
'((lexer code-lexer
|
|
|
|
:lalr-1
|
2001-03-09 02:10:15 +00:00
|
|
|
:$next-input-element
|
1999-05-10 20:52:58 +00:00
|
|
|
((:unicode-character (% every (:text "Any Unicode character")) () t)
|
|
|
|
(:unicode-initial-alphabetic
|
2002-10-29 01:12:27 +00:00
|
|
|
(% initial-alpha (:text "Any character in category" :space
|
|
|
|
(:external-name "Lu") " (uppercase letter)," :space
|
|
|
|
(:external-name "Ll") " (lowercase letter)," :space
|
|
|
|
(:external-name "Lt") " (titlecase letter)," :space
|
|
|
|
(:external-name "Lm") " (modifier letter)," :space
|
|
|
|
(:external-name "Lo") " (other letter), or" :space
|
|
|
|
(:external-name "Nl") " (letter number)" :space "in the Unicode Character Database"))
|
1999-05-10 20:52:58 +00:00
|
|
|
() t)
|
|
|
|
(:unicode-alphanumeric
|
2002-10-29 01:12:27 +00:00
|
|
|
(% alphanumeric (:text "Any character in category" :space
|
|
|
|
(:external-name "Lu") " (uppercase letter)," :space
|
|
|
|
(:external-name "Ll") " (lowercase letter)," :space
|
|
|
|
(:external-name "Lt") " (titlecase letter)," :space
|
|
|
|
(:external-name "Lm") " (modifier letter)," :space
|
|
|
|
(:external-name "Lo") " (other letter)," :space
|
|
|
|
(:external-name "Nd") " (decimal number)," :space
|
|
|
|
(:external-name "Nl") " (letter number)," :space
|
|
|
|
(:external-name "Mn") " (non-spacing mark)," :space
|
|
|
|
(:external-name "Mc") " (combining spacing mark), or" :space
|
|
|
|
(:external-name "Pc") " (connector punctuation)" :space "in the Unicode Character Database"))
|
1999-05-10 20:52:58 +00:00
|
|
|
() t)
|
|
|
|
(:white-space-character (++ (#?0009 #?000B #?000C #\space #?00A0)
|
|
|
|
(#?2000 #?2001 #?2002 #?2003 #?2004 #?2005 #?2006 #?2007)
|
|
|
|
(#?2008 #?2009 #?200A #?200B)
|
|
|
|
(#?3000)) ())
|
2003-06-30 22:12:21 +00:00
|
|
|
(:line-terminator (#?000A #?000D #?0085 #?2028 #?2029) ())
|
1999-05-10 20:52:58 +00:00
|
|
|
(:non-terminator (- :unicode-character :line-terminator)
|
|
|
|
(($default-action $default-action)))
|
1999-12-07 22:09:10 +00:00
|
|
|
(:non-terminator-or-slash (- :non-terminator (#\/)) ())
|
|
|
|
(:non-terminator-or-asterisk-or-slash (- :non-terminator (#\* #\/)) ())
|
2003-06-30 22:12:21 +00:00
|
|
|
(:white-space-or-line-terminator-char (+ :white-space-character :line-terminator) ())
|
2000-10-28 05:55:19 +00:00
|
|
|
(:initial-identifier-character (+ :unicode-initial-alphabetic (#\$ #\_))
|
|
|
|
(($default-action $default-action)))
|
|
|
|
(:continuing-identifier-character (+ :unicode-alphanumeric (#\$ #\_))
|
|
|
|
(($default-action $default-action)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(:a-s-c-i-i-digit (#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
|
|
|
|
(($default-action $default-action)
|
1999-07-27 01:05:27 +00:00
|
|
|
(decimal-value $digit-value)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(:non-zero-digit (#\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
|
1999-07-27 01:05:27 +00:00
|
|
|
((decimal-value $digit-value)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(:hex-digit (#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 #\A #\B #\C #\D #\E #\F #\a #\b #\c #\d #\e #\f)
|
1999-07-27 01:05:27 +00:00
|
|
|
((hex-value $digit-value)))
|
1999-06-07 21:57:29 +00:00
|
|
|
(:letter-e (#\E #\e) (($default-action $default-action)))
|
|
|
|
(:letter-x (#\X #\x) (($default-action $default-action)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(:letter-f (#\F #\f) (($default-action $default-action)))
|
|
|
|
(:letter-l (#\L #\l) (($default-action $default-action)))
|
|
|
|
(:letter-u (#\U #\u) (($default-action $default-action)))
|
1999-06-07 21:57:29 +00:00
|
|
|
((:literal-string-char single) (- :unicode-character (+ (#\' #\\) :line-terminator))
|
1999-05-10 20:52:58 +00:00
|
|
|
(($default-action $default-action)))
|
1999-06-07 21:57:29 +00:00
|
|
|
((:literal-string-char double) (- :unicode-character (+ (#\" #\\) :line-terminator))
|
1999-05-10 20:52:58 +00:00
|
|
|
(($default-action $default-action)))
|
2001-02-23 00:04:17 +00:00
|
|
|
(:identity-escape (- :non-terminator (+ (#\_) :unicode-alphanumeric))
|
1999-05-10 20:52:58 +00:00
|
|
|
(($default-action $default-action)))
|
1999-10-20 00:43:22 +00:00
|
|
|
(:ordinary-reg-exp-char (- :non-terminator (#\\ #\/))
|
|
|
|
(($default-action $default-action))))
|
2003-05-23 01:07:54 +00:00
|
|
|
(($default-action char16 nil identity)
|
1999-07-27 01:05:27 +00:00
|
|
|
($digit-value integer digit-value digit-char-36)))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-03-09 02:10:15 +00:00
|
|
|
(rule :$next-input-element
|
2003-05-23 01:07:54 +00:00
|
|
|
((lex (union input-element extended-rational)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production :$next-input-element ($num (:next-input-element num)) $next-input-element-num
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :next-input-element)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production :$next-input-element ($re (:next-input-element re)) $next-input-element-re
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :next-input-element)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production :$next-input-element ($div (:next-input-element div)) $next-input-element-div
|
2003-05-23 01:07:54 +00:00
|
|
|
(lex (lex :next-input-element)))
|
|
|
|
(production :$next-input-element ($string-to-number :string-numeric-literal) $next-input-element-string-to-number
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :string-numeric-literal)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :$next-input-element ($parse-float :string-decimal-literal) $next-input-element-parse-float
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :string-decimal-literal))))
|
1999-12-07 22:09:10 +00:00
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%text nil "The lexer" :apostrophe "s start symbols are: "
|
2002-09-25 23:51:12 +00:00
|
|
|
(:grammar-symbol (:next-input-element num)) " if the previous input element was a number; "
|
2001-04-12 04:31:46 +00:00
|
|
|
(:grammar-symbol (:next-input-element re)) " if the previous input element was not a number and a "
|
1999-12-07 22:09:10 +00:00
|
|
|
(:character-literal #\/) " should be interpreted as a regular expression; and "
|
2001-04-12 04:31:46 +00:00
|
|
|
(:grammar-symbol (:next-input-element div)) " if the previous input element was not a number and a "
|
1999-12-07 22:09:10 +00:00
|
|
|
(:character-literal #\/) " should be interpreted as a division or division-assignment operator.")
|
2003-05-23 01:07:54 +00:00
|
|
|
(%text nil "In addition to the above, the start symbol " (:grammar-symbol :string-numeric-literal)
|
|
|
|
" is used by the syntactic semantics for string-to-number conversions and the start symbol " (:grammar-symbol :string-decimal-literal)
|
|
|
|
" is used by the syntactic semantics for implementing the " (:character-literal "parseFloat") " function.")
|
2000-10-28 05:55:19 +00:00
|
|
|
|
2001-04-12 04:31:46 +00:00
|
|
|
(deftag line-break)
|
|
|
|
(deftag end-of-input)
|
|
|
|
|
2001-09-10 22:10:36 +00:00
|
|
|
(deftuple keyword (name string))
|
|
|
|
(deftuple punctuator (name string))
|
|
|
|
(deftuple identifier (name string))
|
2002-10-29 01:12:27 +00:00
|
|
|
(deftuple number-token (value general-number))
|
2002-09-25 23:51:12 +00:00
|
|
|
(deftag negated-min-long)
|
2002-10-29 01:12:27 +00:00
|
|
|
(deftuple string-token (value string))
|
2001-09-10 22:10:36 +00:00
|
|
|
(deftuple regular-expression (body string) (flags string))
|
|
|
|
|
2002-10-29 01:12:27 +00:00
|
|
|
(deftype token (union keyword punctuator identifier number-token (tag negated-min-long) string-token regular-expression))
|
2001-04-12 04:31:46 +00:00
|
|
|
(deftype input-element (union (tag line-break end-of-input) token))
|
|
|
|
|
|
|
|
|
|
|
|
(deftag syntax-error)
|
2002-09-25 23:51:12 +00:00
|
|
|
(deftag range-error)
|
|
|
|
(deftype semantic-exception (tag syntax-error range-error))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Unicode Character Classes")
|
1999-05-10 20:52:58 +00:00
|
|
|
(%charclass :unicode-character)
|
|
|
|
(%charclass :unicode-initial-alphabetic)
|
|
|
|
(%charclass :unicode-alphanumeric)
|
|
|
|
(%charclass :white-space-character)
|
|
|
|
(%charclass :line-terminator)
|
|
|
|
(%charclass :a-s-c-i-i-digit)
|
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Comments")
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :line-comment (#\/ #\/ :line-comment-characters) line-comment)
|
|
|
|
|
|
|
|
(production :line-comment-characters () line-comment-characters-empty)
|
|
|
|
(production :line-comment-characters (:line-comment-characters :non-terminator) line-comment-characters-chars)
|
|
|
|
|
|
|
|
(%charclass :non-terminator)
|
|
|
|
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :single-line-block-comment (#\/ #\* :block-comment-characters #\* #\/) single-line-block-comment)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(production :block-comment-characters () block-comment-characters-empty)
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :block-comment-characters (:block-comment-characters :non-terminator-or-slash) block-comment-characters-chars)
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :block-comment-characters (:pre-slash-characters #\/) block-comment-characters-slash)
|
|
|
|
|
|
|
|
(production :pre-slash-characters () pre-slash-characters-empty)
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :pre-slash-characters (:block-comment-characters :non-terminator-or-asterisk-or-slash) pre-slash-characters-chars)
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :pre-slash-characters (:pre-slash-characters #\/) pre-slash-characters-slash)
|
|
|
|
|
1999-12-07 22:09:10 +00:00
|
|
|
(%charclass :non-terminator-or-slash)
|
|
|
|
(%charclass :non-terminator-or-asterisk-or-slash)
|
|
|
|
|
|
|
|
(production :multi-line-block-comment (#\/ #\* :multi-line-block-comment-characters :block-comment-characters #\* #\/) multi-line-block-comment)
|
|
|
|
|
|
|
|
(production :multi-line-block-comment-characters (:block-comment-characters :line-terminator) multi-line-block-comment-characters-first)
|
|
|
|
(production :multi-line-block-comment-characters (:multi-line-block-comment-characters :block-comment-characters :line-terminator)
|
|
|
|
multi-line-block-comment-characters-rest)
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "White Space")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(production :white-space () white-space-empty)
|
|
|
|
(production :white-space (:white-space :white-space-character) white-space-character)
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :white-space (:white-space :single-line-block-comment) white-space-single-line-block-comment)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Line Breaks")
|
1999-12-07 22:09:10 +00:00
|
|
|
|
|
|
|
(production :line-break (:line-terminator) line-break-line-terminator)
|
|
|
|
(production :line-break (:line-comment :line-terminator) line-break-line-comment)
|
|
|
|
(production :line-break (:multi-line-block-comment) line-break-multi-line-block-comment)
|
|
|
|
|
|
|
|
(production :line-breaks (:line-break) line-breaks-first)
|
|
|
|
(production :line-breaks (:line-breaks :white-space :line-break) line-breaks-rest)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Input Elements")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2002-09-25 23:51:12 +00:00
|
|
|
(grammar-argument :nu re div num)
|
2001-03-01 05:32:08 +00:00
|
|
|
(grammar-argument :nu_2 re div)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-03-09 02:10:15 +00:00
|
|
|
(rule (:next-input-element :nu)
|
2001-04-12 04:31:46 +00:00
|
|
|
((lex input-element))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:next-input-element re) (:white-space (:input-element re)) next-input-element-re
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :input-element)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:next-input-element div) (:white-space (:input-element div)) next-input-element-div
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :input-element)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production (:next-input-element num) ((:- :continuing-identifier-character #\\) :white-space (:input-element div)) next-input-element-num
|
|
|
|
(lex (lex :input-element))))
|
1999-12-07 22:09:10 +00:00
|
|
|
|
|
|
|
(%print-actions)
|
|
|
|
|
2001-03-09 02:10:15 +00:00
|
|
|
(rule (:input-element :nu_2)
|
2001-04-12 04:31:46 +00:00
|
|
|
((lex input-element))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:line-breaks) input-element-line-breaks
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex line-break))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:identifier-or-keyword) input-element-identifier-or-keyword
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :identifier-or-keyword)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:punctuator) input-element-punctuator
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :punctuator)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element div) (:division-punctuator) input-element-division-punctuator
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :division-punctuator)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:numeric-literal) input-element-numeric-literal
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :numeric-literal)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:string-literal) input-element-string-literal
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :string-literal)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element re) (:reg-exp-literal) input-element-reg-exp-literal
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex (lex :reg-exp-literal)))
|
2001-03-09 02:10:15 +00:00
|
|
|
(production (:input-element :nu_2) (:end-of-input) input-element-end
|
2001-04-12 04:31:46 +00:00
|
|
|
(lex end-of-input)))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(production :end-of-input ($end) end-of-input-end)
|
|
|
|
(production :end-of-input (:line-comment $end) end-of-input-line-comment)
|
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Keywords and Identifiers")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2002-10-29 01:12:27 +00:00
|
|
|
(rule :identifier-or-keyword
|
|
|
|
((lex input-element))
|
|
|
|
(production :identifier-or-keyword (:identifier-name) identifier-or-keyword-identifier-name
|
|
|
|
(lex (begin
|
2003-06-05 01:34:45 +00:00
|
|
|
(const id string (lex :identifier-name))
|
2002-10-29 01:12:27 +00:00
|
|
|
(if (and (set-in id (list-set "abstract" "as" "break" "case" "catch" "class" "const" "continue" "debugger" "default" "delete" "do" "else" "enum"
|
2003-06-05 01:34:45 +00:00
|
|
|
"export" "extends" "false" "finally" "for" "function" "get" "goto" "if" "implements" "import" "in"
|
|
|
|
"instanceof" "interface" "is" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return"
|
2003-05-23 01:07:54 +00:00
|
|
|
"set" "super" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "use"
|
2002-10-29 01:12:27 +00:00
|
|
|
"var" "volatile" "while" "with"))
|
|
|
|
(not (contains-escapes :identifier-name)))
|
|
|
|
(return (new keyword id))
|
|
|
|
(return (new identifier id)))))))
|
|
|
|
(%print-actions)
|
|
|
|
|
1999-05-10 20:52:58 +00:00
|
|
|
(rule :identifier-name
|
2003-06-05 01:34:45 +00:00
|
|
|
((lex string) (contains-escapes boolean))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :identifier-name (:initial-identifier-character-or-escape) identifier-name-initial
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (vector (lex :initial-identifier-character-or-escape)))
|
2000-10-28 05:55:19 +00:00
|
|
|
(contains-escapes (contains-escapes :initial-identifier-character-or-escape)))
|
|
|
|
(production :identifier-name (:null-escapes :initial-identifier-character-or-escape) identifier-name-initial-null-escapes
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (vector (lex :initial-identifier-character-or-escape)))
|
2000-08-22 04:29:34 +00:00
|
|
|
(contains-escapes true))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :identifier-name (:identifier-name :continuing-identifier-character-or-escape) identifier-name-continuing
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (append (lex :identifier-name) (vector (lex :continuing-identifier-character-or-escape))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(contains-escapes (or (contains-escapes :identifier-name)
|
2000-10-28 05:55:19 +00:00
|
|
|
(contains-escapes :continuing-identifier-character-or-escape))))
|
2000-08-22 04:29:34 +00:00
|
|
|
(production :identifier-name (:identifier-name :null-escape) identifier-name-null-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :identifier-name))
|
2000-08-22 04:29:34 +00:00
|
|
|
(contains-escapes true)))
|
2000-10-28 05:55:19 +00:00
|
|
|
|
2000-08-22 04:29:34 +00:00
|
|
|
(production :null-escapes (:null-escape) null-escapes-one)
|
|
|
|
(production :null-escapes (:null-escapes :null-escape) null-escapes-more)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-02-23 00:04:17 +00:00
|
|
|
(production :null-escape (#\\ #\_) null-escape-underscore)
|
2000-10-28 05:55:19 +00:00
|
|
|
|
|
|
|
(rule :initial-identifier-character-or-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
((lex char16) (contains-escapes boolean))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :initial-identifier-character-or-escape (:initial-identifier-character) initial-identifier-character-or-escape-ordinary
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ($default-action :initial-identifier-character))
|
1999-05-10 20:52:58 +00:00
|
|
|
(contains-escapes false))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :initial-identifier-character-or-escape (#\\ :hex-escape) initial-identifier-character-or-escape-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (begin
|
|
|
|
(const ch char16 (lex :hex-escape))
|
2003-06-30 22:12:21 +00:00
|
|
|
(if (lisp-call initial-identifier-character? (ch)
|
|
|
|
boolean
|
|
|
|
"the nonterminal " (:grammar-symbol :initial-identifier-character) " can expand into " (:expr string (vector ch)))
|
2003-06-05 01:34:45 +00:00
|
|
|
(return ch)
|
|
|
|
(throw syntax-error))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(contains-escapes true)))
|
|
|
|
|
2000-10-28 05:55:19 +00:00
|
|
|
(%charclass :initial-identifier-character)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2000-10-28 05:55:19 +00:00
|
|
|
(rule :continuing-identifier-character-or-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
((lex char16) (contains-escapes boolean))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :continuing-identifier-character-or-escape (:continuing-identifier-character) continuing-identifier-character-or-escape-ordinary
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ($default-action :continuing-identifier-character))
|
1999-05-10 20:52:58 +00:00
|
|
|
(contains-escapes false))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :continuing-identifier-character-or-escape (#\\ :hex-escape) continuing-identifier-character-or-escape-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (begin
|
|
|
|
(const ch char16 (lex :hex-escape))
|
2003-06-30 22:12:21 +00:00
|
|
|
(if (lisp-call continuing-identifier-character? (ch)
|
|
|
|
boolean
|
|
|
|
"the nonterminal " (:grammar-symbol :continuing-identifier-character) " can expand into " (:expr string (vector ch)))
|
2003-06-05 01:34:45 +00:00
|
|
|
(return ch)
|
|
|
|
(throw syntax-error))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(contains-escapes true)))
|
|
|
|
|
2000-10-28 05:55:19 +00:00
|
|
|
(%charclass :continuing-identifier-character)
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Punctuators")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-04-12 04:31:46 +00:00
|
|
|
(rule :punctuator ((lex token))
|
2001-09-10 22:10:36 +00:00
|
|
|
(production :punctuator (#\!) punctuator-not (lex (new punctuator "!")))
|
|
|
|
(production :punctuator (#\! #\=) punctuator-not-equal (lex (new punctuator "!=")))
|
|
|
|
(production :punctuator (#\! #\= #\=) punctuator-not-identical (lex (new punctuator "!==")))
|
|
|
|
(production :punctuator (#\%) punctuator-modulo (lex (new punctuator "%")))
|
|
|
|
(production :punctuator (#\% #\=) punctuator-modulo-equals (lex (new punctuator "%=")))
|
|
|
|
(production :punctuator (#\&) punctuator-and (lex (new punctuator "&")))
|
|
|
|
(production :punctuator (#\& #\&) punctuator-logical-and (lex (new punctuator "&&")))
|
|
|
|
(production :punctuator (#\& #\& #\=) punctuator-logical-and-equals (lex (new punctuator "&&=")))
|
|
|
|
(production :punctuator (#\& #\=) punctuator-and-equals (lex (new punctuator "&=")))
|
|
|
|
(production :punctuator (#\() punctuator-open-parenthesis (lex (new punctuator "(")))
|
|
|
|
(production :punctuator (#\)) punctuator-close-parenthesis (lex (new punctuator ")")))
|
|
|
|
(production :punctuator (#\*) punctuator-times (lex (new punctuator "*")))
|
|
|
|
(production :punctuator (#\* #\=) punctuator-times-equals (lex (new punctuator "*=")))
|
|
|
|
(production :punctuator (#\+) punctuator-plus (lex (new punctuator "+")))
|
|
|
|
(production :punctuator (#\+ #\+) punctuator-increment (lex (new punctuator "++")))
|
|
|
|
(production :punctuator (#\+ #\=) punctuator-plus-equals (lex (new punctuator "+=")))
|
|
|
|
(production :punctuator (#\,) punctuator-comma (lex (new punctuator ",")))
|
|
|
|
(production :punctuator (#\-) punctuator-minus (lex (new punctuator "-")))
|
|
|
|
(production :punctuator (#\- #\-) punctuator-decrement (lex (new punctuator "--")))
|
|
|
|
(production :punctuator (#\- #\=) punctuator-minus-equals (lex (new punctuator "-=")))
|
|
|
|
(production :punctuator (#\.) punctuator-dot (lex (new punctuator ".")))
|
|
|
|
(production :punctuator (#\. #\. #\.) punctuator-triple-dot (lex (new punctuator "...")))
|
|
|
|
(production :punctuator (#\:) punctuator-colon (lex (new punctuator ":")))
|
|
|
|
(production :punctuator (#\: #\:) punctuator-namespace (lex (new punctuator "::")))
|
|
|
|
(production :punctuator (#\;) punctuator-semicolon (lex (new punctuator ";")))
|
|
|
|
(production :punctuator (#\<) punctuator-less-than (lex (new punctuator "<")))
|
|
|
|
(production :punctuator (#\< #\<) punctuator-left-shift (lex (new punctuator "<<")))
|
|
|
|
(production :punctuator (#\< #\< #\=) punctuator-left-shift-equals (lex (new punctuator "<<=")))
|
|
|
|
(production :punctuator (#\< #\=) punctuator-less-than-or-equal (lex (new punctuator "<=")))
|
|
|
|
(production :punctuator (#\=) punctuator-assignment (lex (new punctuator "=")))
|
|
|
|
(production :punctuator (#\= #\=) punctuator-equal (lex (new punctuator "==")))
|
|
|
|
(production :punctuator (#\= #\= #\=) punctuator-identical (lex (new punctuator "===")))
|
|
|
|
(production :punctuator (#\>) punctuator-greater-than (lex (new punctuator ">")))
|
|
|
|
(production :punctuator (#\> #\=) punctuator-greater-than-or-equal (lex (new punctuator ">=")))
|
|
|
|
(production :punctuator (#\> #\>) punctuator-right-shift (lex (new punctuator ">>")))
|
|
|
|
(production :punctuator (#\> #\> #\=) punctuator-right-shift-equals (lex (new punctuator ">>=")))
|
|
|
|
(production :punctuator (#\> #\> #\>) punctuator-logical-right-shift (lex (new punctuator ">>>")))
|
|
|
|
(production :punctuator (#\> #\> #\> #\=) punctuator-logical-right-shift-equals (lex (new punctuator ">>>=")))
|
|
|
|
(production :punctuator (#\?) punctuator-question (lex (new punctuator "?")))
|
|
|
|
(production :punctuator (#\[) punctuator-open-bracket (lex (new punctuator "[")))
|
|
|
|
(production :punctuator (#\]) punctuator-close-bracket (lex (new punctuator "]")))
|
|
|
|
(production :punctuator (#\^) punctuator-xor (lex (new punctuator "^")))
|
|
|
|
(production :punctuator (#\^ #\=) punctuator-xor-equals (lex (new punctuator "^=")))
|
|
|
|
(production :punctuator (#\^ #\^) punctuator-logical-xor (lex (new punctuator "^^")))
|
|
|
|
(production :punctuator (#\^ #\^ #\=) punctuator-logical-xor-equals (lex (new punctuator "^^=")))
|
|
|
|
(production :punctuator (#\{) punctuator-open-brace (lex (new punctuator "{")))
|
|
|
|
(production :punctuator (#\|) punctuator-or (lex (new punctuator "|")))
|
|
|
|
(production :punctuator (#\| #\=) punctuator-or-equals (lex (new punctuator "|=")))
|
|
|
|
(production :punctuator (#\| #\|) punctuator-logical-or (lex (new punctuator "||")))
|
|
|
|
(production :punctuator (#\| #\| #\=) punctuator-logical-or-equals (lex (new punctuator "||=")))
|
|
|
|
(production :punctuator (#\}) punctuator-close-brace (lex (new punctuator "}")))
|
|
|
|
(production :punctuator (#\~) punctuator-complement (lex (new punctuator "~"))))
|
2001-04-12 04:31:46 +00:00
|
|
|
|
|
|
|
(rule :division-punctuator ((lex token))
|
2001-09-10 22:10:36 +00:00
|
|
|
(production :division-punctuator (#\/ (:- #\/ #\*)) punctuator-divide (lex (new punctuator "/")))
|
|
|
|
(production :division-punctuator (#\/ #\=) punctuator-divide-equals (lex (new punctuator "/="))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Numeric Literals")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-04-12 04:31:46 +00:00
|
|
|
(rule :numeric-literal ((lex token))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :numeric-literal ((:decimal-literal no-leading-zeros)) numeric-literal-decimal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new number-token (real-to-float64 (lex :decimal-literal)))))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production :numeric-literal (:hex-integer-literal) numeric-literal-hex
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new number-token (real-to-float64 (lex :hex-integer-literal)))))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :numeric-literal ((:decimal-literal no-leading-zeros) :letter-f) numeric-literal-single
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new number-token (real-to-float32 (lex :decimal-literal)))))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production :numeric-literal (:integer-literal :letter-l) numeric-literal-long
|
|
|
|
(lex (begin
|
2003-06-05 01:34:45 +00:00
|
|
|
(const i integer (lex :integer-literal))
|
2002-09-25 23:51:12 +00:00
|
|
|
(cond
|
2002-10-29 01:12:27 +00:00
|
|
|
((<= i (- (expt 2 63) 1)) (return (new number-token (new long i))))
|
2002-09-25 23:51:12 +00:00
|
|
|
((= i (expt 2 63)) (return negated-min-long))
|
|
|
|
(nil (throw range-error))))))
|
|
|
|
(production :numeric-literal (:integer-literal :letter-u :letter-l) numeric-literal-unsigned-long
|
|
|
|
(lex (begin
|
2003-06-05 01:34:45 +00:00
|
|
|
(const i integer (lex :integer-literal))
|
2002-09-25 23:51:12 +00:00
|
|
|
(if (<= i (- (expt 2 64) 1))
|
2002-10-29 01:12:27 +00:00
|
|
|
(return (new number-token (new u-long i)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(throw range-error))))))
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :integer-literal ((lex integer))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :integer-literal ((:decimal-integer-literal no-leading-zeros)) integer-literal-decimal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :decimal-integer-literal)))
|
2002-09-25 23:51:12 +00:00
|
|
|
(production :integer-literal (:hex-integer-literal) integer-literal-hex
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :hex-integer-literal))))
|
2002-09-25 23:51:12 +00:00
|
|
|
(%charclass :letter-f)
|
|
|
|
(%charclass :letter-l)
|
|
|
|
(%charclass :letter-u)
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(grammar-argument :zeta no-leading-zeros allow-leading-zeros)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule (:decimal-literal :zeta) ((lex rational))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:decimal-literal :zeta) ((:mantissa :zeta)) decimal-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :mantissa)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:decimal-literal :zeta) ((:mantissa :zeta) :letter-e :signed-integer) decimal-literal-exponent
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (rat* (lex :mantissa) (expt 10 (lex :signed-integer))))))
|
1999-06-07 21:57:29 +00:00
|
|
|
|
|
|
|
(%charclass :letter-e)
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule (:mantissa :zeta) ((lex rational))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:mantissa :zeta) ((:decimal-integer-literal :zeta)) mantissa-integer
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :decimal-integer-literal)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:mantissa :zeta) ((:decimal-integer-literal :zeta) #\.) mantissa-integer-dot
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :decimal-integer-literal)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:mantissa :zeta) ((:decimal-integer-literal :zeta) #\. :fraction) mantissa-integer-dot-fraction
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (rat+ (lex :decimal-integer-literal) (lex :fraction))))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:mantissa :zeta) (#\. :fraction) mantissa-dot-fraction
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :fraction))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule (:decimal-integer-literal :zeta) ((lex integer))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:decimal-integer-literal no-leading-zeros) (#\0) decimal-integer-literal-0
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex 0))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:decimal-integer-literal no-leading-zeros) (:non-zero-decimal-digits) decimal-integer-literal-nonzero
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :non-zero-decimal-digits)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production (:decimal-integer-literal allow-leading-zeros) (:decimal-digits) decimal-integer-literal-decimal-digits
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :decimal-digits))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :non-zero-decimal-digits ((lex integer))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :non-zero-decimal-digits (:non-zero-digit) non-zero-decimal-digits-first
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (decimal-value :non-zero-digit)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :non-zero-decimal-digits (:non-zero-decimal-digits :a-s-c-i-i-digit) non-zero-decimal-digits-rest
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (+ (* 10 (lex :non-zero-decimal-digits)) (decimal-value :a-s-c-i-i-digit)))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(%charclass :non-zero-digit)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :fraction ((lex rational))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :fraction (:decimal-digits) fraction-decimal-digits
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (rat/ (lex :decimal-digits)
|
|
|
|
(expt 10 (n-digits :decimal-digits))))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :signed-integer ((lex integer))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :signed-integer (:optional-sign :decimal-digits) signed-integer-sign-and-digits
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (* (lex :optional-sign) (lex :decimal-digits)))))
|
2003-05-23 01:07:54 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :optional-sign ((lex (integer-list -1 1)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :optional-sign () optional-sign-none
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex 1))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :optional-sign (#\+) optional-sign-plus
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex 1))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :optional-sign (#\-) optional-sign-minus
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex -1)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
|
|
|
(rule :decimal-digits
|
2003-06-05 01:34:45 +00:00
|
|
|
((lex integer) (n-digits integer))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :decimal-digits (:a-s-c-i-i-digit) decimal-digits-first
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (decimal-value :a-s-c-i-i-digit))
|
1999-05-10 20:52:58 +00:00
|
|
|
(n-digits 1))
|
|
|
|
(production :decimal-digits (:decimal-digits :a-s-c-i-i-digit) decimal-digits-rest
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (+ (* 10 (lex :decimal-digits)) (decimal-value :a-s-c-i-i-digit)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(n-digits (+ (n-digits :decimal-digits) 1))))
|
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :hex-integer-literal ((lex integer))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :hex-integer-literal (#\0 :letter-x :hex-digit) hex-integer-literal-first
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (hex-value :hex-digit)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :hex-integer-literal (:hex-integer-literal :hex-digit) hex-integer-literal-rest
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (+ (* 16 (lex :hex-integer-literal)) (hex-value :hex-digit)))))
|
1999-06-07 21:57:29 +00:00
|
|
|
(%charclass :letter-x)
|
1999-05-10 20:52:58 +00:00
|
|
|
(%charclass :hex-digit)
|
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "String Literals")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(grammar-argument :theta single double)
|
2001-04-12 04:31:46 +00:00
|
|
|
(rule :string-literal ((lex token))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :string-literal (#\' (:string-chars single) #\') string-literal-single
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new string-token (lex :string-chars))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :string-literal (#\" (:string-chars double) #\") string-literal-double
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new string-token (lex :string-chars)))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule (:string-chars :theta) ((lex string))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production (:string-chars :theta) () string-chars-none
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ""))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production (:string-chars :theta) ((:string-chars :theta) (:string-char :theta)) string-chars-some
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (append (lex :string-chars)
|
|
|
|
(vector (lex :string-char)))))
|
2000-08-22 04:29:34 +00:00
|
|
|
(production (:string-chars :theta) ((:string-chars :theta) :null-escape) string-chars-null-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :string-chars))))
|
1999-06-07 21:57:29 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule (:string-char :theta) ((lex char16))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production (:string-char :theta) ((:literal-string-char :theta)) string-char-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ($default-action :literal-string-char)))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production (:string-char :theta) (#\\ :string-escape) string-char-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :string-escape))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
1999-06-07 21:57:29 +00:00
|
|
|
(%charclass (:literal-string-char single))
|
|
|
|
(%charclass (:literal-string-char double))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :string-escape ((lex char16))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :string-escape (:control-escape) string-escape-control
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :control-escape)))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :string-escape (:zero-escape) string-escape-zero
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :zero-escape)))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :string-escape (:hex-escape) string-escape-hex
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :hex-escape)))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :string-escape (:identity-escape) string-escape-non-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ($default-action :identity-escape))))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%charclass :identity-escape)
|
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :control-escape ((lex char16))
|
|
|
|
(production :control-escape (#\b) control-escape-backspace (lex #?0008))
|
|
|
|
(production :control-escape (#\f) control-escape-form-feed (lex #?000C))
|
|
|
|
(production :control-escape (#\n) control-escape-new-line (lex #?000A))
|
|
|
|
(production :control-escape (#\r) control-escape-return (lex #?000D))
|
|
|
|
(production :control-escape (#\t) control-escape-tab (lex #?0009))
|
|
|
|
(production :control-escape (#\v) control-escape-vertical-tab (lex #?000B)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :zero-escape ((lex char16))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :zero-escape (#\0 (:- :a-s-c-i-i-digit)) zero-escape-zero
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex #?0000)))
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :hex-escape ((lex char16))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :hex-escape (#\x :hex-digit :hex-digit) hex-escape-2
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (integer-to-char16 (+ (* 16 (hex-value :hex-digit 1))
|
|
|
|
(hex-value :hex-digit 2)))))
|
1999-06-07 21:57:29 +00:00
|
|
|
(production :hex-escape (#\u :hex-digit :hex-digit :hex-digit :hex-digit) hex-escape-4
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (integer-to-char16 (+ (+ (+ (* 4096 (hex-value :hex-digit 1))
|
|
|
|
(* 256 (hex-value :hex-digit 2)))
|
|
|
|
(* 16 (hex-value :hex-digit 3)))
|
|
|
|
(hex-value :hex-digit 4)))))
|
|
|
|
(production :hex-escape (#\U :hex-digit :hex-digit :hex-digit :hex-digit :hex-digit :hex-digit :hex-digit :hex-digit) hex-escape-8
|
|
|
|
(lex (todo))))
|
2000-10-28 05:55:19 +00:00
|
|
|
|
1999-05-10 20:52:58 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-05-23 01:07:54 +00:00
|
|
|
(%heading 2 "Regular Expression Literals")
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2001-04-12 04:31:46 +00:00
|
|
|
(rule :reg-exp-literal ((lex token))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :reg-exp-literal (:reg-exp-body :reg-exp-flags) reg-exp-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (new regular-expression (lex :reg-exp-body) (lex :reg-exp-flags)))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :reg-exp-flags ((lex string))
|
1999-05-10 20:52:58 +00:00
|
|
|
(production :reg-exp-flags () reg-exp-flags-none
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex ""))
|
2000-10-28 05:55:19 +00:00
|
|
|
(production :reg-exp-flags (:reg-exp-flags :continuing-identifier-character-or-escape) reg-exp-flags-more
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (append (lex :reg-exp-flags) (vector (lex :continuing-identifier-character-or-escape)))))
|
2000-08-22 04:29:34 +00:00
|
|
|
(production :reg-exp-flags (:reg-exp-flags :null-escape) reg-exp-flags-null-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :reg-exp-flags))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :reg-exp-body ((lex string))
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :reg-exp-body (#\/ (:- #\*) :reg-exp-chars #\/) reg-exp-body
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :reg-exp-chars))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :reg-exp-chars ((lex string))
|
1999-12-07 22:09:10 +00:00
|
|
|
(production :reg-exp-chars (:reg-exp-char) reg-exp-chars-one
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :reg-exp-char)))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :reg-exp-chars (:reg-exp-chars :reg-exp-char) reg-exp-chars-more
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (append (lex :reg-exp-chars) (lex :reg-exp-char)))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :reg-exp-char ((lex string))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :reg-exp-char (:ordinary-reg-exp-char) reg-exp-char-ordinary
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (vector ($default-action :ordinary-reg-exp-char))))
|
1999-10-20 00:43:22 +00:00
|
|
|
(production :reg-exp-char (#\\ :non-terminator) reg-exp-char-escape
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (vector #\\ ($default-action :non-terminator)))))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
1999-10-20 00:43:22 +00:00
|
|
|
(%charclass :ordinary-reg-exp-char)
|
2003-05-23 01:07:54 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
2003-06-30 22:12:21 +00:00
|
|
|
(%heading 1 "String-to-Number Conversion")
|
2003-05-23 01:07:54 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :string-numeric-literal ((lex extended-rational))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :string-numeric-literal (:string-white-space) string-numeric-literal-white-space
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex +zero))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :string-numeric-literal (:string-white-space :signed-decimal-literal :string-white-space) string-numeric-literal-signed-decimal-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :signed-decimal-literal)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :string-numeric-literal (:string-white-space :optional-sign :hex-integer-literal :string-white-space) string-numeric-literal-hex-integer-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (combine-with-sign (lex :optional-sign) (lex :hex-integer-literal)))))
|
2003-05-23 01:07:54 +00:00
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :signed-decimal-literal ((lex extended-rational))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :signed-decimal-literal (:optional-sign (:decimal-literal allow-leading-zeros)) signed-decimal-literal-decimal-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (combine-with-sign (lex :optional-sign) (lex :decimal-literal))))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :signed-decimal-literal (:optional-sign #\I #\n #\f #\i #\n #\i #\t #\y) signed-decimal-literal-infinity
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (if (> (lex :optional-sign) 0) +infinity -infinity)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :signed-decimal-literal (#\N #\a #\N) signed-decimal-literal-nan
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex nan)))
|
2003-06-30 22:12:21 +00:00
|
|
|
|
|
|
|
(production :string-white-space () string-white-space-empty)
|
|
|
|
(production :string-white-space (:string-white-space :white-space-or-line-terminator-char) string-white-space-character)
|
|
|
|
(%charclass :white-space-or-line-terminator-char)
|
|
|
|
|
|
|
|
(deftag +zero)
|
|
|
|
(deftag -zero)
|
|
|
|
(deftag +infinity)
|
|
|
|
(deftag -infinity)
|
|
|
|
(deftag nan)
|
|
|
|
(deftype extended-rational (union rational (tag +zero -zero +infinity -infinity nan)))
|
2003-05-23 01:07:54 +00:00
|
|
|
(%print-actions)
|
|
|
|
|
|
|
|
(define (combine-with-sign (sign (integer-list -1 1)) (q rational)) extended-rational
|
|
|
|
(cond
|
|
|
|
((/= q 0 rational) (return (rat* sign q)))
|
|
|
|
((> sign 0) (return +zero))
|
|
|
|
(nil (return -zero))))
|
|
|
|
|
|
|
|
(%heading 2 "parseFloat Conversion")
|
|
|
|
|
2003-06-05 01:34:45 +00:00
|
|
|
(rule :string-decimal-literal ((lex extended-rational))
|
2003-05-23 01:07:54 +00:00
|
|
|
(production :string-decimal-literal (:string-white-space :signed-decimal-literal) string-decimal-literal-signed-decimal-literal
|
2003-06-05 01:34:45 +00:00
|
|
|
(lex (lex :signed-decimal-literal))))
|
2003-05-23 01:07:54 +00:00
|
|
|
(%print-actions)
|
1999-05-10 20:52:58 +00:00
|
|
|
)))
|
|
|
|
|
|
|
|
(defparameter *ll* (world-lexer *lw* 'code-lexer))
|
|
|
|
(defparameter *lg* (lexer-grammar *ll*))
|
|
|
|
(set-up-lexer-metagrammar *ll*)
|
|
|
|
(defparameter *lm* (lexer-metagrammar *ll*)))
|
|
|
|
|
1999-12-07 22:09:10 +00:00
|
|
|
|
2003-06-30 22:12:21 +00:00
|
|
|
; Convert the string to an extended-rational if the entire string is an expansion of the :string-numeric-literal nonterminal.
|
2003-05-23 01:07:54 +00:00
|
|
|
(defun string-to-extended-rational (string)
|
|
|
|
(handler-case
|
|
|
|
(first (action-parse *lg* (lexer-classifier *ll*) (cons '$string-to-number (coerce string 'list))))
|
|
|
|
(syntax-error () :syntax-error)))
|
|
|
|
|
|
|
|
|
2003-06-30 22:12:21 +00:00
|
|
|
; Convert the string to an extended-rational if a prefix of the string is an expansion of the :string-decimal-literal nonterminal.
|
|
|
|
; Pick the longest prefix that works. No indication is given of any ignored trailing characters.
|
|
|
|
(defun string-prefix-to-float (string)
|
|
|
|
(handler-case
|
|
|
|
(first (action-metaparse *lm* (lexer-classifier *ll*) (cons '$parse-float (coerce string 'list))))
|
|
|
|
(syntax-error () :syntax-error)))
|
|
|
|
|
|
|
|
|
2001-10-23 22:46:26 +00:00
|
|
|
(defun dump-lexer ()
|
|
|
|
(values
|
|
|
|
(depict-rtf-to-local-file
|
|
|
|
"JS20/LexerGrammar.rtf"
|
|
|
|
"JavaScript 2 Lexical Grammar"
|
|
|
|
#'(lambda (rtf-stream)
|
|
|
|
(depict-world-commands rtf-stream *lw* :heading-offset 1 :visible-semantics nil)))
|
|
|
|
(depict-rtf-to-local-file
|
|
|
|
"JS20/LexerSemantics.rtf"
|
|
|
|
"JavaScript 2 Lexical Semantics"
|
|
|
|
#'(lambda (rtf-stream)
|
|
|
|
(depict-world-commands rtf-stream *lw* :heading-offset 1)))
|
|
|
|
(depict-html-to-local-file
|
|
|
|
"JS20/LexerGrammar.html"
|
|
|
|
"JavaScript 2 Lexical Grammar"
|
|
|
|
t
|
|
|
|
#'(lambda (rtf-stream)
|
|
|
|
(depict-world-commands rtf-stream *lw* :heading-offset 1 :visible-semantics nil))
|
|
|
|
:external-link-base "notation.html")
|
|
|
|
(depict-html-to-local-file
|
|
|
|
"JS20/LexerSemantics.html"
|
|
|
|
"JavaScript 2 Lexical Semantics"
|
|
|
|
t
|
|
|
|
#'(lambda (rtf-stream)
|
|
|
|
(depict-world-commands rtf-stream *lw* :heading-offset 1))
|
|
|
|
:external-link-base "notation.html")))
|
|
|
|
|
|
|
|
|
1999-05-10 20:52:58 +00:00
|
|
|
#|
|
2001-10-23 22:46:26 +00:00
|
|
|
(dump-lexer)
|
|
|
|
|
1999-05-10 20:52:58 +00:00
|
|
|
(depict-rtf-to-local-file
|
1999-11-20 02:16:56 +00:00
|
|
|
"JS20/LexerCharClasses.rtf"
|
2001-03-09 02:10:15 +00:00
|
|
|
"JavaScript 2 Lexical Character Classes"
|
1999-05-10 20:52:58 +00:00
|
|
|
#'(lambda (rtf-stream)
|
2001-04-12 04:31:46 +00:00
|
|
|
(depict-paragraph (rtf-stream :grammar-header)
|
1999-05-10 20:52:58 +00:00
|
|
|
(depict rtf-stream "Character Classes"))
|
|
|
|
(dolist (charclass (lexer-charclasses *ll*))
|
|
|
|
(depict-charclass rtf-stream charclass))
|
2001-04-12 04:31:46 +00:00
|
|
|
(depict-paragraph (rtf-stream :grammar-header)
|
1999-05-10 20:52:58 +00:00
|
|
|
(depict rtf-stream "Grammar"))
|
|
|
|
(depict-grammar rtf-stream *lg*)))
|
|
|
|
|
1999-11-20 02:16:56 +00:00
|
|
|
(with-local-output (s "JS20/LexerGrammar.txt") (print-lexer *ll* s) (print-grammar *lg* s))
|
1999-05-10 20:52:58 +00:00
|
|
|
|
|
|
|
(print-illegal-strings m)
|
|
|
|
|#
|
|
|
|
|
|
|
|
|
1999-12-04 05:04:08 +00:00
|
|
|
#+allegro (clean-grammar *lg*) ;Remove this line if you wish to print the grammar's state tables.
|
1999-06-08 00:44:52 +00:00
|
|
|
(length (grammar-states *lg*))
|