示例#1
0
 def process_17(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(
             AstNode(ntype=22, content=None, subNode=[sub1]))
         return self.process_17(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         parentheses_count = 0
         while (True):
             self.get_temp_cont()
             if (self.temp_cont in [';', '{', '}']):
                 break
             elif (self.temp_cont == ')'):
                 self.AstNodes.append(
                     AstNode(ntype=1, content=self.pointer, subNode=[]))
                 self.pointer += 1
                 self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)
                 parentheses_count -= 1
                 if (parentheses_count == 0):
                     break
             elif (self.temp_cont == '('):
                 self.AstNodes.append(
                     AstNode(ntype=1, content=self.pointer, subNode=[]))
                 self.pointer += 1
                 self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)
                 parentheses_count += 1
             else:
                 self.AstNodes.append(
                     AstNode(ntype=1, content=self.pointer, subNode=[]))
                 self.pointer += 1
                 self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)
         return value
示例#2
0
 def process_18(self, way: int, value=None):
     if ((way == 0) and (self.temp_cont == '{')):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(
             AstNode(ntype=23, content=None, subNode=[sub1]))
         return self.process_18(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '}'):
             self.token_append(value)
             return value
         elif (self.temp_cont in ['default', 'case']):
             self.AstNodes[value].subNode.append(self.process_19(way=0))
             return self.process_18(way=1, value=value)
         elif (self.text[self.text_map[self.pointer]][0] == 'Label'):
             self.AstNodes[value].subNode.append(self.process_15(way=0))
             return self.process_18(way=1, value=value)
         elif (self.temp_cont == '#'):
             self.AstNodes[value].subNode.append(self.process_2(way=0))
             return self.process_18(way=1, value=value)
         else:
             return self.process_error(value)
示例#3
0
 def process_9(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(
             AstNode(ntype=14, content=None, subNode=[sub1]))
         return self.process_9(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.AstNodes[value].subNode.append(self.process_10(way=0))
         return value
示例#4
0
 def process_24(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=30, content=None, subNode=[]))
         return self.process_24(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         while (True):
             self.get_temp_cont()
             self.AstNodes.append(
                 AstNode(ntype=1, content=self.pointer, subNode=[]))
             self.pointer += 1
             self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)
             if (self.temp_cont == ';'):
                 break
         return value
示例#5
0
 def process_6(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=11, content=None, subNode=[]))
         return self.process_6(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         temp_conts = self.get_next_cont(2)
         if (temp_conts[0] == 'if'):
             self.AstNodes[value].subNode.append(self.process_7(way=0))
             return self.process_6(way=2, value=value)
         elif (temp_conts == ['else', 'if']):
             self.AstNodes[value].subNode.append(self.process_8(way=0))
             return self.process_6(way=2, value=value)
         elif (temp_conts[0] == 'else'):
             self.AstNodes[value].subNode.append(self.process_9(way=0))
             return self.process_6(way=2, value=value)
         else:
             return value
     elif (way == 2):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return self.process_6(way=1, value=value)
         else:
             self.AstNodes[value].subNode.append(self.process_5(way=0))
             return self.process_6(way=1, value=value)
示例#6
0
 def process_21(self, way: int, value=None):
     if ((way == 0) and (self.temp_cont == '{')):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(
             AstNode(ntype=27, content=None, subNode=[sub1]))
         return self.process_21(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '}'):
             self.token_append(value)
             return value
         else:
             self.AstNodes[value].subNode.append(self.process_22(way=0))
             return self.process_21(way=1, value=value)
示例#7
0
 def process_4(self, way: int, value=None):
     if (self.pointer > len(self.text_map) - 1):
         return value
     if ((way == 0) and (self.temp_cont == '{')):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(AstNode(ntype=4, content=None,
                                      subNode=[sub1]))
         return self.process_4(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == '}'):
             self.token_append(value)
             return value
         elif (self.temp_cont == 'if'):
             self.AstNodes[value].subNode.append(self.process_6(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == 'for'):
             self.AstNodes[value].subNode.append(self.process_11(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == 'while'):
             self.AstNodes[value].subNode.append(self.process_13(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == 'switch'):
             self.AstNodes[value].subNode.append(self.process_16(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == 'do'):
             self.AstNodes[value].subNode.append(self.process_23(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont == '#'):
             self.AstNodes[value].subNode.append(self.process_2(way=0))
             return self.process_4(way=1, value=value)
         elif (self.text[self.text_map[self.pointer]][0] == 'Label'):
             self.AstNodes[value].subNode.append(self.process_15(way=0))
             return self.process_4(way=1, value=value)
         else:
             self.AstNodes[value].subNode.append(self.process_5(way=0))
             return self.process_4(way=1, value=value)
     else:
         return self.process_error(value)
示例#8
0
 def process_20(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=25, content=None, subNode=[]))
         return self.process_20(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         parentheses_count = 0
         while (True):
             self.get_temp_cont()
             self.AstNodes.append(
                 AstNode(ntype=1, content=self.pointer, subNode=[]))
             self.pointer += 1
             self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)
             if (self.temp_cont == ':'):
                 break
             elif (self.temp_cont == ')'):
                 parentheses_count -= 1
                 if (parentheses_count == 0):
                     break
             elif (self.temp_cont == '('):
                 parentheses_count += 1
         return value
示例#9
0
 def process_2(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=3, content=None, subNode=[]))
         return self.process_2(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if ('\n' in self.temp_cont):
             self.token_append(value)
             return value
         else:
             self.token_append(value)
             return self.process_2(way=1, value=value)
示例#10
0
 def process_1(self, way: int, value=None):
     if (self.pointer > len(self.text_map) - 1):
         return value
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=10, content=None, subNode=[]))
         return self.process_1(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '#'):
             self.AstNodes[value].subNode.append(self.process_2(way=0))
             return self.process_1(way=1, value=value)
         else:
             return value
示例#11
0
 def process_23(self, way: int, value=None):
     if ((way == 0) and (self.temp_cont == 'do')):
         self.AstNodes.append(
             AstNode(ntype=1, content=self.pointer, subNode=[]))
         self.pointer += 1
         sub1 = len(self.AstNodes) - 1
         self.AstNodes.append(
             AstNode(ntype=29, content=None, subNode=[sub1]))
         return self.process_23(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
         return self.process_23(way=2, value=value)
     elif (way == 2):
         self.get_temp_cont()
         if (self.temp_cont == 'while'):
             self.AstNodes[value].subNode.append(self.process_24(way=0))
             return value
         else:
             self.AstNodes[value].ntype = 4
             return value
示例#12
0
 def process_5(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=2, content=None, subNode=[]))
         return self.process_5(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == ';'):
             self.token_append(value)
             return value
         # elif(self.temp_cont == '{'):
         #     self.AstNodes[value].subNode.append(self.process_4(way=0))
         #     return value
         else:
             self.token_append(value)
             return self.process_5(way=1, value=value)
示例#13
0
 def process_16(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=21, content=None, subNode=[]))
         return self.process_16(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == 'switch'):
             self.AstNodes[value].subNode.append(self.process_17(way=0))
             return self.process_16(way=2, value=value)
         else:
             return self.process_error(value)
     elif (way == 2):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_18(way=0))
             return value
示例#14
0
 def process_13(self, way: int, value=None):
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=18, content=None, subNode=[]))
         return self.process_13(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == 'while'):
             self.AstNodes[value].subNode.append(self.process_14(way=0))
             return self.process_13(way=2, value=value)
         else:
             return self.process_error(value)
     elif (way == 2):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return value
         else:
             self.AstNodes[value].subNode.append(self.process_5(way=0))
             return value
