Commit 333c0168 authored by Stefan Marr's avatar Stefan Marr

Added support for double literals

Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent 746a6041
......@@ -25,10 +25,19 @@ class Lexer(object):
self._symc = '\0'
self._text = ''
saw_decimal_mark = False
while self._current_char().isdigit():
self._text += self._current_char()
self._bufp += 1
if (not saw_decimal_mark and '.' == self._current_char() and
self._bufchar(self._bufp + 1).isdigit()):
self._sym = Symbol.Double
saw_decimal_mark = True
self._text += self._current_char()
self._bufp += 1
def _lex_operator(self):
if self._is_operator(self._bufchar(self._bufp + 1)):
self._sym = Symbol.OperatorSequence
......
......@@ -465,30 +465,42 @@ class Parser(object):
def _literal_number(self, mgenc):
if self._sym == Symbol.Minus:
val = self._negative_decimal()
lit = self._negative_decimal()
else:
val = self._literal_decimal()
lit = self._literal_decimal(False)
if integer_value_fits(val):
lit = self._universe.new_integer(val)
else:
lit = self._universe.new_biginteger(val)
mgenc.add_literal_if_absent(lit)
self._bc_gen.emitPUSHCONSTANT(mgenc, lit)
def _literal_decimal(self):
return self._literal_integer()
def _literal_decimal(self, negate_value):
if self._sym == Symbol.Integer:
return self._literal_integer(negate_value)
else:
assert self._sym == Symbol.Double
return self._literal_double(negate_value)
def _negative_decimal(self):
self._expect(Symbol.Minus)
return -self._literal_integer()
return self._literal_decimal(True)
def _literal_integer(self):
def _literal_integer(self, negate_value):
i = int(self._text)
if negate_value:
i = 0 - i
self._expect(Symbol.Integer)
return i
if integer_value_fits(i):
return self._universe.new_integer(i)
else:
return self._universe.new_biginteger(i)
def _literal_double(self, negate_value):
f = float(self._text)
if negate_value:
f = 0.0 - f
self._expect(Symbol.Double)
return self._universe.new_double(f)
def _literal_symbol(self, mgenc):
self._expect(Symbol.Pound)
......@@ -529,9 +541,10 @@ class Parser(object):
return s
def _nested_block(self, mgenc):
mgenc.add_argument_if_absent("$block self")
self._expect(Symbol.NewBlock)
mgenc.add_argument_if_absent("$blockSelf")
if self._sym == Symbol.Colon:
self._block_pattern(mgenc)
......
......@@ -2,36 +2,38 @@
class Symbol(object):
NONE = -1
Integer = 0
Not = 1
And = 2
Or = 3
Star = 4
Div = 5
Mod = 6
Plus = 7
Minus = 8
Equal = 9
More = 10
Less = 11
Comma = 12
At = 13
Per = 14
NewBlock = 15
EndBlock = 16
Colon = 17
Period = 18
Exit = 19
Assign = 20
NewTerm = 21
EndTerm = 22
Pound = 23
Primitive = 24
Separator = 25
STString = 26
Identifier = 27
Keyword = 28
KeywordSequence = 29
OperatorSequence = 30
Double = 1
Not = 2
And = 3
Or = 4
Star = 5
Div = 6
Mod = 7
Plus = 8
Minus = 9
Equal = 10
More = 11
Less = 12
Comma = 13
At = 14
Per = 15
NewBlock = 16
EndBlock = 17
Colon = 18
Period = 19
Exit = 20
Assign = 21
NewTerm = 22
EndTerm = 23
Pound = 24
Primitive = 25
Separator = 26
STString = 27
Identifier = 28
Keyword = 29
KeywordSequence = 30
OperatorSequence = 31
def _sorted_symbols(cls):
"NOT_RPYTHON"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment