Corrected special character formatting.

This commit is contained in:
Maggie Mari 2012-08-14 18:28:17 -05:00
commit 538fd76b1f
6 changed files with 92 additions and 92 deletions

View file

@ -753,19 +753,19 @@ external libraries at all for this.
pass
class IdentifierToken(object):
def **init**\ (self, name):
def __init__(self, name):
self.name = name
class NumberToken(object):
def **init**\ (self, value):
def __init__(self, value):
self.value = value
class CharacterToken(object):
def **init**\ (self, char):
def __init__(self, char):
self.char = char
def **eq**\ (self, other):
def __eq__(self, other):
return isinstance(other, CharacterToken) and self.char == other.char
def **ne**\ (self, other):
def __ne__(self, other):
return not self == other
# Regular expressions that tokens and comments of our language.
@ -815,24 +815,24 @@ external libraries at all for this.
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value):
def __init__(self, value):
self.value = value
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name):
def __init__(self, name):
self.name = name
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right):
def __init__(self, operator, left, right):
self.operator = operator
self.left = left
self.right = right
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args):
def __init__(self, callee, args):
self.callee = callee
self.args = args
@ -840,12 +840,12 @@ external libraries at all for this.
# and its argument names (thus implicitly the number of arguments the function
# takes).
class PrototypeNode(object):
def **init**\ (self, name, args):
def __init__(self, name, args):
self.name = name
self.args = args
# This class represents a function definition itself.
class FunctionNode(object): def **init**\ (self, prototype, body):
class FunctionNode(object): def __init__(self, prototype, body):
self.prototype = prototype self.body = body
Parser

View file

