示例#1
0
 def factor(self):
     self.dbg_msg( "factor" )
     tok=self.peek()
     if tok.kind ==  EzhilToken.LPAREN:
         lparen_tok = self.dequeue()
         val=self.expr()
         if self.dequeue().kind!= EzhilToken.RPAREN:
             raise SyntaxError("Missing Parens "+str(self.last_token()))
     elif tok.kind ==  EzhilToken.NUMBER:
         tok_num = self.dequeue()
         [l, c] = tok_num.get_line_col()
         val = Number( tok.val , l, c, self.debug )
     elif tok.kind == EzhilToken.LOGICAL_NOT:
         tok_not = self.dequeue()
         [l, c] = tok_not.get_line_col()
         val = UnaryExpr( self.expr(), tok_not , l, c, self.debug )
         self.dbg_msg("completed parsing unary expression"+str(val))
     elif tok.kind ==  EzhilToken.ID:
         tok_id = self.dequeue()
         [l, c] = tok_id.get_line_col()
         val = Identifier( tok.val , l, c, self.debug )
         ptok = self.peek()
         self.dbg_msg("factor: "+str(ptok) + " / "+str(tok) )
         if ( ptok.kind ==  EzhilToken.LPAREN ):
             ## function call
             [l, c] = ptok.get_line_col()
             vallist = self.valuelist()
             val=ExprCall( val, vallist, l, c, self.debug )
         elif ( ptok.kind ==  EzhilToken.LSQRBRACE ):
             ## indexing a array type variable or ID
             val=None
             raise ParseException("arrays not implemented"+str(ptok));
     elif tok.kind ==  EzhilToken.STRING :
         str_tok = self.dequeue()
         [l,c] = str_tok.get_line_col()
         val = String( tok.val , l, c, self.debug )
     elif tok.kind in EzhilToken.ADDSUB:
         unop = self.dequeue();
         [l, c] = unop.get_line_col()
         val=Expr(Number(0),unop,self.term(),l,c,self.debug);
     elif tok.kind == EzhilToken.LSQRBRACE:
         # creating a list/array expression
         list_start = self.dequeue();
         val = Array()
         while( True ):
             exprval = self.expr()
             val.append( exprval  )
             if self.debug : print(self.peek().__class__,self.peek())
             if ( self.peek().kind == EzhilToken.RSQRBRACE ):
                 break
             else:
                 assert( self.peek().kind == EzhilToken.COMMA)
                 self.dequeue()
         assert( self.peek().kind == EzhilToken.RSQRBRACE )
         list_end = self.dequeue()
     else:
         raise ParseException("Expected Number, found something "+str(tok))
     
     self.dbg_msg( "factor-returning: "+str(val) )
     return val
        def num(p):
            value = 0
            if (p[0].gettokentype() == 'SPECIAL'):
                value = p[1].value / 10000
            else:
                value = p[0].value + p[2] / 10000

            return Number(self.builder, self.module, value)
 def printitem(p):
     '''
     p[0] = numero ou variavel
     '''
     if (p[0].gettokentype() == 'num'):
         return Number(self.builder, self.module, int(p[0].value))
     else:
         return PrintItem(self.builder, self.module, p[0])
