Exemple #1
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     self.__id = IdNode.parse(t)
     if t.currentToken().value == SPECIAL_SYMBOLS[","]:
         match_consume(",", t)
         self.__id_list = IdListNode()
         self.__id_list.parse(t)
Exemple #2
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     self.__fac.parse(t)
     if t.currentToken().value == SPECIAL_SYMBOLS["*"]:
         match_consume("*", t)
         self.__t = TermNode()
         self.__t.parse(t)
Exemple #3
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     if t.currentToken().key not in symbol_table:
         report_error_undeclared_identifier(t)
     self.__id = symbol_table[t.currentToken().key]
     t.nextToken()
     match_consume("=", t)
     self.__exp.parse(t)
     match_consume(";", t)
Exemple #4
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     match_consume("if", t)
     self.__cond.parse(t)
     match_consume("then", t)
     self.__ss_true.parse(t)
     if t.currentToken().value == RESERVED_WORDS["else"]:
         match_consume("else", t)
         from Nodes.StatementSequenceNode import StatementSequenceNode
         self.__ss_false = StatementSequenceNode()
         self.__ss_false.parse(t)
     match_consume("end", t)
     match_consume(";", t)
Exemple #5
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     if t.currentToken().value == TOKEN_VALUE_INTEGER:
         self.__int = int(t.currentToken().key)
         t.nextToken()
         self.__alt = 1
     elif t.currentToken().value == TOKEN_VALUE_IDENTIFIER:
         self.__id = symbol_table[t.currentToken().key]
         t.nextToken()
         self.__alt = 2
     elif t.currentToken().value == SPECIAL_SYMBOLS["("]:
         match_consume("(", t)
         from Nodes.ExpressionNode import ExpressionNode
         self.__exp = ExpressionNode()
         self.__exp.parse(t)
         match_consume(")", t)
         self.__alt = 3
     else:
         report_error_expected_expresion(t)
Exemple #6
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     match_consume("program", t)
     self.__ds.parse(t)
     match_consume("begin", t)
     self.__ss.parse(t)
     match_consume("end", t)
     if t.currentToken().value != TOKEN_VALUE_EOF:
         report_error_expected_eof(t)
Exemple #7
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     if t.currentToken().value == SPECIAL_SYMBOLS["("]:
         self.__comp = ComparisonNode()
         self.__comp.parse(t)
         self.__alt = 1
     elif t.currentToken().value == SPECIAL_SYMBOLS["!"]:
         match_consume("!", t)
         self.__cond1 = ConditionNode()
         self.__cond1.parse(t)
         self.__alt = 2
     elif t.currentToken().value == SPECIAL_SYMBOLS["["]:
         match_consume("[", t)
         self.__cond1 = ConditionNode()
         self.__cond1.parse(t)
         if t.currentToken().value == RESERVED_WORDS["and"]:
             match_consume("and", t)
             self.__alt = 3
         else: # or
             match_consume("or", t)
             self.__alt = 4
         self.__cond2 = ConditionNode()
         self.__cond2.parse(t)
         match_consume("]", t)
Exemple #8
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     match_consume("read", t)
     self.__id_list.parse(t)
     match_consume(";", t)
Exemple #9
0
 def parse(self, t):
     self.__line_number = t.currentToken().line_number
     match_consume("(", t)
     self.__fac1.parse(t)
     if t.currentToken().value == SPECIAL_SYMBOLS["!="]:
         match_consume("!=", t)
         self.__alt = 1
     elif t.currentToken().value == SPECIAL_SYMBOLS["=="]:
         match_consume("==", t)
         self.__alt = 2
     elif t.currentToken().value == SPECIAL_SYMBOLS["<"]:
         match_consume("<", t)
         self.__alt = 3
     elif t.currentToken().value == SPECIAL_SYMBOLS[">"]:
         match_consume(">", t)
         self.__alt = 4
     elif t.currentToken().value == SPECIAL_SYMBOLS["<="]:
         match_consume("<=", t)
         self.__alt = 5
     elif t.currentToken().value == SPECIAL_SYMBOLS[">="]:
         match_consume(">=", t)
         self.__alt = 6
     self.__fac2.parse(t)
     match_consume(")", t)