コード例 #1
0
ファイル: arguments_rules.py プロジェクト: seapp/seapp
def p_create_pair(p):
    "create_list : STRING COMMA multi_type"
    
    if check_layer_name(p[1]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    p[0] = str(p[1]) + ":" + str(p[3])
コード例 #2
0
def p_create_pair(p):
    "create_list : STRING COMMA multi_type"
    
    if check_layer_name(p[1]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    p[0] = str(p[1]) + ":" + str(p[3])
コード例 #3
0
ファイル: primitives_rules.py プロジェクト: seapp/seapp
def p_statement_retrieve(p):
    "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN"
    
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))
    
    # Check if the variable is reserved  
 	if p[7] in reserved_name:
		print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) )
      
    # Check if the variable has been previously declared
    if p[7] not in symbol_table.keys():
        print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) )
      
	# Check if the name has been previously used to declare a packet
    if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR":
        print_error("Error: ID overloading is not allowed", str(p.lineno(1)) )
    
    # Check if the layer name is valid
    if check_layer_name(p[5]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Retrieve(args)
    actions.append(action)
コード例 #4
0
ファイル: primitives_rules.py プロジェクト: asfpp/asfpp
def p_statement_retrieve(p):
    "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN"
    
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))
    
    # Check if the variable is reserved  
 	if p[7] in reserved_name:
		print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) )
      
    # Check if the variable has been previously declared
    if p[7] not in symbol_table.keys():
        print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) )
      
	# Check if the name has been previously used to declare a packet
    if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR":
        print_error("Error: ID overloading is not allowed", str(p.lineno(1)) )
    
    # Check if the layer name is valid
    if check_layer_name(p[5]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    # Check coerency of layer_field structure "layer.field1.field2.field3 ..."
    layer_field = str(p[5])
    id_counter = 0
    while len(layer_field) != 0:
        # search identifier in the string head
        try:
            substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0)
            id_counter += 1
        except AttributeError:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1)))
        
        # remove substring found
        layer_field = layer_field.replace(substring_found, "", 1)
        
        if len(layer_field) == 0:
            break;
        
        # search '.' in the string head
        try:
            substring_found = re.search('^\.', layer_field).group(0)
        except AttributeError:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, '.' missing", str(p.lineno(1)))
        
        layer_field = layer_field.replace(substring_found, "", 1)
    
        if len(layer_field) == 0:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1)))    
    
    if id_counter < 2:
        print_error("Error: layer.field attribute in retrieve action has a bad structure, field missing", str(p.lineno(1)))    
    
    # Coerency test passed, build the object
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Retrieve(args)
    actions.append(action)
コード例 #5
0
def p_statement_retrieve(p):
    "logical_statement : RETRIEVE LPAREN identifier COMMA layer_field_pair COMMA identifier RPAREN"
    
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))
    
    # Check if the variable is reserved  
 	if p[7] in reserved_name:
		print_error("Error: '" + p[7] + "' is a reserved name", str(p.lineno(1)) )
      
    # Check if the variable has been previously declared
    if p[7] not in symbol_table.keys():
        print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) )
      
	# Check if the name has been previously used to declare a packet
    if p[7] in symbol_table.keys() and symbol_table[p[7]] != "VAR":
        print_error("Error: ID overloading is not allowed", str(p.lineno(1)) )
    
    # Check if the layer name is valid
    if check_layer_name(p[5]) == False and check_control_structure_name(p[5]) == False:
        print_error("Error: layer name unknown, you can use only: APP or TRA or NET or MAC or controlInfo", str(p.lineno(1)))
    
    # Check coerency of layer_field structure "layer.field1.field2.field3 ..."
    layer_field = str(p[5])
    id_counter = 0
    while len(layer_field) != 0:
        # search identifier in the string head
        try:
            substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0)
            id_counter += 1
        except AttributeError:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1)))
        
        # remove substring found
        layer_field = layer_field.replace(substring_found, "", 1)
        
        if len(layer_field) == 0:
            break;
        
        # search '.' in the string head
        try:
            substring_found = re.search('^\.', layer_field).group(0)
        except AttributeError:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, '.' missing", str(p.lineno(1)))
        
        layer_field = layer_field.replace(substring_found, "", 1)
    
        if len(layer_field) == 0:
            print_error("Error: layer.field attribute in retrieve action has a bad structure, id missing", str(p.lineno(1)))    
    
    if id_counter < 2:
        print_error("Error: layer.field attribute in retrieve action has a bad structure, field missing", str(p.lineno(1)))    
    
    # Coerency test passed, build the object
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Retrieve(args)
    actions.append(action)