@ -37,14 +37,14 @@ First we define code generation methods in each AST node class:
# Expression class for numeric literals like
"1.0". class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): ...
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): ...
@ -623,15 +623,15 @@ need to `download <../download.html>`_ and
class ExternToken(object): pass
class IdentifierToken(object): def **init**\ (self, name): self.name =
class IdentifierToken(object): def __init__(self, name): self.name =
name
class NumberToken(object): def **init**\ (self, value): self.value =
class NumberToken(object): def __init__(self, value): self.value =
value
class CharacterToken(object): def **init**\ (self, char): self.char =
char def **eq**\ (self, other): return isinstance(other, CharacterToken)
and self.char == other.char def **ne**\ (self, other): return not self
class CharacterToken(object): def __init__(self, char): self.char =
char def __eq__(self, other): return isinstance(other, CharacterToken)
and self.char == other.char def __ne__(self, other): return not self
== other
# Regular expressions that tokens and comments of our language.
@ -682,14 +682,14 @@ need to `download <../download.html>`_ and
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): return Constant.real(Type.double(), self.value)
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): if self.name in g_named_values: return
g_named_values[self.name] else: raise RuntimeError('Unknown variable
@ -698,7 +698,7 @@ need to `download <../download.html>`_ and
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right): self.operator = operator
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def CodeGen(self): left = self.left.CodeGen() right =
@ -722,7 +722,7 @@ need to `download <../download.html>`_ and
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args): self.callee = callee self.args =
def __init__(self, callee, args): self.callee = callee self.args =
args
def CodeGen(self): # Look up the name in the global module table. callee
@ -743,7 +743,7 @@ need to `download <../download.html>`_ and
# takes).
class PrototypeNode(object):
def **init**\ (self, name, args): self.name = name self.args = args
def __init__(self, name, args): self.name = name self.args = args
def CodeGen(self): # Make the function type, eg. double(double,double).
funct_type = Type.function( Type.double(), [Type.double()] \*
@ -779,7 +779,7 @@ need to `download <../download.html>`_ and
# This class represents a function definition itself.
class FunctionNode(object):
def **init**\ (self, prototype, body): self.prototype = prototype
def __init__(self, prototype, body): self.prototype = prototype
self.body = body
def CodeGen(self): # Clear scope. g_named_values.clear()
@ -812,7 +812,7 @@ need to `download <../download.html>`_ and
class Parser(object):
def **init**\ (self, tokens, binop_precedence): self.tokens = tokens
def __init__(self, tokens, binop_precedence): self.tokens = tokens
self.binop_precedence = binop_precedence self.Next()
# Provide a simple token buffer. Parser.current is the current token the
@ -976,4 +976,4 @@ need to `download <../download.html>`_ and
# Print out all of the generated code. print '', g_llvm_module
if **name** == '**main**\ ': main()
if **name** == '__main__': main()

View file

@ -434,15 +434,15 @@ the LLVM JIT and optimizer:
class ExternToken(object): pass
class IdentifierToken(object): def **init**\ (self, name): self.name =
class IdentifierToken(object): def __init__(self, name): self.name =
name
class NumberToken(object): def **init**\ (self, value): self.value =
class NumberToken(object): def __init__(self, value): self.value =
value
class CharacterToken(object): def **init**\ (self, char): self.char =
char def **eq**\ (self, other): return isinstance(other, CharacterToken)
and self.char == other.char def **ne**\ (self, other): return not self
class CharacterToken(object): def __init__(self, char): self.char =
char def __eq__(self, other): return isinstance(other, CharacterToken)
and self.char == other.char def __ne__(self, other): return not self
== other
# Regular expressions that tokens and comments of our language.
@ -493,14 +493,14 @@ the LLVM JIT and optimizer:
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): return Constant.real(Type.double(), self.value)
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): if self.name in g_named_values: return
g_named_values[self.name] else: raise RuntimeError('Unknown variable
@ -509,7 +509,7 @@ the LLVM JIT and optimizer:
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right): self.operator = operator
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def CodeGen(self): left = self.left.CodeGen() right =
@ -533,7 +533,7 @@ the LLVM JIT and optimizer:
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args): self.callee = callee self.args =
def __init__(self, callee, args): self.callee = callee self.args =
args
def CodeGen(self): # Look up the name in the global module table. callee
@ -554,7 +554,7 @@ the LLVM JIT and optimizer:
# takes).
class PrototypeNode(object):
def **init**\ (self, name, args): self.name = name self.args = args
def __init__(self, name, args): self.name = name self.args = args
def CodeGen(self): # Make the function type, eg. double(double,double).
funct_type = Type.function( Type.double(), [Type.double()] \*
@ -590,7 +590,7 @@ the LLVM JIT and optimizer:
# This class represents a function definition itself.
class FunctionNode(object):
def **init**\ (self, prototype, body): self.prototype = prototype
def __init__(self, prototype, body): self.prototype = prototype
self.body = body
def CodeGen(self): # Clear scope. g_named_values.clear()
@ -626,7 +626,7 @@ the LLVM JIT and optimizer:
class Parser(object):
def **init**\ (self, tokens, binop_precedence): self.tokens = tokens
def __init__(self, tokens, binop_precedence): self.tokens = tokens
self.binop_precedence = binop_precedence self.Next()
# Provide a simple token buffer. Parser.current is the current token the
@ -805,4 +805,4 @@ the LLVM JIT and optimizer:
# Print out all of the generated code. print '', g_llvm_module
if **name** == '**main**\ ': main()
if **name** == '__main__': main()

View file

@ -99,7 +99,7 @@ To represent the new expression we add a new AST node for it:
# Expression class for if/then/else. class
IfExpressionNode(ExpressionNode):
def **init**\ (self, condition, then_branch, else_branch):
def __init__(self, condition, then_branch, else_branch):
self.condition = condition self.then_branch = then_branch
self.else_branch = else_branch
@ -502,7 +502,7 @@ variable name and the constituent expressions in the node.
# Expression class for for/in. class
ForExpressionNode(ExpressionNode):
def **init**\ (self, loop_variable, start, end, step, body):
def __init__(self, loop_variable, start, end, step, body):
self.loop_variable = loop_variable self.start = start self.end = end
self.step = step self.body = body
@ -835,15 +835,15 @@ the if/then/else and for expressions:
ThenToken(object): pass class ElseToken(object): pass class
ForToken(object): pass class InToken(object): pass
class IdentifierToken(object): def **init**\ (self, name): self.name =
class IdentifierToken(object): def __init__(self, name): self.name =
name
class NumberToken(object): def **init**\ (self, value): self.value =
class NumberToken(object): def __init__(self, value): self.value =
value
class CharacterToken(object): def **init**\ (self, char): self.char =
char def **eq**\ (self, other): return isinstance(other, CharacterToken)
and self.char == other.char def **ne**\ (self, other): return not self
class CharacterToken(object): def __init__(self, char): self.char =
char def __eq__(self, other): return isinstance(other, CharacterToken)
and self.char == other.char def __ne__(self, other): return not self
== other
# Regular expressions that tokens and comments of our language.
@ -904,14 +904,14 @@ the if/then/else and for expressions:
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): return Constant.real(Type.double(), self.value)
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): if self.name in g_named_values: return
g_named_values[self.name] else: raise RuntimeError('Unknown variable
@ -920,7 +920,7 @@ the if/then/else and for expressions:
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right): self.operator = operator
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def CodeGen(self): left = self.left.CodeGen() right =
@ -944,7 +944,7 @@ the if/then/else and for expressions:
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args): self.callee = callee self.args =
def __init__(self, callee, args): self.callee = callee self.args =
args
def CodeGen(self): # Look up the name in the global module table. callee
@ -963,7 +963,7 @@ the if/then/else and for expressions:
# Expression class for if/then/else.
class IfExpressionNode(ExpressionNode):
def **init**\ (self, condition, then_branch, else_branch):
def __init__(self, condition, then_branch, else_branch):
self.condition = condition self.then_branch = then_branch
self.else_branch = else_branch
@ -1014,7 +1014,7 @@ the if/then/else and for expressions:
# Expression class for for/in.
class ForExpressionNode(ExpressionNode):
def **init**\ (self, loop_variable, start, end, step, body):
def __init__(self, loop_variable, start, end, step, body):
self.loop_variable = loop_variable self.start = start self.end = end
self.step = step self.body = body
@ -1095,7 +1095,7 @@ the if/then/else and for expressions:
# takes).
class PrototypeNode(object):
def **init**\ (self, name, args): self.name = name self.args = args
def __init__(self, name, args): self.name = name self.args = args
def CodeGen(self): # Make the function type, eg. double(double,double).
funct_type = Type.function( Type.double(), [Type.double()] \*
@ -1131,7 +1131,7 @@ the if/then/else and for expressions:
# This class represents a function definition itself.
class FunctionNode(object):
def **init**\ (self, prototype, body): self.prototype = prototype
def __init__(self, prototype, body): self.prototype = prototype
self.body = body
def CodeGen(self): # Clear scope. g_named_values.clear()
@ -1167,7 +1167,7 @@ the if/then/else and for expressions:
class Parser(object):
def **init**\ (self, tokens, binop_precedence): self.tokens = tokens
def __init__(self, tokens, binop_precedence): self.tokens = tokens
self.binop_precedence = binop_precedence self.Next()
# Provide a simple token buffer. Parser.current is the current token the
@ -1408,4 +1408,4 @@ the if/then/else and for expressions:
# Print out all of the generated code. print '', g_llvm_module
if **name** == '**main**\ ': main()
if **name** == '__main__': main()

View file

@ -113,7 +113,7 @@ keywords:
implicitly the number of arguments the function # takes), as well as if
it is an operator. class PrototypeNode(object):
def **init**\ (self, name, args, is_operator=False, precedence=0):
def __init__(self, name, args, is_operator=False, precedence=0):
self.name = name self.args = args self.is_operator = is_operator
self.precedence = precedence
@ -280,7 +280,7 @@ that, we need an AST node:
# Expression class for a unary operator. class
UnaryExpressionNode(ExpressionNode):
def **init**\ (self, operator, operand): self.operator = operator
def __init__(self, operator, operand): self.operator = operator
self.operand = operand
def CodeGen(self): ...
@ -725,15 +725,15 @@ the if/then/else and for expressions:
ForToken(object): pass class InToken(object): pass class
BinaryToken(object): pass class UnaryToken(object): pass
class IdentifierToken(object): def **init**\ (self, name): self.name =
class IdentifierToken(object): def __init__(self, name): self.name =
name
class NumberToken(object): def **init**\ (self, value): self.value =
class NumberToken(object): def __init__(self, value): self.value =
value
class CharacterToken(object): def **init**\ (self, char): self.char =
char def **eq**\ (self, other): return isinstance(other, CharacterToken)
and self.char == other.char def **ne**\ (self, other): return not self
class CharacterToken(object): def __init__(self, char): self.char =
char def __eq__(self, other): return isinstance(other, CharacterToken)
and self.char == other.char def __ne__(self, other): return not self
== other
# Regular expressions that tokens and comments of our language.
@ -798,14 +798,14 @@ the if/then/else and for expressions:
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): return Constant.real(Type.double(), self.value)
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): if self.name in g_named_values: return
g_named_values[self.name] else: raise RuntimeError('Unknown variable
@ -814,7 +814,7 @@ the if/then/else and for expressions:
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right): self.operator = operator
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def CodeGen(self): left = self.left.CodeGen() right =
@ -839,7 +839,7 @@ the if/then/else and for expressions:
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args): self.callee = callee self.args =
def __init__(self, callee, args): self.callee = callee self.args =
args
def CodeGen(self): # Look up the name in the global module table. callee
@ -858,7 +858,7 @@ the if/then/else and for expressions:
# Expression class for if/then/else.
class IfExpressionNode(ExpressionNode):
def **init**\ (self, condition, then_branch, else_branch):
def __init__(self, condition, then_branch, else_branch):
self.condition = condition self.then_branch = then_branch
self.else_branch = else_branch
@ -909,7 +909,7 @@ the if/then/else and for expressions:
# Expression class for for/in.
class ForExpressionNode(ExpressionNode):
def **init**\ (self, loop_variable, start, end, step, body):
def __init__(self, loop_variable, start, end, step, body):
self.loop_variable = loop_variable self.start = start self.end = end
self.step = step self.body = body
@ -988,7 +988,7 @@ the if/then/else and for expressions:
# Expression class for a unary operator.
class UnaryExpressionNode(ExpressionNode):
def **init**\ (self, operator, operand): self.operator = operator
def __init__(self, operator, operand): self.operator = operator
self.operand = operand
def CodeGen(self): operand = self.operand.CodeGen() function =
@ -1000,7 +1000,7 @@ the if/then/else and for expressions:
# takes), as well as if it is an operator.
class PrototypeNode(object):
def **init**\ (self, name, args, is_operator=False, precedence=0):
def __init__(self, name, args, is_operator=False, precedence=0):
self.name = name self.args = args self.is_operator = is_operator
self.precedence = precedence
@ -1042,7 +1042,7 @@ the if/then/else and for expressions:
# This class represents a function definition itself.
class FunctionNode(object):
def **init**\ (self, prototype, body): self.prototype = prototype
def __init__(self, prototype, body): self.prototype = prototype
self.body = body
def CodeGen(self): # Clear scope. g_named_values.clear()
@ -1085,7 +1085,7 @@ the if/then/else and for expressions:
class Parser(object):
def **init**\ (self, tokens): self.tokens = tokens self.Next()
def __init__(self, tokens): self.tokens = tokens self.Next()
# Provide a simple token buffer. Parser.current is the current token the
# parser is looking at. Parser.Next() reads another token from the lexer
@ -1354,4 +1354,4 @@ the if/then/else and for expressions:
# Print out all of the generated code. print '', g_llvm_module
if **name** == '**main**\ ': main()
if **name** == '__main__': main()

