Beispiel #1
0
 def p_opt_program(self, p):
     """opt_program :
                    | program"""
     if len(p) == 1:
         p[0] = [[], []]
     else:
         p[0] = [[
             ast.Block(program=p[1][0],
                       namespace='__scriptname__',
                       debug_info=self.debug_info(p, 1))
         ], p[1][1]]
Beispiel #2
0
 def parse_block(self) -> ast.Block:
     """
     Parses a block.
     """
     line = self.expect('{').line
     block = []
     while self.tokens.peek != '}':
         if self.tokens.peek == TokenType.TYPE:
             # declaration
             var_type, name, line = self.parse_declaration()
             if self.tokens.peek == '=':
                 self.tokens.next()
                 expr = self.parse_expression()
                 self.expect(';')
                 block.append(ast.Declaration(line, var_type, name, expr))
             else:
                 self.expect(';')
                 block.append(ast.Declaration(line, var_type, name))
         else:
             # statement
             block.append(self.parse_statement())
     self.tokens.next()
     return ast.Block(line, block)
Beispiel #3
0
 def p_opt_program(self, p):
     """opt_program : program
                    | empty"""
     p[0] = [] if p[1] is None else [ast.Block(program=p[1], namespace='__scriptname__', debug_info=self.debug_info(p, 1))]