add undocumented unary operators

This commit is contained in:
xenia 2020-09-09 23:09:47 -04:00
parent 1b7b13d16e
commit 90c8538be4
1 changed files with 8 additions and 4 deletions

View File

@ -6,8 +6,8 @@
parser-tools/yacc) parser-tools/yacc)
(define-tokens kaitai-expr [boolean number string identifier]) (define-tokens kaitai-expr [boolean number string identifier])
(define-empty-tokens kaitai-sym [eof + - * / % < <= > >= == != << >> & pipe ^ not and or ? : (define-empty-tokens kaitai-sym [eof + - * / % < <= > >= == != << >> & pipe ^ not and or ? : ~
lparen rparen lbracket comma dot rbracket]) lparen rparen lbracket comma dot rbracket])
(define (kaitai-numstr->number str) (define (kaitai-numstr->number str)
(match (regexp-replace* #px"_" str "") (match (regexp-replace* #px"_" str "")
@ -52,6 +52,7 @@
["&" (token-&)] ["&" (token-&)]
["|" (token-pipe)] ["|" (token-pipe)]
["^" (token-^)] ["^" (token-^)]
["~" (token-~)]
["not" (token-not)] ["not" (token-not)]
["and" (token-and)] ["and" (token-and)]
["or" (token-or)] ["or" (token-or)]
@ -81,7 +82,7 @@
(left & pipe ^) (left & pipe ^)
(left < <= > >= != ==) (left < <= > >= != ==)
(left << >>) (left << >>)
(left + -) (left + - ~)
(left * / %) (left * / %)
(right not) (right not)
(left dot lparen rparen lbracket rbracket)] (left dot lparen rparen lbracket rbracket)]
@ -112,6 +113,9 @@
[(exp and exp) (list 'and $1 $3)] [(exp and exp) (list 'and $1 $3)]
[(exp or exp) (list 'or $1 $3)] [(exp or exp) (list 'or $1 $3)]
[(not exp) (list 'not $2)] [(not exp) (list 'not $2)]
[(+ exp) (list '+ $2)]
[(- exp) (list '- $2)]
[(~ exp) (list '~ $2)]
[(exp ? exp : exp) (list 'if $1 $3 $5)] [(exp ? exp : exp) (list 'if $1 $3 $5)]
[(lparen exp rparen) $2]) [(lparen exp rparen) $2])
(apply-args (apply-args
@ -119,7 +123,7 @@
[(exp comma apply-args) (cons $1 $3)]) [(exp comma apply-args) (cons $1 $3)])
])) ]))
(define test2 "true and 'a' != 'b' ? 1 : ('hello' + 'world').substring(2, 3)") (define test2 "true and 'a' != 'b' ? -1 + ~bits : ('hello' + 'world').substring(2, 3)")
(let ([input (open-input-string test2)]) (let ([input (open-input-string test2)])
(kaitai-parser (lambda () (kaitai-lexer input)))) (kaitai-parser (lambda () (kaitai-lexer input))))