Mercurial > lcfOS
comparison ide/compiler/compiler.py @ 5:818f80afa78b
Added handy highlighting to IDE
author | windel-eee |
---|---|
date | Thu, 22 Sep 2011 17:44:31 +0200 |
parents | 92df07bc2081 |
children | 1784af239df4 |
comparison
equal
deleted
inserted
replaced
4:0d5ef85b8698 | 5:818f80afa78b |
---|---|
1 import hashlib | 1 import hashlib |
2 # Import compiler components: | 2 # Import compiler components: |
3 from . import lexer | 3 from . import lexer |
4 from . import parser | 4 from .parser import Parser |
5 from .codegenerator import CodeGenerator | 5 from .codegenerator import CodeGenerator |
6 from .nodes import ExportedSymbol | 6 from .nodes import ExportedSymbol |
7 | 7 |
8 class Compiler: | 8 class Compiler: |
9 versie = '0.9.3' | 9 versie = '0.9.3' |
14 def generateSignature(self, src): | 14 def generateSignature(self, src): |
15 return hashlib.md5(bytes(src,encoding='ascii')).hexdigest() | 15 return hashlib.md5(bytes(src,encoding='ascii')).hexdigest() |
16 | 16 |
17 def compilesource(self, src): | 17 def compilesource(self, src): |
18 """ Front end that handles the stages: """ | 18 """ Front end that handles the stages: """ |
19 # Pass 1: parsing and type checking | |
19 tokens = lexer.tokenize(src) # Lexical stage | 20 tokens = lexer.tokenize(src) # Lexical stage |
20 ast = parser.Parser(tokens).parseModule() # Parse a module | 21 p = Parser(tokens) |
22 ast = p.parseModule() # Parse a module | |
23 print(p.errorlist) | |
24 if len(p.errorlist) > 0: | |
25 self.errorlist = p.errorlist | |
26 return | |
27 # Pass 2: code generation | |
21 CodeGenerator().generatecode(ast) | 28 CodeGenerator().generatecode(ast) |
22 # Attach a signature: | 29 # Attach a signature: |
23 ast.signature = self.generateSignature(src) | 30 ast.signature = self.generateSignature(src) |
24 # Generate exported symbols: | 31 # Generate exported symbols: |
25 ast.exports = [] | 32 ast.exports = [] |