Corrected special character formatting.
This commit is contained in:
parent
a5c892de72
commit
538fd76b1f
6 changed files with 92 additions and 92 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue