Exemplo n.º 1
0
def parse_literal(tok):
    """Given a token, parse its string value and return the denotated
    Gobstones value.
    """
    if tok.type == 'symbol':
        val = tok.value
    else:
        val = gbs_builtins.parse_constant(tok.value)
        #assert val is not None
        if val is None:
            val = tok.value
    return val
Exemplo n.º 2
0
 def compile_and(self, tree, code):
     "Compile a short-circuiting conjunction."
     lcontinue = GbsLabel()
     lend = GbsLabel()
     type_annotation = self.get_type_annotation(tree)
     self.compile_expression(tree.children[2], code)
     code.push(('jumpIfFalse', lcontinue), near=tree)
     self.compile_expression(tree.children[3], code)
     code.push(('jump', lend), near=tree)
     code.push(('label', lcontinue), near=tree)
     code.push(('pushConst', gbs_builtins.parse_constant('False')),
               near=tree)
     code.push(('label', lend), near=tree)
 def _parse_constant(self, name):
   val = gbs_builtins.parse_constant(name)
   if val is None:
     self.fail('Unknown constant %s' % (name,))
   return val