示例#15
0
 def process_19(self, way: int, value=None):
     if ((way == 0) and (self.temp_cont in ['default', 'case'])):
         self.AstNodes.append(
             AstNode(ntype=24,
                     content=None,
                     subNode=[self.process_20(way=0)]))
         return self.process_19(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return self.process_4(way=1, value=value)
         elif (self.temp_cont in ['}', 'default', 'case']):
             return value
         elif (self.temp_cont == 'if'):
             self.AstNodes[value].subNode.append(self.process_6(way=0))
             return self.process_19(way=1, value=value)
         elif (self.temp_cont == 'for'):
             self.AstNodes[value].subNode.append(self.process_11(way=0))
             return self.process_19(way=1, value=value)
         elif (self.temp_cont == 'while'):
             self.AstNodes[value].subNode.append(self.process_13(way=0))
             return self.process_19(way=1, value=value)
         elif (self.temp_cont == 'switch'):
             self.AstNodes[value].subNode.append(self.process_16(way=0))
             return self.process_19(way=1, value=value)
         elif (self.temp_cont == 'do'):
             self.AstNodes[value].subNode.append(self.process_23(way=0))
             return self.process_19(way=1, value=value)
         elif (self.temp_cont == '#'):
             self.AstNodes[value].subNode.append(self.process_2(way=0))
             return self.process_19(way=1, value=value)
         elif (self.text[self.text_map[self.pointer]][0] == 'Label'):
             self.AstNodes[value].subNode.append(self.process_15(way=0))
             return self.process_19(way=1, value=value)
         else:
             self.AstNodes[value].subNode.append(self.process_5(way=0))
             return self.process_19(way=1, value=value)
示例#16
0
 def process_3(self, way: int, value=None):
     if (self.pointer > len(self.text_map) - 1):
         return value
     if (way == 0):
         self.AstNodes.append(AstNode(ntype=6, content=None, subNode=[]))
         return self.process_3(way=1, value=(len(self.AstNodes) - 1))
     elif (way == 1):
         self.get_temp_cont()
         if (self.text[self.text_map[self.pointer]][0] == 'Keyword'):
             return self.process_3(way=2, value=value)
         else:
             return self.process_3(way=4, value=value)
     #start with keywords
     elif (way == 2):
         self.get_temp_cont()
         if (self.temp_cont == 'struct'):
             self.token_append(value)
             return self.process_3(way=6, value=value)
         elif ((self.text[self.text_map[self.pointer]][0] == 'Keyword')
               or (self.temp_cont == '*')):
             self.token_append(value)
             return self.process_3(way=2, value=value)
         elif (self.text[self.text_map[self.pointer]][0] == 'Funcname'):
             self.token_append(value)
             return self.process_3(way=3, value=value)
         else:
             return self.process_3(way=5, value=value)
     #function implementation or declaration
     elif (way == 3):
         self.get_temp_cont()
         if (self.temp_cont == ';'):
             self.token_append(value)
             self.AstNodes[value].ntype = 26
             return value
         elif (self.temp_cont == '{'):
             self.AstNodes[value].ntype = 7
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return value
         else:
             self.token_append(value)
             return self.process_3(way=3, value=value)
     #plain statement
     elif (way == 4):
         self.AstNodes[value].ntype = 5
         self.get_temp_cont()
         if (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_4(way=0))
             return value
         elif (self.temp_cont == '#'):
             self.AstNodes[value].subNode.append(self.process_2(way=0))
             return value
         elif (self.text[self.text_map[self.pointer]][0] == 'Label'):
             self.AstNodes[value].subNode.append(self.process_15(way=0))
             return value
         else:
             return self.process_3(way=5, value=value)
     #other
     elif (way == 5):
         self.AstNodes[value].ntype = 2
         self.get_temp_cont()
         if (self.temp_cont == ';'):
             self.token_append(value)
             return value
         elif (self.temp_cont == '{'):
             self.AstNodes[value].subNode.append(self.process_21(way=0))
             return self.process_3(way=5, value=value)
         else:
             self.token_append(value)
             return self.process_3(way=5, value=value)
     elif (way == 6):
         self.token_append(value)
         return self.process_3(way=2, value=value)
示例#17
0
 def token_append(self, value):
     self.AstNodes.append(AstNode(ntype=1, content=self.pointer,
                                  subNode=[]))
     self.pointer += 1
     self.AstNodes[value].subNode.append(len(self.AstNodes) - 1)