Removed extraneous slashes.

This commit is contained in:
Maggie Mari 2012-08-19 12:18:26 -05:00
commit 391a121d6d
3 changed files with 18 additions and 18 deletions

View file

@ -1375,7 +1375,7 @@ Parser
return ForExpressionNode(loop_variable, start, end, step, body) return ForExpressionNode(loop_variable, start, end, step, body)
# primary ::= identifierexpr \| numberexpr \| parenexpr \| ifexpr \| # primary ::= identifierexpr | numberexpr | parenexpr | ifexpr |
forexpr def ParsePrimary(self): if isinstance(self.current, forexpr def ParsePrimary(self): if isinstance(self.current,
IdentifierToken): return self.ParseIdentifierExpr() elif IdentifierToken): return self.ParseIdentifierExpr() elif
isinstance(self.current, NumberToken): return self.ParseNumberExpr() isinstance(self.current, NumberToken): return self.ParseNumberExpr()

View file

@ -60,10 +60,10 @@ binary operators. An example of this is:
def binary> 10 (LHS RHS) RHS < LHS def binary> 10 (LHS RHS) RHS < LHS
# Binary "logical or", (note that it does not "short circuit"). # Binary "logical or", (note that it does not "short circuit").
def binary\| 5 (LHS RHS) if LHS then 1 else if RHS then 1 else 0 def binary| 5 (LHS RHS) if LHS then 1 else if RHS then 1 else 0
# Define = with slightly lower precedence than relationals. # Define = with slightly lower precedence than relationals.
def binary= 9 (LHS RHS) !(LHS < RHS \| LHS > RHS) def binary= 9 (LHS RHS) !(LHS < RHS | LHS > RHS)
@ -101,7 +101,7 @@ keywords:
any new AST or parser support. any new AST or parser support.
On the other hand, we have to be able to represent the definitions of On the other hand, we have to be able to represent the definitions of
these new operators, in the "def binary\| 5" part of the function these new operators, in the "def binary| 5" part of the function
definition. In our grammar so far, the "name" for the function definition. In our grammar so far, the "name" for the function
definition is parsed as the "prototype" production and into the definition is parsed as the "prototype" production and into the
``PrototypeNode``. To represent our new user-defined operators as ``PrototypeNode``. To represent our new user-defined operators as
@ -294,7 +294,7 @@ simple: we'll add a new function to do it:
.. code-block:: python .. code-block:: python
# unary ::= primary \| unary_operator unary def # unary ::= primary | unary_operator unary def
ParseUnary(self): # If the current token is not an operator, it must be ParseUnary(self): # If the current token is not an operator, it must be
a primary expression. if (not isinstance(self.current, CharacterToken) a primary expression. if (not isinstance(self.current, CharacterToken)
or self.current in [CharacterToken('('), CharacterToken(',')]): return or self.current in [CharacterToken('('), CharacterToken(',')]): return
@ -419,13 +419,13 @@ We can also define a bunch of other "primitive" operations, such as:
def binary> 10 (LHS RHS) RHS < LHS def binary> 10 (LHS RHS) RHS < LHS
# Binary logical or, which does not short circuit. # Binary logical or, which does not short circuit.
def binary\| 5 (LHS RHS) if LHS then 1 else if RHS then 1 else 0 def binary| 5 (LHS RHS) if LHS then 1 else if RHS then 1 else 0
# Binary logical and, which does not short circuit. # Binary logical and, which does not short circuit.
def binary& 6 (LHS RHS) if !LHS then 0 else !!RHS def binary& 6 (LHS RHS) if !LHS then 0 else !!RHS
# Define = with slightly lower precedence than relationals. # Define = with slightly lower precedence than relationals.
def binary = 9 (LHS RHS) !(LHS < RHS \| LHS > RHS) def binary = 9 (LHS RHS) !(LHS < RHS | LHS > RHS)
@ -454,7 +454,7 @@ denser the character:
# determine whether the specific location # determine whether the specific location
diverges. # Solve for z = z^2 + c in the complex plane. def diverges. # Solve for z = z^2 + c in the complex plane. def
mandelconverger(real imag iters creal cimag) if iters > 255 \| mandelconverger(real imag iters creal cimag) if iters > 255 |
(real\ *real + imag*\ imag > 4) then iters else (real\ *real + imag*\ imag > 4) then iters else
mandelconverger(real\ *real - imag*\ imag + creal, 2\ *real*\ imag + mandelconverger(real\ *real - imag*\ imag + creal, 2\ *real*\ imag +
cimag, iters+1, creal, cimag) cimag, iters+1, creal, cimag)
@ -1095,7 +1095,7 @@ the if/then/else and for expressions:
isinstance(self.current, CharacterToken): return isinstance(self.current, CharacterToken): return
g_binop_precedence.get(self.current.char, -1) else: return -1 g_binop_precedence.get(self.current.char, -1) else: return -1
# identifierexpr ::= identifier \| identifier '(' expression\* ')' def # identifierexpr ::= identifier | identifier '(' expression\* ')' def
ParseIdentifierExpr(self): identifier_name = self.current.name ParseIdentifierExpr(self): identifier_name = self.current.name
self.Next() # eat identifier. self.Next() # eat identifier.
@ -1196,7 +1196,7 @@ the if/then/else and for expressions:
return ForExpressionNode(loop_variable, start, end, step, body) return ForExpressionNode(loop_variable, start, end, step, body)
# primary ::= identifierexpr \| numberexpr \| parenexpr \| ifexpr \| # primary ::= identifierexpr | numberexpr | parenexpr | ifexpr |
forexpr def ParsePrimary(self): if isinstance(self.current, forexpr def ParsePrimary(self): if isinstance(self.current,
IdentifierToken): return self.ParseIdentifierExpr() elif IdentifierToken): return self.ParseIdentifierExpr() elif
isinstance(self.current, NumberToken): return self.ParseNumberExpr() isinstance(self.current, NumberToken): return self.ParseNumberExpr()
@ -1205,7 +1205,7 @@ the if/then/else and for expressions:
self.current == CharacterToken('('): return self.ParseParenExpr() else: self.current == CharacterToken('('): return self.ParseParenExpr() else:
raise RuntimeError('Unknown token when expecting an expression.') raise RuntimeError('Unknown token when expecting an expression.')
# unary ::= primary \| unary_operator unary def ParseUnary(self): # If # unary ::= primary | unary_operator unary def ParseUnary(self): # If
the current token is not an operator, it must be a primary expression. the current token is not an operator, it must be a primary expression.
if (not isinstance(self.current, CharacterToken) or self.current in if (not isinstance(self.current, CharacterToken) or self.current in
[CharacterToken('('), CharacterToken(',')]): return self.ParsePrimary() [CharacterToken('('), CharacterToken(',')]): return self.ParsePrimary()

View file

@ -181,7 +181,7 @@ using a PHI node:
into SSA registers, inserting Phi nodes as appropriate. If you run this into SSA registers, inserting Phi nodes as appropriate. If you run this
example through the pass, for example, you'll get: example through the pass, for example, you'll get:
$ llvm-as < example.ll \| opt -mem2reg \| llvm-dis $ llvm-as < example.ll | opt -mem2reg | llvm-dis
@ -628,8 +628,8 @@ do is add it as a primary expression:
.. code-block:: python .. code-block:: python
# primary ::= # dentifierexpr \| numberexpr \| # primary ::= # dentifierexpr | numberexpr |
parenexpr \| ifexpr \| forexpr \| varexpr def ParsePrimary(self): if parenexpr | ifexpr | forexpr | varexpr def ParsePrimary(self): if
isinstance(self.current, IdentifierToken): return isinstance(self.current, IdentifierToken): return
self.ParseIdentifierExpr() elif isinstance(self.current, NumberToken): self.ParseIdentifierExpr() elif isinstance(self.current, NumberToken):
return self.ParseNumberExpr() elif isinstance(self.current, IfToken): return self.ParseNumberExpr() elif isinstance(self.current, IfToken):
@ -1304,7 +1304,7 @@ mutable variables and var/in support:
isinstance(self.current, CharacterToken): return isinstance(self.current, CharacterToken): return
g_binop_precedence.get(self.current.char, -1) else: return -1 g_binop_precedence.get(self.current.char, -1) else: return -1
# identifierexpr ::= identifier \| identifier '(' expression\* ')' def # identifierexpr ::= identifier | identifier '(' expression\* ')' def
ParseIdentifierExpr(self): identifier_name = self.current.name ParseIdentifierExpr(self): identifier_name = self.current.name
self.Next() # eat identifier. self.Next() # eat identifier.
@ -1444,8 +1444,8 @@ mutable variables and var/in support:
return VarExpressionNode(variables, body) return VarExpressionNode(variables, body)
# primary ::= # dentifierexpr \| numberexpr \| parenexpr \| ifexpr \| # primary ::= # dentifierexpr | numberexpr | parenexpr | ifexpr |
forexpr \| varexpr def ParsePrimary(self): if isinstance(self.current, forexpr | varexpr def ParsePrimary(self): if isinstance(self.current,
IdentifierToken): return self.ParseIdentifierExpr() elif IdentifierToken): return self.ParseIdentifierExpr() elif
isinstance(self.current, NumberToken): return self.ParseNumberExpr() isinstance(self.current, NumberToken): return self.ParseNumberExpr()
elif isinstance(self.current, IfToken): return self.ParseIfExpr() elif elif isinstance(self.current, IfToken): return self.ParseIfExpr() elif
@ -1454,7 +1454,7 @@ mutable variables and var/in support:
self.current == CharacterToken('('): return self.ParseParenExpr() else: self.current == CharacterToken('('): return self.ParseParenExpr() else:
raise RuntimeError('Unknown token when expecting an expression.') raise RuntimeError('Unknown token when expecting an expression.')
# unary ::= primary \| unary_operator unary def ParseUnary(self): # If # unary ::= primary | unary_operator unary def ParseUnary(self): # If
the current token is not an operator, it must be a primary expression. the current token is not an operator, it must be a primary expression.
if (not isinstance(self.current, CharacterToken) or self.current in if (not isinstance(self.current, CharacterToken) or self.current in
[CharacterToken('('), CharacterToken(',')]): return self.ParsePrimary() [CharacterToken('('), CharacterToken(',')]): return self.ParsePrimary()