View file

@ -615,7 +615,7 @@ var/in, it looks like this:
# Expression class for var/in. class
VarExpressionNode(ExpressionNode):
def **init**\ (self, variables, body): self.variables = variables
def __init__(self, variables, body): self.variables = variables
self.body = body
def CodeGen(self): ...
@ -861,15 +861,15 @@ mutable variables and var/in support:
BinaryToken(object): pass class UnaryToken(object): pass class
VarToken(object): pass
class IdentifierToken(object): def **init**\ (self, name): self.name =
class IdentifierToken(object): def __init__(self, name): self.name =
name
class NumberToken(object): def **init**\ (self, value): self.value =
class NumberToken(object): def __init__(self, value): self.value =
value
class CharacterToken(object): def **init**\ (self, char): self.char =
char def **eq**\ (self, other): return isinstance(other, CharacterToken)
and self.char == other.char def **ne**\ (self, other): return not self
class CharacterToken(object): def __init__(self, char): self.char =
char def __eq__(self, other): return isinstance(other, CharacterToken)
and self.char == other.char def __ne__(self, other): return not self
== other
# Regular expressions that tokens and comments of our language.
@ -936,14 +936,14 @@ mutable variables and var/in support:
# Expression class for numeric literals like "1.0".
class NumberExpressionNode(ExpressionNode):
def **init**\ (self, value): self.value = value
def __init__(self, value): self.value = value
def CodeGen(self): return Constant.real(Type.double(), self.value)
# Expression class for referencing a variable, like "a".
class VariableExpressionNode(ExpressionNode):
def **init**\ (self, name): self.name = name
def __init__(self, name): self.name = name
def CodeGen(self): if self.name in g_named_values: return
g_llvm_builder.load(g_named_values[self.name], self.name) else:
@ -952,7 +952,7 @@ mutable variables and var/in support:
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def **init**\ (self, operator, left, right): self.operator = operator
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def CodeGen(self): # A special case for '=' because we don't want to
@ -994,7 +994,7 @@ mutable variables and var/in support:
# Expression class for function calls.
class CallExpressionNode(ExpressionNode):
def **init**\ (self, callee, args): self.callee = callee self.args =
def __init__(self, callee, args): self.callee = callee self.args =
args
def CodeGen(self): # Look up the name in the global module table. callee
@ -1013,7 +1013,7 @@ mutable variables and var/in support:
# Expression class for if/then/else.
class IfExpressionNode(ExpressionNode):
def **init**\ (self, condition, then_branch, else_branch):
def __init__(self, condition, then_branch, else_branch):
self.condition = condition self.then_branch = then_branch
self.else_branch = else_branch
@ -1064,7 +1064,7 @@ mutable variables and var/in support:
# Expression class for for/in.
class ForExpressionNode(ExpressionNode):
def **init**\ (self, loop_variable, start, end, step, body):
def __init__(self, loop_variable, start, end, step, body):
self.loop_variable = loop_variable self.start = start self.end = end
self.step = step self.body = body
@ -1146,7 +1146,7 @@ mutable variables and var/in support:
# Expression class for a unary operator.
class UnaryExpressionNode(ExpressionNode):
def **init**\ (self, operator, operand): self.operator = operator
def __init__(self, operator, operand): self.operator = operator
self.operand = operand
def CodeGen(self): operand = self.operand.CodeGen() function =
@ -1156,7 +1156,7 @@ mutable variables and var/in support:
# Expression class for var/in.
class VarExpressionNode(ExpressionNode):
def **init**\ (self, variables, body): self.variables = variables
def __init__(self, variables, body): self.variables = variables
self.body = body
def CodeGen(self): old_bindings = {} function =
@ -1204,7 +1204,7 @@ mutable variables and var/in support:
# takes), as well as if it is an operator.
class PrototypeNode(object):
def **init**\ (self, name, args, is_operator=False, precedence=0):
def __init__(self, name, args, is_operator=False, precedence=0):
self.name = name self.args = args self.is_operator = is_operator
self.precedence = precedence
@ -1251,7 +1251,7 @@ mutable variables and var/in support:
# This class represents a function definition itself.
class FunctionNode(object):
def **init**\ (self, prototype, body): self.prototype = prototype
def __init__(self, prototype, body): self.prototype = prototype
self.body = body
def CodeGen(self): # Clear scope. g_named_values.clear()
@ -1297,7 +1297,7 @@ mutable variables and var/in support:
class Parser(object):
def **init**\ (self, tokens): self.tokens = tokens self.Next()
def __init__(self, tokens): self.tokens = tokens self.Next()
# Provide a simple token buffer. Parser.current is the current token the
# parser is looking at. Parser.Next() reads another token from the lexer
@ -1608,4 +1608,4 @@ mutable variables and var/in support:
# Print out all of the generated code. print '', g_llvm_module
if **name** == '**main**\ ': main()
if **name** == '__main__': main()