Mercurial > lcfOS
comparison python/ppci/frontends/ks/parser.py @ 101:af0d7913677a
Fixes and splitting into 3 stage
author | windel |
---|---|
date | Mon, 24 Dec 2012 17:55:08 +0100 |
parents | fe145e42259d |
children | 63937c8d1478 |
comparison
equal
deleted
inserted
replaced
100:fe145e42259d | 101:af0d7913677a |
---|---|
3 """ | 3 """ |
4 | 4 |
5 from .symboltable import SymbolTable | 5 from .symboltable import SymbolTable |
6 from .nodes import * | 6 from .nodes import * |
7 from ...core.errors import CompilerException, Error | 7 from ...core.errors import CompilerException, Error |
8 #from .modules import loadModule | |
9 #from .display import printNode | |
10 #from .builtin import * | 8 #from .builtin import * |
11 #from . import assembler | 9 #from . import assembler |
10 from .lexer import tokenize | |
12 | 11 |
13 class KsParser: | 12 class KsParser: |
14 def __init__(self, tokens): | 13 def __init__(self, source): |
15 """ provide the parser with the tokens iterator from the lexer. """ | 14 """ provide the parser with the tokens iterator from the lexer. """ |
16 self.tokens = tokens | 15 self.tokens = tokenize(source) # Lexical stage |
17 self.NextToken() | 16 self.NextToken() |
18 self.errorlist = [] | 17 self.errorlist = [] |
19 | 18 |
20 def Error(self, msg): | 19 def Error(self, msg): |
21 raise CompilerException(msg, self.token.row, self.token.col) | 20 raise CompilerException(msg, self.token.row, self.token.col) |
51 Recursive descent parser functions: | 50 Recursive descent parser functions: |
52 A set of mutual recursive functions. | 51 A set of mutual recursive functions. |
53 Starting symbol is the Module. | 52 Starting symbol is the Module. |
54 """ | 53 """ |
55 def parseModule(self): | 54 def parseModule(self): |
55 """ Top level parsing routine """ | |
56 self.imports = [] | 56 self.imports = [] |
57 loc = self.getLocation() | 57 loc = self.getLocation() |
58 self.Consume('module') | 58 self.Consume('module') |
59 modname = self.Consume('ID') | 59 modname = self.Consume('ID') |
60 self.Consume(';') | 60 self.Consume(';') |
96 self.Consume(';') | 96 self.Consume(';') |
97 | 97 |
98 def parseImport(self): | 98 def parseImport(self): |
99 loc = self.getLocation() | 99 loc = self.getLocation() |
100 modname = self.Consume('ID') | 100 modname = self.Consume('ID') |
101 mod = loadModule(modname) | 101 #mod = loadModule(modname) |
102 self.setLocation(mod, loc) | 102 self.setLocation(mod, loc) |
103 self.cst.addSymbol(mod) | 103 self.cst.addSymbol(mod) |
104 | 104 |
105 # Helper to parse an identifier defenitions | 105 # Helper to parse an identifier defenitions |
106 def parseIdentDef(self): | 106 def parseIdentDef(self): |