Пример #1
0
 def parse(self):
     if TokList.checkTok('ID'):
         self.altNo = 1
         self.s1 = Assign()
         self.s1.parse()
     elif TokList.checkTok('IF'):
         self.altNo = 2
         self.s2 = If()
         self.s2.parse()
     elif TokList.checkTok('WHILE'):
         self.altNo = 3
         self.s3 = Loop()
         self.s3.parse()
     elif TokList.checkTok('INPUT'):
         self.altNo = 4
         self.s4 = In()
         self.s4.parse()
     elif TokList.checkTok('OUTPUT'):
         self.altNo = 5
         self.s5 = Out()
         self.s5.parse()
     elif TokList.checkTok('CASE'):
         self.altNo = 6
         self.s6 = Case()
         self.s6.parse()
     else:
         #Used to briefly check for and EOF exception
         TokList.match('', 'statement')
Пример #2
0
 def parse(self):
     self.id = Id()
     self.id.parse(TokList.getIdOrConst())
     TokList.nextToken()
     TokList.match('ASSIGN', 'assign')
     self.expr = Expr()
     self.expr.parse()
     TokList.match('SEMICOLON', 'assign')
Пример #3
0
 def parse(self):
     self.id = Id()
     #Passing in name of id to the parse function
     self.id.parse(TokList.getIdOrConst())
     TokList.nextToken()
     if TokList.checkTok('COMMA'):
         TokList.match('COMMA', 'id list')
         self.id_list = IdList()
         self.id_list.parse()
Пример #4
0
 def parse(self):
     self.const = Const()
     self.const.parse(TokList.getIdOrConst())
     TokList.nextToken()
     if TokList.currentToken() == 'COMMA':
         self.constList = ConstList()
         self.constList.parse()
     TokList.match('COLON', 'case line')
     self.expr = Expr()
     self.expr.parse()
     self.caseLineFollow = CaseLineFollow()
     self.caseLineFollow.parse()
Пример #5
0
 def parse(self):
     TokList.match('CASE','case')
     self.id = Id()
     self.id.parse(TokList.getIdOrConst())
     TokList.nextToken()
     TokList.match('OF','case')
     self.case_line = CaseLine()
     self.case_line.parse()
     TokList.match('ELSE','case')
     self.expr = Expr()
     self.expr.parse()
     TokList.match('END','case')
     TokList.match('SEMICOLON','case')
Пример #6
0
 def parse(self):
     if TokList.checkTok('CONST'):
         self.const = Const()
         self.const.parse(TokList.getIdOrConst())
         TokList.nextToken()
     elif TokList.checkTok('ID'):
         self.id = Id()
         self.id.parse(TokList.getIdOrConst())
         TokList.nextToken()
     elif TokList.match('LEFTPARAN', 'factor'):
         self.expr = Expr.Expr()
         self.expr.parse()
         TokList.match('RIGHTPARAN', 'factor')
Пример #7
0
 def parse(self):
     if TokList.checkTok('NOT'):
         self.notStr = '!'
         TokList.nextToken()
         TokList.match('LEFTPARAN', 'cond')
         self.cond = Cond()
         self.cond.parse()
         TokList.match('RIGHTPARAN', 'cond')
         return
     self.cmpr = Cmpr()
     self.cmpr.parse()
     if TokList.checkTok('OR'):
         TokList.nextToken()
         self.cond = Cond()
         self.cond.parse()
Пример #8
0
 def parse(self):
     TokList.match('WHILE', 'loop')
     self.cond = Cond()
     self.cond.parse()
     TokList.match('BEGIN', 'loop')
     self.stmt_seq = StmtSeq.StmtSeq()
     self.stmt_seq.parse()
     TokList.match('ENDWHILE', 'loop')
     TokList.match('SEMICOLON', 'loop')
Пример #9
0
 def parse(self):
     TokList.match('IF', 'if')
     self.cond = Cond()
     self.cond.parse()
     TokList.match('THEN', 'if')
     self.stmt_seq_then = StmtSeq.StmtSeq()
     self.stmt_seq_then.parse()
     if TokList.checkTok('ELSE'):
         TokList.nextToken()
         self.stmt_seq_else = StmtSeq.StmtSeq()
         self.stmt_seq_else.parse()
     TokList.match('ENDIF', 'if')
     TokList.match('SEMICOLON', 'if')
Пример #10
0
 def parse(self):
     TokList.match("PROGRAM", "program")
     self.decl_seq = DeclSeq()
     self.decl_seq.parse()
     TokList.match("BEGIN", "program")
     self.stmt_seq = StmtSeq()
     self.stmt_seq.parse()
     TokList.match("END", "program")
     #Checks for code after end of program
     if not TokList.checkTok('EOF'):
         print("ERROR: Improper code after end of program")
Пример #11
0
 def parse(self):
     TokList.match('INT', "decl")
     self.id_list = IdList()
     self.id_list.parse()
     TokList.match('SEMICOLON', "decl")
Пример #12
0
 def parse(self):
     TokList.match('INPUT', 'input')
     self.idList = IdList()
     self.idList.parse()
     TokList.match('SEMICOLON', 'input')
Пример #13
0
 def parse(self):
     TokList.match('OUTPUT', 'output')
     self.expr = Expr()
     self.expr.parse()
     TokList.match('SEMICOLON', 'output')
Пример #14
0
 def parse(self):
     if not TokList.checkTok('BAR'):
         return
     TokList.match('BAR', 'case line follow')
     self.caseLine = CaseLine.CaseLine()
     self.caseLine.parse()