new.fixed_value = fixed_value
return new
+ def parse():
+ """If the current token is an identifier that names a type, returns
+ the type and skips to the next token. Otherwise, returns
+ None.
+ """
+ if toktype == 'id':
+ for type_ in types.values():
+ if type_.name == token:
+ get_token()
+ return type_
+ return None
+
def init_type(type_):
global types
types[type_.name] = type_
else:
break
- return_type = parse_type()
+ return_type = Type.parse()
if return_type is None:
return_type = types['number']
if return_type.name not in ['number', 'string', 'boolean']:
aux = []
while toktype == 'id':
- type_ = parse_type()
+ type_ = Type.parse()
if type_ is None:
sys.stderr.write('parse error\n')
sys.exit(1)
if comment_ofs >= 0:
line = line[:comment_ofs]
-def parse_type():
- """If the current token is an identifier that names a type, returns
- the type and skips to the next token. Otherwise, returns
- undef.
- """
- if toktype == 'id':
- for type_ in types.values():
- if type_.name == token:
- get_token()
- return type_
- return None
-
def force(type_):
"""Makes sure that 'toktype' equals 'type', reads the next token, and
returns the previous 'token'.
def parse_arg():
"""Parses and returns a function argument."""
- type_ = parse_type()
+ type_ = Type.parse()
if type_ is None:
type_ = types['number']