示例#1
0
def p_bracket_list(p):
	'''bracket_list	: LBRACKET expression RBRACKET
					| bracket_list LBRACKET expression RBRACKET'''
	  
	if len(p) == 4:
		p[0] = AST.bracketListNode(p[2], nlines)
	else:
		p[0] = AST.bracketListNode(p[1].children + [p[3]], nlines)
示例#2
0
def p_exprArray(p):
	'''expression	: IDENTIFIER bracket_list
					| IDENTIFIER LBRACKET RBRACKET'''
	
	if len(p) == 3:
		p[0] = AST.array_exprNode([AST.TokenNode(p[1], nlines)] + [p[2]], nlines)
	else:
		p[0] = AST.array_exprNode([AST.TokenNode(p[1], nlines)])
示例#3
0
文件: syntax.py 项目: 8l/connectal
def generate_bsvcpp(filelist, project_dir, bsvdefines, interfaces):
    for inputfile in filelist:
        syntax_parse(open(inputfile).read(),inputfile, bsvdefines)
    ## code generation pass
    ilist = []
    for i in interfaces:
        ifc = globalv.globalvars.get(i)
        if not ifc:
            print 'Connectal: Unable to locate the interface:', i
            for keys in globalv.globalvars:
                print '    ', keys
            sys.exit(1)
        ifc = ifc.instantiate(dict(zip(ifc.params, ifc.params)))
        ilist.append(ifc)
        for ditem in ifc.decls:
            for pitem in ditem.params:
                thisType = pitem.type
                p = globalv.globalvars.get(thisType.name)
                if p and thisType.params and p.params:
                    myName = '%sL_%s_P' % (thisType.name, '_'.join([t.name for t in thisType.params if t]))
                    pitem.oldtype = pitem.type
                    pitem.type = AST.Type(myName, [])
                    if not globalv.globalvars.get(myName):
                        globalv.add_new(AST.TypeDef(p.tdtype.instantiate(dict(zip(p.params, thisType.params))), myName, []))
    jsondata = AST.serialize_json(ilist, globalimports, bsvdefines)
    if project_dir:
        cppgen.generate_cpp(project_dir, noisyFlag, jsondata)
        bsvgen.generate_bsv(project_dir, noisyFlag, False, jsondata)
示例#4
0
def p_argument_declaration(p):
    '''argument_declaration	: IDENTIFIER
							| NUMBER
							| IDENTIFIER LBRACKET RBRACKET'''
	
    if len(p) == 2:
        p[0] = AST.TokenNode(p[1], nlines)
    elif len(p) == 2 and isinstance (p[1], AST.NumberNode):
        p[0] = AST.NumberNode(p[1], nlines)
    else:
        p[0] = AST.array_declNode(AST.TokenNode(p[1], nlines), nlines)
示例#5
0
def generate_bsvcpp(filelist, project_dir, dutname, bsvdefines, interfaces, nf):
    global noisyFlag
    noisyFlag=nf
    for inputfile in filelist:
        syntax_parse(open(inputfile).read(),inputfile, bsvdefines)
    ## code generation pass
    ilist = []
    for i in interfaces:
        ifc = globalv.globalvars[i]
        ifc = ifc.instantiate(dict(zip(ifc.params, ifc.params)))
        ifc.ind = AST.Interface(i, [], [], None, ifc.package)
        ifc.ind.req = ifc
        ilist.append(ifc)
    jsondata = AST.serialize_json(ilist, globalimports, dutname)
    cppgen.generate_cpp(project_dir, noisyFlag, jsondata)
    bsvgen.generate_bsv(project_dir, noisyFlag, jsondata)
示例#6
0
def p_rect(p):
    '''expression : expression '[' expression ']' '''
    p[0] = AST.TabNode([p[1], p[3]])
示例#7
0
 def p_for_instruction(self, p):
     """for_instruction : FOR variable_expression '=' expression ':' expression  instruction """
     p[0] = AST.ForInstruction(p[2], p[4], p[6], p[7], p.lineno(1))
示例#8
0
                                                      self.children[2].children)
            OUT = self.children[1].execute()
            if OUT:
                VARS[self.children[0]][ORDERED][i] = OUT

    else:
        for c in VARS[self.children[0]].keys():
            if isinstance(VARS[self.children[0]][c], list):
                continue
            self.children[1].children[0] = ParamsNode([TokenNode(self.children[0], c)] + self.children[2].children)
            OUT = self.children[1].execute()
            if OUT:
                VARS[self.children[0]][c] = OUT


@addToClass(AST.SomehowNode)
def execute(self):
    if self.children[0].execute():
        return self.children[1].execute()
    else:
        return self.children[2].execute()


if __name__ == '__main__':
    from PARSER import PARSE
    import sys

    with open(sys.argv[1]) as PROG:
        AST = PARSE(PROG.read())
    AST.execute()