示例#4
0
 def parseSwitchStmt(self, exp):
     ## @ <ID/EXPR> SWITCH @( expr ) CASE {stmtlist} @( expr ) CASE {stmtlist} OTHERWISE {stmtlist} END
     ## implement as an if-elseif-else statement
     self.dbg_msg("parsing SWITCH statement")
     sw_tok = self.dequeue()
     [l, c] = sw_tok.get_line_col()
     self.inside_if = True
     lhs = exp[0]
     # enter this if-statement always
     ifstmt = IfStmt(Number(1), None, None, l, c, self.debug)
     self.if_stack.append(ifstmt)
     self.dbg_msg("parsing SWITCH-body")  #self.dbg_msg
     ptok = self.peek()
     equality_token = EzhilLexeme("=", EzhilToken.EQUALITY)
     while (ptok.kind == EzhilToken.ATRATEOF
            or ptok.kind == EzhilToken.OTHERWISE):
         self.inside_if = True
         [l, c] = ptok.get_line_col()
         if (ptok.kind == EzhilToken.ATRATEOF):
             # parse elseif branch
             self.dbg_msg("parsing CASE")
             self.match(EzhilToken.ATRATEOF)
             exp = self.valuelist()
             self.dbg_msg("parsing CASE EXPR")
             self.match(EzhilToken.CASE)
             next_stmt = self.stmtlist()
             expr = Expr(lhs, equality_token, exp[0], l, c, self.debug)
             self.dbg_msg("building an Expr " + str(expr))
             if not ifstmt.body:
                 ifstmt.expr = expr
                 ifstmt.body = next_stmt
             else:
                 case_stmt = IfStmt(expr, next_stmt, None, l, c, self.debug)
                 ifstmt.append_stmt(case_stmt)
         elif (ptok.kind == EzhilToken.OTHERWISE):
             #parse else branch
             self.dbg_msg("parsing OTHERWISE: ")
             self.match(EzhilToken.OTHERWISE)
             self.dbg_msg("parsing OTHERWISE-Body")
             self.inside_if = False
             body = self.stmtlist()
             else_stmt = ElseStmt(body, l, c, self.debug)
             if not ifstmt.body:
                 ifstmt.body = else_stmt
             else:
                 ifstmt.append_stmt(else_stmt)
             break
         else:
             self.inside_if = False
             raise ParseError(
                 "SWITCH-CASE-OTHERWISE statement syntax is messed up")
         ptok = self.peek()
         self.dbg_msg("parsing SWITCH-CASE next bits " + str(ptok))
     self.match(EzhilToken.END)
     self.inside_if = False
     self.dbg_msg("parsing -SWITCH-CASE- complete")
     return ifstmt
示例#5
0
 def factor(self):
     if self.current_token.type == NUM:
         factor = Number(self.current_token.value)
         self.consume(NUM)
     elif self.current_token.type == LPAREN:
         self.consume(LPAREN)
         factor = self.expr()
         self.consume(RPAREN)
     else:
         self.error()
     return factor
示例#6
0
def parseExpression(parser):
    expression = None
    if parser.matchTokensort(STRING):  #data string
        expression = Text(parser.currentToken[1], lineo=parser.currentToken[2])
        parser.next()
    elif parser.matchTokensort(NUMBER):  #number stuff
        expression = Number(parser.currentToken[1],
                            lineo=parser.currentToken[2])
        parser.next()
    elif parser.matchLexeme("["):
        expression = parseList(parser)
    elif parser.matchLexeme("{"):
        expression = parseRecord(parser)
    elif parser.matchTokensort(NAME):
        #Variable
        expression = Name(parser.currentToken[1])
        #Check for Variable DOT Field expression
        fields = []
        while parser.peek(lexeme=".") and parser.peek(x=2, tokensort=NAME):
            parser.next(lexeme=".")  #skip.
            parser.next(expected="NAME", tokensort=NAME)
            fields.append(parser.currentToken[1])
        if fields:
            expression = Field(expression,
                               fields,
                               lineo=parser.currentToken[2])
        parser.next()
    #Check for expression PLUS expression
    if parser.matchLexeme("+") and expression:
        left = expression
        parser.next()  # skip +
        right = parseExpression(parser)
        expression = Cat(left, right, lineo=parser.currentToken[2])

    #indentedLog(expression)

    if not expression:
        raise SyntaxError(
            parser.currentToken,
            expected=
            "Expression: symbol, string, number, list, record, name.field")

    return expression
示例#7
0
    def factor(self):
        self.dbg_msg("factor")
        tok = self.peek()
        if tok.kind == Token.LPAREN:
            lparen_tok = self.dequeue()
            val = self.expr()
            if self.dequeue().kind != Token.RPAREN:
                raise SyntaxError("Missing Parens")
        elif tok.kind == Token.NUMBER:
            tok_num = self.dequeue()
            [l, c] = tok_num.get_line_col()
            val = Number(tok.val, l, c, self.debug)
        elif tok.kind == Token.ID:
            tok_id = self.dequeue()
            [l, c] = tok_id.get_line_col()
            val = Identifier(tok.val, l, c, self.debug)
            ptok = self.peek()
            self.dbg_msg("factor: " + str(ptok) + " / " + str(tok))
            if (ptok.kind == Token.LPAREN):
                ## function call
                [l, c] = ptok.get_line_col()
                vallist = self.valuelist()
                val = ExprCall(val, vallist, l, c, self.debug)
            elif (ptok.kind == Token.LSQRBRACE):
                ## array type
                val = None
                raise ParseException("arrays not implemented" + str(ptok))
        elif tok.kind == Token.STRING:
            str_tok = self.dequeue()
            [l, c] = str_tok.get_line_col()
            val = String(tok.val, l, c, self.debug)
        else:
            raise ParseException("Expected Number, found something " +
                                 str(tok))

        self.dbg_msg("factor-returning: " + str(val))
        return val
