コード例 #1
0
    def __idrval(self):
        """<idrvalue> ::= ID ( DOT ID )* | ID LPAREN <exprlist> RPAREN """

        idrval = ast.IDRvalue()
        idrval.path.append(self.current_token)
        call_rval = ast.CallRValue()
        call_rval.fun = self.current_token

        self.__eat(token.ID, "expected an ID")

        is_id_not_call = None
        if self.__tokenIs(token.LPAREN):
            is_id_not_call = False
            self.__advance()
            self.__exprlist(call_rval.args)
            self.__eat(token.RPAREN, "expected ')'")

        else:
            is_id_not_call = True

            while self.__tokenIs(token.DOT):
                self.__advance()
                idrval.path.append(self.current_token)

                self.__eat(token.ID, "expected an ID")

        if (is_id_not_call):
            return idrval
        else:
            return call_rval
コード例 #2
0
    def __idrval(self, exprNode):
        temp = self.current_token
        self.__eat(token.ID, 'expecting id')
        if self.current_token.tokentype == token.LPAREN:
            exprNode.term = ast.CallRValue()
            exprNode.term.fun = temp
            self.__eat(token.LPAREN, 'expecting (')
            self.__exprlist(exprNode.term)
            self.__eat(token.RPAREN, 'expecting )')

        else:
            exprNode.term = ast.IDRvalue()
            exprNode.term.path.append(temp)
            while self.current_token.tokentype == token.DOT:
                self.__advance()
                exprNode.term.path.append(self.current_token)
                self.__eat(token.ID, 'expecting id')
コード例 #3
0
 def __idrval(self):
     """<idrval> ::= ID (DOT ID)* | ID LPAREN <exprlist> RPAREN"""
     idr_value_node = ast.IDRvalue()
     idr_value_node.path.append(self.current_token)
     self.__eat(token.ID, "expecting an identifier")
     if self.current_token.tokentype == token.LPAREN:
         call_rvalue_node = ast.CallRValue()
         call_rvalue_node.fun = idr_value_node.path[0]
         self.__advance()
         call_rvalue_node.args = self.__exprlist()
         self.__eat(token.RPAREN, 'expecting a ")"')
         return call_rvalue_node
     else:
         while self.current_token.tokentype == token.DOT:
             self.__advance()
             idr_value_node.path.append(self.current_token)
             self.__eat(token.ID, "expecting an identifier")
     return idr_value_node
コード例 #4
0
    def __idrval(self):
        id_rval_node = ast.IDRvalue()
        call_rval_node = ast.CallRValue()

        id_rval_node.path.append(self.current_token)
        call_rval_node.fun = self.current_token

        self.__eat(token.ID, 'expecting ID')
        if self.current_token.tokentype == token.LPAREN:
            self.__advance()
            self.__exprlist(call_rval_node)
            self.__eat(token.RPAREN, 'expecting rparren')
            return call_rval_node
        else:
            while self.current_token.tokentype == token.DOT:
                self.__advance()
                id_rval_node.path.append(self.current_token)
                self.__eat(token.ID, 'expecting ID')
            return id_rval_node
コード例 #5
0
ファイル: mypl_parser.py プロジェクト: michael-newell/CPSC326
 def __idrval(self):
     """<idrval> ::= ID ( DOT ID )* | ID LPAREN <exprlist> RPAREN"""
     first = self.current_token
     self.__eat(token.ID, 'expecting "ID"')
     if (self.current_token.tokentype == token.LPAREN):
         call_r_value_node = ast.CallRValue()
         call_r_value_node.fun = first
         self.__advance()
         call_r_value_node.args = self.__exprlist()
         self.__eat(token.RPAREN, 'expecting ")"')
         return call_r_value_node
     else:
         id_r_value_node = ast.IDRValue()
         id_r_value_node.path.append(first)
         while (self.current_token.tokentype == token.DOT):
             self.__advance()
             id_r_value_node.path.append(self.current_token)
             self.__eat(token.ID, 'expecting "ID"')
         return id_r_value_node
コード例 #6
0
ファイル: mypl_parser.py プロジェクト: ericav99/CPSC326
 def __idrval(self):
     # print("idrval: " + str(self.current_token))
     rvalue_id = self.current_token # save this for later in the method
     self.__eat(token.ID, 'expected ID')
     if self.current_token.tokentype == token.LPAREN: # parentheses -> function -> CallRValue node
         call_rvalue = ast.CallRValue()
         call_rvalue.fun = rvalue_id
         self.__advance() # eat LPAREN (we already know from 1 line up)
         call_rvalue.args = self.__exprlist()
         self.__eat(token.RPAREN, 'expected ")"')
         return call_rvalue # return CallRValue
     else: # no parentheses (and maybe dots) -> ID -> IDRValue
         id_rvalue = ast.IDRValue()
         id_rvalue.path.append(rvalue_id) # add first ID to list
         while self.current_token.tokentype == token.DOT:
             self.__advance() # eat DOT (we already know from 1 line up)
             id_rvalue.path.append(self.current_token) # add following IDs to list
             self.__eat(token.ID, 'expected ID')
         return id_rvalue # return IDRValue
コード例 #7
0
    def idrval(self):
        id_node = ast.IDRvalue()
        call_rvalue_node = ast.CallRValue()
        id_node.path.append(self.current_token)
        self.__eat(token.ID, "expecting an ID")
        if self.current_token.tokentype == token.DOT:

            while self.current_token.tokentype == token.DOT:
                self.__advance()
                id_node.path.append(self.current_token)
                self.__eat(token.ID, "expecting an ID")
            return id_node
        elif self.current_token.tokentype == token.LPAREN:
            call_rvalue_node.fun = id_node.path[0]
            self.__advance()
            if self.current_token.tokentype != token.RPAREN:
                self.__expr_list(call_rvalue_node)
            self.__eat(token.RPAREN, "expecting ')'")
            return call_rvalue_node
        return id_node
コード例 #8
0
 def __idrval(self):
     """<idrval> ::= ID ( DOT ID )* | ID LPAREN <exprlist> RPAREN"""
     rStmt = ast.SimpleRValue()
     rStmt.val = self.current_token
     self.__eat(token.ID, "expecting ID")
     if self.current_token.tokentype == token.LPAREN:
         temp = rStmt.val
         rStmt = ast.CallRValue()
         rStmt.fun = temp
         self.__advance()
         self.__exprlist(rStmt)
         self.__eat(token.RPAREN, "expecting a ')'")
         return rStmt
     else:
         if self.current_token.tokentype == token.DOT:
             temp = rStmt.val
             rStmt = ast.IDRvalue()
             rStmt.path.append(temp)
             while self.current_token.tokentype == token.DOT:
                 self.__advance()
                 temp = self.current_token
                 rStmt.path.append(temp)
                 self.__eat(token.ID, "expecting an ID")
     return rStmt