示例#9
0
 def p_matrix_initialization_zeros(self, p):
     """expression : ZEROS '(' expression ')'"""
     p[0] = AST.ZerosInitialization(p[3], p.lineno(1))
示例#10
0
 def p_matrix_initialization_eye(self, p):
     """expression : EYE '(' expression ')'"""
     p[0] = AST.EyeInitialization(p[3], p.lineno(1))
示例#11
0
def p_range_op(p):
    """rangeoperator : expr ':' expr """
    p[0] = AST.BinExpr(p[2], p[1], p[3])
示例#12
0
 def p_neg_unary_expression(self, p):
     """expression : '-' expression %prec NEGATION """
     p[0] = AST.NegUnaryExpression(p[2], p.lineno(1))
示例#13
0
def p_expr2(p):
    """expr : INTNUMBER """
    p[0] = AST.IntNum(p[1])
示例#14
0
def p_for_loop(p):
    """forloop : FOR ID '=' rangeoperator block"""
    p[0] = AST.ForLoop(p[2], p[4], p[5])
示例#15
0
def p_waitOneFrame(p):
    '''statement : WAITONEFRAME '''
    p[0] = AST.WaitNode(AST.TokenNode(p[1]))
示例#16
0
def p_member(p):
    '''member : expression '.' climember'''
    #try:
    p[0] = AST.MemberNode([p[1], p[3]])
示例#17
0
def p_cliprog(p):
    '''expression : '{' program '}' '''
    p[0] = AST.ProgramNode(p[2])
示例#18
0
def p_string(p):
    '''expression : STRING'''
    p[0] = AST.PathNode(AST.TokenNode(p[1]))
def p_programme_statement(p):
    ''' programme : statement '''
    p[0] = AST.ProgramNode(p[1])
def p_assign(p):
    ''' assignation : IDENTIFIER '=' expression '''
    p[0] = AST.AssignNode([AST.TokenNode(p[1]), p[3]])
def p_minus(p):
    ''' expression : ADD_OP expression %prec UMINUS'''
    p[0] = AST.OpNode(p[1], [p[2]])
示例#22
0
def p_expr3(p):
    """expr : FLOATNUMBER"""
    p[0] = AST.FloatNum(p[1])
示例#23
0
def p_uminus(p):
    'expression : ADD_OP expression %prec UMINUS'
    #p[0] = operations[p[1]](0,p[2])
    p[0] = AST.OpNode(p[1], [p[2]])
示例#24
0
def p_while_loop(p):
    """whileloop : WHILE '(' expr ')' block"""
    p[0] = AST.WhileLoop(p[3], p[5])
示例#25
0
def p_scene_type(p):
    '''scene : SCENE '(' expression ',' '[' id_list ']' ')' '''
    p[0] = AST.SceneNode([p[3], p[6]])
示例#26
0
def p_print_statement(p):
    """printstatement : PRINT printables"""
    p[0] = AST.PrintStatement(p[2])
示例#27
0
def p_cli_type(p):
    '''cli : CLI '(' expression ',' rect ')' '{' program '}' '''
    p[0] = AST.CliNode([p[3], p[5], p[8]])
示例#28
0
 def p_trans_unary_expression(self, p):
     """expression : expression "'" """
     p[0] = AST.TransUnaryExpression(p[1], p.lineno(2))
示例#29
0
def p_rect_type(p):
    '''rect : RECT '(' expression ',' expression ',' expression ',' expression ')' '''
    p[0] = AST.RectNode([p[3], p[5], p[7], p[9]])
示例#30
0
 def p_matrix_initialization_ones(self, p):
     """expression : ONES '(' expression ')'"""
     p[0] = AST.OnesInitialization(p[3], p.lineno(1))
示例#31
0
def p_expression_op(p):
    '''expression : expression ADD_OP expression
         | expression MULT_OP expression'''
    p[0] = AST.OpNode(p[2], [p[1], p[3]])
示例#32
0
 def p_while_instruction(self, p):
     """while_instruction : WHILE '(' condition ')' instruction"""
     p[0] = AST.WhileInstruction(p[3], p[5], p.lineno(3))
示例#33
0
def p_array_declaration(p):
	'''array_declaration	: NEW IDENTIFIER bracket_list'''
							
	p[0] = AST.array_declNode([AST.TokenNode(p[2], nlines)] + [p[3]], nlines)
示例#34
0
 def p_compound_instruction(self, p):
     """compound_instruction : '{' instructions '}' """
     p[0] = AST.CompoundInstruction(p[2], p.lineno(1))
示例#35
0
def p_variable(p):
    '''expression : ID'''
    p[0] = AST.TokenNode(p[1])
示例#36
0
def p_number(p):
    '''expression : NUMBER'''
    p[0] = AST.TokenNode(p[1])
示例#37
0
def p_pritable2(p):
    """printable : STRING"""
    p[0] = AST.String(p[1])