Skip to content

Commit

Permalink
use hash tables more for token predicates in parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 27, 2014
1 parent 4efd1b6 commit 7c65a93
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
<<= >>= >>>= -> --> |\|\|| && |.| ... |.+=| |.-=|))
(define syntactic-unary-operators '($ & |::|))

(define (syntactic-op? op) (memq op syntactic-operators))
(define (syntactic-unary-op? op) (memq op syntactic-unary-operators))
(define syntactic-op? (Set syntactic-operators))
(define syntactic-unary-op? (Set syntactic-unary-operators))

(define trans-op (string->symbol ".'"))
(define ctrans-op (string->symbol "'"))
Expand All @@ -77,7 +77,7 @@
(define (opchar? c) (and (char? c) (string.find op-chars c)))
;; characters that can follow . in an operator
(define (dot-opchar? c) (and (char? c) (string.find ".*^/\\+-'<>!=%" c)))
(define (operator? c) (memq c operators))
(define operator? (Set operators))

(define reserved-words '(begin while if for try return break continue
function macro quote let local global const
Expand Down Expand Up @@ -815,7 +815,7 @@
(parse-juxtapose
(read-number (ts:port s) (eqv? nch #\.) (eq? op '-))
s)))
(if (memq (peek-token s) '(^ |.^|))
(if (is-prec-power? (peek-token s))
;; -2^x parsed as (- (^ 2 x))
(begin (ts:put-back! s (maybe-negate op num))
(list 'call op (parse-factor s)))
Expand Down Expand Up @@ -1636,7 +1636,7 @@
; parse numbers, identifiers, parenthesized expressions, lists, vectors, etc.
(define (parse-atom s)
(let ((ex (parse-atom- s)))
(if (or (memq ex syntactic-operators)
(if (or (syntactic-op? ex)
(eq? ex '....))
(error (string "invalid identifier name \"" ex "\"")))
ex))
Expand Down Expand Up @@ -1697,7 +1697,7 @@
((eqv? (require-token s) #\) )
;; empty tuple ()
(begin (take-token s) '(tuple)))
((memq (peek-token s) syntactic-operators)
((syntactic-op? (peek-token s))
;; allow (=) etc.
(let ((tok (take-token s)))
(if (not (eqv? (require-token s) #\) ))
Expand Down
2 changes: 1 addition & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@
,.(map (lambda (x) `(,what ,x)) vars)
,.(reverse assigns)))
(let ((x (car b)))
(cond ((and (pair? x) (memq (car x) prec-assignment))
(cond ((assignment-like? x)
(loop (cdr b)
(cons (assigned-name (cadr x)) vars)
(cons `(,(car x) ,(decl-var (cadr x)) ,(caddr x))
Expand Down

0 comments on commit 7c65a93

Please sign in to comment.