示例#8
0
 def PRINTF(*args):
     str_op = Interpreter.SPRINTF_worker(*args)
     print(str_op)
     return Number(len(str_op))
示例#9
0
 def INPUT(args):
     op = (raw_input(args))
     if (isinstance(op, int) or isinstance(op, float)):
         return Number(0.0 + op)
     return String(op)
示例#10
0
 def factor(self):
     self.dbg_msg( "factor" )
     tok=self.peek()
     if tok.kind ==  EzhilToken.LPAREN:
         lparen_tok = self.dequeue()
         val=self.expr()
         if self.dequeue().kind!= EzhilToken.RPAREN:
             raise SyntaxError("Missing Parens "+unicode(self.last_token()))
     elif tok.kind ==  EzhilToken.NUMBER:
         tok_num = self.dequeue()
         [l, c] = tok_num.get_line_col()
         val = Number( tok.val , l, c, self.debug )
     elif tok.kind == EzhilToken.LOGICAL_NOT:
         tok_not = self.dequeue()
         [l, c] = tok_not.get_line_col()
         val = UnaryExpr( self.expr(), tok_not , l, c, self.debug )
         self.dbg_msg("completed parsing unary expression"+unicode(val))
     elif tok.kind ==  EzhilToken.ID:
         tok_id = self.dequeue()
         [l, c] = tok_id.get_line_col()
         val = Identifier( tok.val , l, c, self.debug )
         ptok = self.peek()
         self.dbg_msg(u"factor: "+unicode(ptok) + u" / "+ unicode(tok) )
         if ( ptok.kind ==  EzhilToken.LPAREN ):
             ## function call
             [l, c] = ptok.get_line_col()
             vallist = self.valuelist()
             val=ExprCall( val, vallist, l, c, self.debug )
         elif ( ptok.kind ==  EzhilToken.LSQRBRACE ):
             ## indexing a array type variable or ID                
             [l,c] = ptok.get_line_col()
             ## replace with a call to __getitem__
             exp = self.factor();
             if ( hasattr(exp,'__getitem__') ):
                 VL2 = ValueList([val,exp[0]],l,c,self.debug)
             else:
                 # when exp is a expression
                 VL2 = ValueList([val,exp],l,c,self.debug)
             val = ExprCall( Identifier("__getitem__",l,c), VL2,l,c,self.debug)
             for itr in range(1,len(exp)):
                 VL2 = ValueList([val,exp[itr]],l,c,self.debug)
                 val = ExprCall( Identifier("__getitem__",l,c), VL2,l,c,self.debug)
             #raise ParseException("array indexing implemented"+unicode(ptok));
         elif ( ptok.kind ==  EzhilToken.LCURLBRACE ):
             val=None
             raise ParseException("dictionary indexing implemented"+unicode(ptok));
     elif tok.kind ==  EzhilToken.STRING :
         str_tok = self.dequeue()
         [l,c] = str_tok.get_line_col()
         val = String( tok.val , l, c, self.debug )
     elif tok.kind in EzhilToken.ADDSUB:
         unop = self.dequeue();
         [l, c] = unop.get_line_col()
         val=Expr(Number(0),unop,self.term(),l,c,self.debug);
     elif tok.kind == EzhilToken.LCURLBRACE:
         # creating a list/dictionary expression
         dict_start = self.dequeue();
         val = Dict()
         while( True ):
             if ( self.peek().kind == EzhilToken.RCURLBRACE ):
                 break;
             exprkey = self.expr()
             tok_colon = self.match(EzhilToken.COLON)
             exprval = self.expr()
             val.update( {exprkey : exprval}  )
             if self.debug : print(self.peek().__class__,self.peek())
             if ( self.peek().kind == EzhilToken.RCURLBRACE ):
                 break
             else:
                 assert( self.peek().kind == EzhilToken.COMMA)
                 self.dequeue()
         assert( self.peek().kind == EzhilToken.RCURLBRACE )
         list_end = self.dequeue()
     elif tok.kind == EzhilToken.LSQRBRACE:
         # creating a list/array expression
         list_start = self.dequeue();
         val = Array()
         while( True ):
             if ( self.peek().kind == EzhilToken.RSQRBRACE ):
                 break;
             exprval = self.expr()
             val.append( exprval  )
             if self.debug : print(self.peek().__class__,self.peek())
             if ( self.peek().kind == EzhilToken.RSQRBRACE ):
                 break
             else:
                 assert( self.peek().kind == EzhilToken.COMMA)
                 self.dequeue()
         assert( self.peek().kind == EzhilToken.RSQRBRACE )
         list_end = self.dequeue()
     else:
         raise ParseException("Expected Number, found something "+unicode(tok))
     self.dbg_msg( u"factor-returning: "+unicode(val) )
     return val
示例#11
0
    def factor(self):
        self.dbg_msg("factor")
        tok = self.peek()
        if tok.kind == EzhilToken.LPAREN:
            lparen_tok = self.dequeue()
            val = self.expr()
            if self.dequeue().kind != EzhilToken.RPAREN:
                raise SyntaxError("Missing Parens " + str(self.last_token()))
        elif tok.kind == EzhilToken.NUMBER:
            tok_num = self.dequeue()
            [l, c] = tok_num.get_line_col()
            val = Number(tok.val, l, c, self.debug)
        elif tok.kind == EzhilToken.LOGICAL_NOT:
            tok_not = self.dequeue()
            [l, c] = tok_not.get_line_col()
            val = UnaryExpr(self.expr(), tok_not, l, c, self.debug)
            self.dbg_msg("completed parsing unary expression" + str(val))
        elif tok.kind == EzhilToken.ID:
            tok_id = self.dequeue()
            [l, c] = tok_id.get_line_col()
            val = Identifier(tok.val, l, c, self.debug)
            ptok = self.peek()
            self.dbg_msg("factor: " + str(ptok) + " / " + str(tok))
            if (ptok.kind == EzhilToken.LPAREN):
                ## function call
                [l, c] = ptok.get_line_col()
                vallist = self.valuelist()
                val = ExprCall(val, vallist, l, c, self.debug)
            elif (ptok.kind == EzhilToken.LSQRBRACE):
                ## indexing a array type variable or ID
                [l, c] = ptok.get_line_col()
                ## replace with a call to __getitem__
                exp = self.factor()
                if (hasattr(exp, '__getitem__')):
                    VL2 = ValueList([val, exp[0]], l, c, self.debug)
                else:
                    # when exp is a expression
                    VL2 = ValueList([val, exp], l, c, self.debug)
                val = ExprCall(Identifier("__getitem__", l, c), VL2, l, c,
                               self.debug)
                for itr in range(1, len(exp)):
                    VL2 = ValueList([val, exp[itr]], l, c, self.debug)
                    val = ExprCall(Identifier("__getitem__", l, c), VL2, l, c,
                                   self.debug)
                #raise ParseException("array indexing implemented"+str(ptok));
            elif (ptok.kind == EzhilToken.LCURLBRACE):
                val = None
                raise ParseException("dictionary indexing implemented" +
                                     str(ptok))
        elif tok.kind == EzhilToken.STRING:
            str_tok = self.dequeue()
            [l, c] = str_tok.get_line_col()
            val = String(tok.val, l, c, self.debug)
        elif tok.kind in EzhilToken.ADDSUB:
            unop = self.dequeue()
            [l, c] = unop.get_line_col()
            val = Expr(Number(0), unop, self.term(), l, c, self.debug)
        elif tok.kind == EzhilToken.LCURLBRACE:
            # creating a list/dictionary expression
            dict_start = self.dequeue()
            val = Dict()
            while (True):
                if (self.peek().kind == EzhilToken.RCURLBRACE):
                    break
                exprkey = self.expr()
                tok_colon = self.match(EzhilToken.COLON)
                exprval = self.expr()
                val.update({exprkey: exprval})
                if self.debug: print(self.peek().__class__, self.peek())
                if (self.peek().kind == EzhilToken.RCURLBRACE):
                    break
                else:
                    assert (self.peek().kind == EzhilToken.COMMA)
                    self.dequeue()
            assert (self.peek().kind == EzhilToken.RCURLBRACE)
            list_end = self.dequeue()
        elif tok.kind == EzhilToken.LSQRBRACE:
            # creating a list/array expression
            list_start = self.dequeue()
            val = Array()
            while (True):
                if (self.peek().kind == EzhilToken.RSQRBRACE):
                    break
                exprval = self.expr()
                val.append(exprval)
                if self.debug: print(self.peek().__class__, self.peek())
                if (self.peek().kind == EzhilToken.RSQRBRACE):
                    break
                else:
                    assert (self.peek().kind == EzhilToken.COMMA)
                    self.dequeue()
            assert (self.peek().kind == EzhilToken.RSQRBRACE)
            list_end = self.dequeue()
        else:
            raise ParseException("Expected Number, found something " +
                                 str(tok))

        self.dbg_msg("factor-returning: " + str(val))
        return val
示例#12
0
 def factor_number(p):
     return Number(self.builder, self.module, p[0].getstr())
示例#13
0
 def snum(p):
     value = p[1].value
     if (p[0].getstr() == '-'):
         value = value * (-1)
     return Number(self.builder, self.module, value)
示例#14
0
    def factor(self):
        self.dbg_msg("factor")
        tok = self.peek()
        if tok.kind == EzhilToken.LPAREN:
            lparen_tok = self.dequeue()
            val = self.expr()
            if self.dequeue().kind != EzhilToken.RPAREN:
                raise SyntaxError("Missing Parens " + str(self.last_token()))
        elif tok.kind == EzhilToken.NUMBER:
            tok_num = self.dequeue()
            [l, c] = tok_num.get_line_col()
            val = Number(tok.val, l, c, self.debug)
        elif tok.kind == EzhilToken.LOGICAL_NOT:
            tok_not = self.dequeue()
            [l, c] = tok_not.get_line_col()
            val = UnaryExpr(self.expr(), tok_not, l, c, self.debug)
            self.dbg_msg("completed parsing unary expression" + str(val))
        elif tok.kind == EzhilToken.ID:
            tok_id = self.dequeue()
            [l, c] = tok_id.get_line_col()
            val = Identifier(tok.val, l, c, self.debug)
            ptok = self.peek()
            self.dbg_msg("factor: " + str(ptok) + " / " + str(tok))
            if (ptok.kind == EzhilToken.LPAREN):
                ## function call
                [l, c] = ptok.get_line_col()
                vallist = self.valuelist()
                val = ExprCall(val, vallist, l, c, self.debug)
            elif (ptok.kind == EzhilToken.LSQRBRACE):
                ## indexing a array type variable or ID
                val = None
                raise ParseException("arrays not implemented" + str(ptok))
        elif tok.kind == EzhilToken.STRING:
            str_tok = self.dequeue()
            [l, c] = str_tok.get_line_col()
            val = String(tok.val, l, c, self.debug)
        elif tok.kind in EzhilToken.ADDSUB:
            unop = self.dequeue()
            [l, c] = unop.get_line_col()
            val = Expr(Number(0), unop, self.term(), l, c, self.debug)
        elif tok.kind == EzhilToken.LSQRBRACE:
            # creating a list/array expression
            list_start = self.dequeue()
            val = Array()
            while (True):
                exprval = self.expr()
                val.append(exprval)
                if self.debug: print(self.peek().__class__, self.peek())
                if (self.peek().kind == EzhilToken.RSQRBRACE):
                    break
                else:
                    assert (self.peek().kind == EzhilToken.COMMA)
                    self.dequeue()
            assert (self.peek().kind == EzhilToken.RSQRBRACE)
            list_end = self.dequeue()
        else:
            raise ParseException("Expected Number, found something " +
                                 str(tok))

        self.dbg_msg("factor-returning: " + str(val))
        return val
