comparison python/c3/parser.py @ 293:6aa721e7b10b

Try to improve build sequence
author Windel Bouwman
date Thu, 28 Nov 2013 20:39:37 +0100
parents bd2593de3ff8
children 9417caea2eb3
comparison
equal deleted inserted replaced
292:534b94b40aa8 293:6aa721e7b10b
1 import logging 1 import logging
2 from . import astnodes, lexer 2 from .lexer import Lexer
3 from . import astnodes
3 from ppci import CompilerError 4 from ppci import CompilerError
4 5
5 6
6 class Parser: 7 class Parser:
7 """ Parses sourcecode into an abstract syntax tree (AST) """ 8 """ Parses sourcecode into an abstract syntax tree (AST) """
8 def __init__(self, diag): 9 def __init__(self, diag):
9 self.logger = logging.getLogger('c3') 10 self.logger = logging.getLogger('c3')
10 self.diag = diag 11 self.diag = diag
12 self.lexer = Lexer(diag)
11 13
12 def parseSource(self, source): 14 def parseSource(self, source):
13 self.logger.info('Parsing source') 15 self.logger.info('Parsing source')
14 self.initLex(source) 16 self.initLex(source)
15 try: 17 try:
47 if t.typ != 'END': 49 if t.typ != 'END':
48 self.token = self.tokens.__next__() 50 self.token = self.tokens.__next__()
49 return t 51 return t
50 52
51 def initLex(self, source): 53 def initLex(self, source):
52 self.tokens = lexer.tokenize(source) # Lexical stage 54 self.tokens = self.lexer.tokenize(source)
53 self.token = self.tokens.__next__() 55 self.token = self.tokens.__next__()
54 56
55 def addDeclaration(self, decl): 57 def addDeclaration(self, decl):
56 self.currentPart.declarations.append(decl) 58 self.currentPart.declarations.append(decl)
57 59