Merge pull request #33 from jszakmeister/fix-bugs-in-tutorial
Fix bugs in tutorial
This commit is contained in:
commit
d12b145bee
5 changed files with 10 additions and 10 deletions
|
|
@ -115,13 +115,13 @@ following simple example computes `Fibonacci
|
||||||
numbers <http://en.wikipedia.org/wiki/Fibonacci_number>`_:
|
numbers <http://en.wikipedia.org/wiki/Fibonacci_number>`_:
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: text
|
||||||
|
|
||||||
# Compute the x'th fibonacci number.
|
# Compute the x'th fibonacci number.
|
||||||
def fib(x):
|
def fib(x)
|
||||||
if x < 3:
|
if x < 3
|
||||||
return 1
|
return 1
|
||||||
else:
|
else
|
||||||
return fib(x-1)+fib(x-2)
|
return fib(x-1)+fib(x-2)
|
||||||
|
|
||||||
# This expression will compute the 40th number.
|
# This expression will compute the 40th number.
|
||||||
|
|
@ -226,7 +226,7 @@ the line.
|
||||||
|
|
||||||
# Regular expressions that tokens and comments of our language.
|
# Regular expressions that tokens and comments of our language.
|
||||||
REGEX_NUMBER = re.compile('[0-9]+(?:.[0-9]+)?')
|
REGEX_NUMBER = re.compile('[0-9]+(?:.[0-9]+)?')
|
||||||
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9]\ *')
|
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9]*')
|
||||||
REGEX_COMMENT = re.compile('#.*')
|
REGEX_COMMENT = re.compile('#.*')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -772,7 +772,7 @@ Lexer
|
||||||
|
|
||||||
# Regular expressions that tokens and comments of our language.
|
# Regular expressions that tokens and comments of our language.
|
||||||
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
||||||
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9] *')
|
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9]*')
|
||||||
REGEX_COMMENT = re.compile('#.*')
|
REGEX_COMMENT = re.compile('#.*')
|
||||||
|
|
||||||
def Tokenize(string):
|
def Tokenize(string):
|
||||||
|
|
@ -811,7 +811,7 @@ Lexer
|
||||||
yield CharacterToken(string[0])
|
yield CharacterToken(string[0])
|
||||||
string = string[1:]
|
string = string[1:]
|
||||||
|
|
||||||
yield EOFToken()
|
yield EOFToken()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1058,7 +1058,7 @@ Main driver code.
|
||||||
'+': 20,
|
'+': 20,
|
||||||
'-': 20,
|
'-': 20,
|
||||||
'*': 40
|
'*': 40
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run the main "interpreter loop".
|
# Run the main "interpreter loop".
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -847,7 +847,7 @@ Lexer
|
||||||
|
|
||||||
# Regular expressions that tokens and comments of our language.
|
# Regular expressions that tokens and comments of our language.
|
||||||
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
||||||
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9] *')
|
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9]*')
|
||||||
REGEX_COMMENT = re.compile('#.*')
|
REGEX_COMMENT = re.compile('#.*')
|
||||||
|
|
||||||
def Tokenize(string):
|
def Tokenize(string):
|
||||||
|
|
|
||||||
|
|
@ -1000,7 +1000,7 @@ Lexer
|
||||||
|
|
||||||
# Regular expressions that tokens and comments of our language.
|
# Regular expressions that tokens and comments of our language.
|
||||||
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
REGEX_NUMBER = re.compile('[0-9]+(?:\.[0-9]+)?')
|
||||||
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9] *')
|
REGEX_IDENTIFIER = re.compile('[a-zA-Z][a-zA-Z0-9] *')
|
||||||
REGEX_COMMENT = re.compile('#.*')
|
REGEX_COMMENT = re.compile('#.*')
|
||||||
|
|
||||||
def Tokenize(string):
|
def Tokenize(string):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue