Line 5... |
Line 5... |
import os.path
|
import os.path
|
import StringIO
|
import StringIO
|
|
|
from chips.compiler.exceptions import C2CHIPError
|
from chips.compiler.exceptions import C2CHIPError
|
from chips.compiler.builtins import builtins
|
from chips.compiler.builtins import builtins
|
|
from chips.compiler.library import libs
|
|
|
operators = [
|
operators = [
|
"!", "~", "+", "-", "*", "/", "//", "%", "=", "==", "<", ">", "<=", ">=",
|
"!", "~", "+", "-", "*", "/", "//", "%", "=", "==", "<", ">", "<=", ">=",
|
"!=", "|", "&", "^", "||", "&&", "(", ")", "{", "}", "[", "]", ";", "<<",
|
"!=", "|", "&", "^", "||", "&&", "(", ")", "{", "}", "[", "]", ";", "<<",
|
">>", ",", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=", ">>=", "++",
|
">>", ",", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=", ">>=", "^=",
|
"--", "?", ":", "."
|
"++", "--", "?", ":", "."
|
]
|
]
|
|
|
class Tokens:
|
class Tokens:
|
|
|
"""Break the input file into a stream of tokens,
|
"""Break the input file into a stream of tokens,
|
Line 49... |
Line 50... |
filename = self.filename
|
filename = self.filename
|
lineno = self.lineno
|
lineno = self.lineno
|
self.tokens.extend(tokens)
|
self.tokens.extend(tokens)
|
directory = os.path.abspath(self.filename)
|
directory = os.path.abspath(self.filename)
|
directory = os.path.dirname(directory)
|
directory = os.path.dirname(directory)
|
|
if line.strip().endswith(">"):
|
|
self.filename = "library"
|
|
library = line.strip().split("<")[1].strip(' ><"')
|
|
self.scan(self.filename, StringIO.StringIO(libs[library]))
|
|
else:
|
self.filename = line.strip().replace("#include", "").strip(' ><"')
|
self.filename = line.strip().replace("#include", "").strip(' ><"')
|
self.filename = os.path.join(directory, self.filename)
|
self.filename = os.path.join(directory, self.filename)
|
self.scan(self.filename)
|
self.scan(self.filename)
|
self.lineno = lineno
|
self.lineno = lineno
|
self.filename = filename
|
self.filename = filename
|
Line 87... |
Line 93... |
tokens.append((self.filename, self.lineno, token))
|
tokens.append((self.filename, self.lineno, token))
|
token = char
|
token = char
|
|
|
#number
|
#number
|
elif token[0].isdigit():
|
elif token[0].isdigit():
|
if char.upper() in "UXABCDEFL0123456789":
|
if char.upper() in "UXABCDEFL0123456789.":
|
token += char
|
token += char
|
else:
|
else:
|
tokens.append((self.filename, self.lineno, token))
|
tokens.append((self.filename, self.lineno, token))
|
token = char
|
token = char
|
|
|