示例#15
0
 def stmt(self, pass_in_ATexpr=None):
     """ try an assign, print, return, if or eval statement """
     self.dbg_msg(" STMT ")
     ptok = self.peek()
     self.dbg_msg("stmt: peeking at " + str(ptok))
     if (ptok.kind == EzhilToken.RETURN):
         ## return <expression>
         self.dbg_msg('enter->return: <expression>')
         ret_tok = self.dequeue()
         [l, c] = ret_tok.get_line_col()
         rstmt = ReturnStmt(self.expr(), l, c, self.debug)
         self.dbg_msg("return statement parsed")
         return rstmt
     elif (ptok.kind == EzhilToken.PRINT):
         self.currently_parsing.append(ptok)
         ## print <expression>
         print_tok = self.dequeue()
         [l, c] = print_tok.get_line_col()
         exprlist_val = self.exprlist()
         self.currently_parsing.pop()
         return PrintStmt(exprlist_val, l, c, self.debug)
     elif (ptok.kind == EzhilToken.ATRATEOF or pass_in_ATexpr):
         ## @ <expression> {if | while | elseif}
         if not pass_in_ATexpr:
             at_tok = self.match(EzhilToken.ATRATEOF)
             self.currently_parsing.append(at_tok)
             exp = self.valuelist()
             self.currently_parsing.pop()
         else:
             exp = pass_in_ATexpr
         if (self.debug): print("return from valuelist ", str(exp))
         ptok = self.peek()
         if (ptok.kind == EzhilToken.IF):
             return self.parseIfStmt(exp)
         elif (ptok.kind == EzhilToken.WHILE):
             ## @ ( expr ) while { body } end
             self.loop_stack.append(True)
             self.dbg_msg("while-statement")
             while_tok = self.dequeue()
             self.currently_parsing.append(while_tok)
             [l, c] = while_tok.get_line_col()
             wexpr = exp[0]
             body = self.stmtlist()
             self.match(EzhilToken.END)
             whilestmt = WhileStmt(wexpr, body, l, c, self.debug)
             self.loop_stack.pop()
             self.currently_parsing.pop()
             return whilestmt
         elif (ptok.kind == EzhilToken.SWITCH):
             return self.parseSwitchStmt(exp)
         elif (ptok.kind == EzhilToken.FOREACH):
             foreach_tok = self.dequeue()
             self.currently_parsing.append(foreach_tok)
             [l, c] = foreach_tok.get_line_col()
             if (self.debug): print("parsing FOREACH stmt")
             self.loop_stack.append(True)
             self.dbg_msg("foreach-statement")
             # convert to a for statement - building Ezhil AST - transformations
             if not isinstance(exp[1], Identifier):
                 raise ParseError(" FOR-EACH statement " + str(foreach_tok))
             foreach_iter = exp[1]
             iter = Identifier("__" + foreach_iter.id, l=0, c=-1)
             eq_token = EzhilLexeme("=", EzhilToken.EQUALS)
             plus_token = EzhilLexeme("+", EzhilToken.PLUS)
             lt_token = EzhilLexeme("<", EzhilToken.LT)
             if (self.debug): print("build init assign stmt")
             init = AssignStmt(iter, eq_token, Number(0), l, c, self.debug)
             if (self.debug): print("build cond expr")
             VL1 = ValueList([exp[0]], l, c, self.debug)
             cond = Expr(
                 iter, lt_token,
                 ExprCall(Identifier("len", l, c), VL1, l, c, self.debug),
                 l, c, self.debug)
             if (self.debug): print("build plus1 stmt")
             plus1_iter = Expr(iter, plus_token, Number(1), l, c,
                               self.debug)
             if (self.debug): print("build equals stmt")
             update = AssignStmt(iter, eq_token, plus1_iter, l, c,
                                 self.debug)
             body = self.stmtlist()  #parse body
             # and insert artifical update variable in body
             VL2 = ValueList([exp[0], iter], l, c, self.debug)
             extract_foreach_iter_from_list = ExprCall(
                 Identifier("__getitem__", l, c), VL2, l, c, self.debug)
             foreach_iter_Assign = AssignStmt(
                 foreach_iter, eq_token, extract_foreach_iter_from_list, l,
                 c, self.debug)
             body.List.insert(0, foreach_iter_Assign)
             # complete FOREACH stmt
             self.match(EzhilToken.END)
             self.currently_parsing.pop()
             foreach_stmt = ForStmt(init, cond, update, body, l, c,
                                    self.debug)
             self.loop_stack.pop()
             if (self.debug):
                 print("completed parsing FOR-EACH loop", str(foreach_stmt))
             return foreach_stmt
         elif (ptok.kind == EzhilToken.FOR):
             ## Fixme : empty for loops not allowed.
             """ For ( exp1 , exp2 , exp3 ) stmtlist  end"""
             if (self.debug): print("parsing FOR stmt")
             self.loop_stack.append(True)
             self.dbg_msg("for-statement")
             for_tok = self.peek()
             self.currently_parsing.append(for_tok)
             if (self.debug): print("matching for STMT", str(self.peek()))
             self.match(EzhilToken.FOR)
             if (self.debug): print("matched for STMT", str(self.peek()))
             [l, c] = for_tok.get_line_col()
             init, cond, update = exp[0], exp[1], exp[2]
             if (self.debug):
                 print("extract 3 parts", str(init), str(cond), str(update))
             body = self.stmtlist()
             self.match(EzhilToken.END)
             self.currently_parsing.pop()
             if (self.debug): print("body of loop", str(body))
             forstmt = ForStmt(init, cond, update, body, l, c, self.debug)
             self.loop_stack.pop()
             if (self.debug):
                 print("completed parsing FOR loop", str(forstmt))
             return forstmt
     elif (ptok.kind == EzhilToken.DO):
         if (self.debug): print("parsing DO-WHILE statement")
         self.loop_stack.append(True)
         do_tok = self.dequeue()
         self.currently_parsing.append(do_tok)
         [l, c] = do_tok.get_line_col()
         body = self.stmtlist()
         if (self.debug): print("parsed body")
         self.match(EzhilToken.DOWHILE)
         self.match(EzhilToken.ATRATEOF)
         exp = self.valuelist()
         if (self.debug): print("parsed EXP", exp[0])
         doWhileStmt = DoWhileStmt(exp[0], body, l, c, self.debug)
         self.loop_stack.pop()
         self.currently_parsing.pop()
         return doWhileStmt
     elif (ptok.kind == EzhilToken.BREAK):
         ## break, must be in loop-environment
         self.dbg_msg("break-statement")
         break_tok = self.dequeue()
         [l, c] = break_tok.get_line_col()
         self.check_loop_stack()
         ##raises a parse error
         brkstmt = BreakStmt(l, c, self.debug)
         return brkstmt
     elif (ptok.kind == EzhilToken.CONTINUE):
         ## continue, must be in loop-environment
         self.dbg_msg("continue-statement")
         cont_tok = self.dequeue()
         [l, c] = cont_tok.get_line_col()
         self.check_loop_stack()
         ##raises a parse error
         cntstmt = ContinueStmt(l, c, self.debug)
         return cntstmt
     else:
         ## lval := rval
         ptok = self.peek()
         self.currently_parsing.append(ptok)
         [l, c] = ptok.get_line_col()
         lhs = self.expr()
         self.dbg_msg("parsing expr: " + str(lhs))
         ptok = self.peek()
         if (ptok.kind in EzhilToken.ASSIGNOP):
             assign_tok = self.dequeue()
             rhs = self.expr()
             [l, c] = assign_tok.get_line_col()
             self.currently_parsing.pop()
             return AssignStmt(lhs, assign_tok, rhs, l, c, self.debug)
         self.currently_parsing.pop()
         return EvalStmt(lhs, l, c, self.debug)
     raise ParseException("parsing Statement, unkown operators" + str(ptok))
示例#16
0
 def number(p):
     return Number(self.builder, self.module, p[0].value)
示例#17
0
def ezhil_tamil_length(arg):
    return Number(len(tamil.utf8.get_letters(arg)))
示例#18
0
def expression_number(p):
    # p is a list of the pieces matched by the right hand side of the
    # rule
    return Number(int(p[0].getstr()))
示例#19
0
 def p_atom(tokens):
     token = tokens[0]
     if (token.gettokentype() == 'NUMBER'):
         return Number(int(token.getstr()))
     elif (token.gettokentype() == 'NAME'):
         return Ident(token.getstr())
示例#20
0
 def handleNumber(p):
     return Number(p[0].value)
示例#21
0
 def number(p):
     return Number(p[0].value)
示例#22
0
 def int_function(p):
     result = 0
     for i in range(len(p)):
         result = result * 10 + p[i]
     return Number(self.builder, self.module, result)