コード例 #6
0
ファイル: primitives_rules.py プロジェクト: seapp/seapp
def p_statement_change(p):
    "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN"
    
    # Check the third argument
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))
    
    # p[7] is multi_type (NUMBER, STRING, ID) 
    if p[7] not in reserved_name and p[7] not in symbol_table.keys():
        
        re_pattern = r"^-?\d+(\.\d+)?"
        pattern = re.compile(re_pattern)
        
        # Add an entry in the variable table if STRING is not present in it
        if p[7][0] == "\"" and p[7][-1] == "\"":
            symbol_table[p[7]] = "VAR"
            variables[p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>"
        
        # Add an entry in the variable table if NUMBER is not present in it
        elif re.match(pattern, p[7]):
            symbol_table[p[7]] = "VAR"
            variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>"
		
        # Return error if the ID is not declared
        else:
            print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) )

    # Check if the variable is initialized
    if p[7] not in reserved_name:
        
        value = variables[p[7]][7]
     
        # Variable not initialized if its first char is '<'
        if value == "<":
            print_error("Error: variable '" + p[7] + "' must be initialized", str(p.lineno(1)) )
    
    # Check layer name
    if check_layer_name(p[5]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Change(args)
    actions.append(action)
コード例 #7
0
ファイル: primitives_rules.py プロジェクト: asfpp/asfpp
def p_statement_change(p):
    "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN"
    
    # Check the third argument
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))
    
    # p[7] is multi_type (NUMBER, STRING, ID) 
    if p[7] not in reserved_name and p[7] not in symbol_table.keys():
        
        re_pattern = r"^-?\d+(\.\d+)?"
        pattern = re.compile(re_pattern)
        
        # Add an entry in the variable table if STRING is not present in it
        if p[7][0] == "\"" and p[7][-1] == "\"":
            symbol_table[p[7]] = "VAR"
            variables[p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>"
        
        # Add an entry in the variable table if NUMBER is not present in it
        elif re.match(pattern, p[7]):
            symbol_table[p[7]] = "VAR"
            variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>"
		
        # Return error if the ID is not declared
        else:
            print_error("Error: '" + p[7] + "' undefined variable identifier", str(p.lineno(1)) )

    # Check if the variable is initialized
    if p[7] not in reserved_name:
        
        value = variables[p[7]][7]
     
        # Variable not initialized if its first char is '<'
        if value == "<":
            print_error("Error: variable '" + p[7] + "' must be initialized", str(p.lineno(1)) )
    
    # Check layer name
    if check_layer_name(p[5]) == False:
        print_error("Error: layer name unknown, you can use only: APP or NET or MAC", str(p.lineno(1)))
    
    # Check coerency of layer_field structure "layer.field1.field2.field3 ..."
    layer_field = str(p[5])
    id_counter = 0
    while len(layer_field) != 0:
        # search identifier in the string head
        try:
            substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*', layer_field).group(0)
            id_counter += 1
        except AttributeError:
            print_error("Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1)))
        
        # remove substring found
        layer_field = layer_field.replace(substring_found, "", 1)
        
        if len(layer_field) == 0:
            break;
        
        # search '.' in the string head
        try:
            substring_found = re.search('^\.', layer_field).group(0)
        except AttributeError:
            print_error("Error: layer.field attribute in change action has a bad structure, '.' missing", str(p.lineno(1)))
        
        layer_field = layer_field.replace(substring_found, "", 1)
    
        if len(layer_field) == 0:
            print_error("Error: layer.field attribute in change action has a bad structure, id missing", str(p.lineno(1)))    
    
    if id_counter < 2:
        print_error("Error: layer.field attribute in change action has a bad structure, field missing", str(p.lineno(1)))    
    
    # Coerency test passed, build the object
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Change(args)
    actions.append(action)
コード例 #8
0
def p_statement_change(p):
    "logical_statement : CHANGE LPAREN identifier COMMA layer_field_pair COMMA multi_type RPAREN"

    # Check the third argument
    if p[3] != "original":
        packet_check(p[3], p.lineno(1))

    # p[7] is multi_type (NUMBER, STRING, ID)
    if p[7] not in reserved_name and p[7] not in symbol_table.keys():

        re_pattern = r"^-?\d+(\.\d+)?"
        pattern = re.compile(re_pattern)

        # Add an entry in the variable table if STRING is not present in it
        if p[7][0] == "\"" and p[7][-1] == "\"":
            symbol_table[p[7]] = "VAR"
            variables[
                p[7]] = "<value>" + p[7][1:-1] + "</value><type>STRING</type>"

        # Add an entry in the variable table if NUMBER is not present in it
        elif re.match(pattern, p[7]):
            symbol_table[p[7]] = "VAR"
            variables[p[7]] = "<value>" + p[7] + "</value><type>NUMBER</type>"

        # Return error if the ID is not declared
        else:
            print_error("Error: '" + p[7] + "' undefined variable identifier",
                        str(p.lineno(1)))

    # Check if the variable is initialized
    if p[7] not in reserved_name:

        value = variables[p[7]][7]

        # Variable not initialized if its first char is '<'
        if value == "<":
            print_error("Error: variable '" + p[7] + "' must be initialized",
                        str(p.lineno(1)))

    # Check layer name
    if check_layer_name(p[5]) == False:
        print_error(
            "Error: layer name unknown, you can use only: APP or NET or MAC",
            str(p.lineno(1)))

    # Check coerency of layer_field structure "layer.field1.field2.field3 ..."
    layer_field = str(p[5])
    id_counter = 0
    while len(layer_field) != 0:
        # search identifier in the string head
        try:
            substring_found = re.search('^[a-zA-Z_][a-zA-Z_0-9]*',
                                        layer_field).group(0)
            id_counter += 1
        except AttributeError:
            print_error(
                "Error: layer.field attribute in change action has a bad structure, id missing",
                str(p.lineno(1)))

        # remove substring found
        layer_field = layer_field.replace(substring_found, "", 1)

        if len(layer_field) == 0:
            break

        # search '.' in the string head
        try:
            substring_found = re.search('^\.', layer_field).group(0)
        except AttributeError:
            print_error(
                "Error: layer.field attribute in change action has a bad structure, '.' missing",
                str(p.lineno(1)))

        layer_field = layer_field.replace(substring_found, "", 1)

        if len(layer_field) == 0:
            print_error(
                "Error: layer.field attribute in change action has a bad structure, id missing",
                str(p.lineno(1)))

    if id_counter < 2:
        print_error(
            "Error: layer.field attribute in change action has a bad structure, field missing",
            str(p.lineno(1)))

    # Coerency test passed, build the object
    args = str(p[3]) + ":" + str(p[5]) + ":" + str(p[7])
    action = Change(args)
    actions.append(action)