コード例 #1
0
 def visit_generic_declaration(self, that):
     that.symbol = ast.Symbol(that.get_name(), that)
     bindings = {}
     bindings[that.get_name()] = that.symbol
     outer_scope = self.scope
     self.scope = MappedScope(bindings, outer_scope)
     try:
         that.body.accept(self)
     finally:
         self.scope = outer_scope
コード例 #2
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
    def function(self):
        symbol = None
        private = False
        arguments = None
        if self.nafter.gettokentype() == 'KEYWORD':
            if self.nafter.getstr() == ":private":
                private = True
                x = next(self.tokens)
                if x and x.gettokentype() == 'SYMBOL':
                    symbol = x
                else:
                    raise IOError
        elif self.nafter.gettokentype() in self._strict_symtokens:
            symbol = self.nafter
        else:
            _malformed(self.nafter)

        x = next(self.tokens)
        if x and x.gettokentype() == 'LBRACKET':
            hit, stuff = self.tokens.get_until((RBRACKET), True)
            if not hit:
                raise IOError
            next(self.tokens)
            args = [ast.Symbol(x.getstr(), x, self.input) for x in stuff]
            if not args:
                arguments = ast.EmptyCollection(CollTypes.LIST, args, x,
                                                self.input)
            else:
                arguments = ast.Collection(CollTypes.LIST, args, x, self.input)
        else:
            _malformed(x)

        hit, stuff = self.tokens.get_until(self._ttype_tuple, True)
        fhdr = self._vfhdrs.get(symbol.getstr(), None)
        if fhdr:
            print("Redefinition of func {}".format(symbol.getstr()))
            _malformed(self.nafter)

        self._vfhdrs[symbol.getstr()] = ast.FuncHeader(
            ast.Symbol(symbol.getstr(), symbol, self.input), arguments, symbol,
            self.input, private)
コード例 #3
0
def get_random_symbols(l, h):
    symbols = list()

    # calculate num symbols.
    num = get_rand_int(l, h)

    for x in range(num):
        type = get_random_type()
        name = get_random_var_name()
        symbols.append(ast.Symbol(name, type, list()))

    return symbols
コード例 #4
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
 def include(self):
     symlist = []
     if self.nafter.gettokentype() == "LBRACKET":
         hit, stuff = self.tokens.get_until(self._ttype_tuple, True)
         self._rinclude.extend(stuff)
         symlist = stuff[0:-1]
     elif self.nafter.gettokentype() == "SYMBOL":
         symlist.append(self.nafter)
     else:
         _malformed(self.nafter)
     [
         self._include.append(ast.Symbol(x.getstr(), x, self.input))
         for x in symlist if x.gettokentype() == 'SYMBOL'
     ]
コード例 #5
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
    def parse_let(self, token, frame):
        """Parse Let expression"""
        if len(frame) < 2:
            _malformed(token)
        # Resolve first as return val versus args
        letres = None
        letargs = None
        letexpr = None

        if isinstance(frame[0], ast.Symbol):
            letres = frame.pop(0)
        else:
            sp = token.getsourcepos()
            lsym = "let_" + str(sp.lineno) + "_" + str(sp.colno)
            letres = ast.Symbol(lsym,
                                Token("LET_RES", lsym, token.getsourcepos()),
                                self.input)

        if isinstance(frame[0], ast.CollectionAst):
            letargs = frame.pop(0)
        else:
            _panic(
                "{}:{} Let expects local argument pair(s) signature [...] {}",
                token)

        if letargs.ctype != CollTypes.LIST:
            _panic(
                "{}:{} Invalid let argument pair(s) type. Should be [...] {}",
                token)

        if len(frame) < 1:
            _panic("{}:{} Missing Let expression {}", token)

        letexpr = [frame.pop(0)]
        letargs = ast.LetPairs(letargs, token, self.input)
        _check_no_declarations(token, letexpr, self._decl_set)
        frame.insert(0, ast.Let(letres, letargs, letexpr, token, self.input))
        return frame
コード例 #6
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
    def variable(self):
        symbol = None
        private = False
        hit, stuff = self.tokens.get_until(self._ttype_tuple, True)
        if self.nafter.gettokentype() == 'KEYWORD':
            if self.nafter.getstr() == ":private":
                private = True
                if stuff and stuff[0].gettokentype() == 'SYMBOL':
                    symbol = stuff[0]
            else:
                _malformed(self.nafter)
        elif self.nafter.gettokentype() in self._strict_symtokens:
            symbol = self.nafter
        else:
            _malformed(self.nafter)

        vhdr = self._vfhdrs.get(symbol.getstr(), None)
        if vhdr:
            print("Redefinition of var {}".format(symbol.getstr()))
            _malformed(self.nafter)

        self._vfhdrs[symbol.getstr()] = ast.VarHeader(
            ast.Symbol(symbol.getstr(), symbol, self.input), symbol,
            self.input, private)
コード例 #7
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
 def parse_symbol(self, token, frame):
     frame.insert(0, ast.Symbol(token.getstr(), token.token, self.input))
     return frame
コード例 #8
0
ファイル: fparser.py プロジェクト: FrankC01/foidl
 def parse_common_references(self, token, frame):
     frame.insert(0, ast.Symbol(token.getstr(), token.token, self.input))
     return frame
コード例 #9
0
ファイル: hparser.py プロジェクト: FrankC01/foidl
 def get_symbol(self, tstrm):
     tk = tstrm.next()
     if tk.gettokentype() in self.symboltypes:
         return True, tk, ast.Symbol(tk.getstr(), tk, self.input)
     else:
         return False, tk, None