Skip to content
Snippets Groups Projects
Commit 870d25ee authored by Richard Torenvliet's avatar Richard Torenvliet
Browse files

Merge branch 'master' of github.com:taddeus/peephole

Conflicts:
	src/optimize.py
parents eea69c60 61b61a39
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,13 @@ import ply.yacc as yacc ...@@ -3,11 +3,13 @@ import ply.yacc as yacc
from statement import Statement as S, Block from statement import Statement as S, Block
# Global statements administration # Global statements administration
statements = [] statements = []
tokens = ('NEWLINE', 'WORD', 'COMMENT', 'DIRECTIVE', 'COMMA', 'COLON') tokens = ('NEWLINE', 'WORD', 'COMMENT', 'DIRECTIVE', 'COMMA', 'COLON')
# Tokens # Tokens
def t_NEWLINE(t): def t_NEWLINE(t):
r'\n+' r'\n+'
...@@ -32,7 +34,7 @@ def t_DIRECTIVE(t): ...@@ -32,7 +34,7 @@ def t_DIRECTIVE(t):
return t return t
def t_hex_word(t): def t_hex_word(t):
r'0x[0-9a-fA-F]{8}' r'0x([0-9a-fA-F]{8}|[0-9a-fA-F]{4})'
t.type = 'WORD' t.type = 'WORD'
return t return t
...@@ -47,9 +49,10 @@ def t_int(t): ...@@ -47,9 +49,10 @@ def t_int(t):
return t return t
def t_WORD(t): def t_WORD(t):
r'[a-zA-Z0-9$_.+()]+' r'[a-zA-Z0-9$_.+()-]+'
return t return t
# Ignore whitespaces # Ignore whitespaces
t_ignore = ' \t' t_ignore = ' \t'
...@@ -57,9 +60,11 @@ def t_error(t): ...@@ -57,9 +60,11 @@ def t_error(t):
print('Illegal character "%s"' % t.value[0]) print('Illegal character "%s"' % t.value[0])
t.lexer.skip(1) t.lexer.skip(1)
# Build the lexer # Build the lexer
lexer = lex.lex() lexer = lex.lex()
# Parsing rules # Parsing rules
start = 'input' start = 'input'
...@@ -102,9 +107,14 @@ def p_command(p): ...@@ -102,9 +107,14 @@ def p_command(p):
def p_error(p): def p_error(p):
print 'Syntax error at "%s" on line %d' % (p.value, lexer.lineno) print 'Syntax error at "%s" on line %d' % (p.value, lexer.lineno)
# Build YACC
yacc.yacc() yacc.yacc()
def parse_file(filename): def parse_file(filename):
"""Parse a given Assembly file, return a Block with Statement objects
containing the parsed instructions."""
global statements global statements
statements = [] statements = []
......
This diff is collapsed.
This diff is collapsed.
File deleted
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment