Misc doc cleanup

This commit is contained in:
Maggie Mari 2012-08-17 14:34:51 -05:00
commit 8e00cd7e66
3 changed files with 154 additions and 145 deletions

View file

@ -160,7 +160,7 @@ The Lexer
When it comes to implementing a language, the first thing needed is the
ability to process a text file and recognize what it says. The
traditional way to do this is to use a
`lexer <http://en.wikipedia.org/wiki/Lexical_analysis>`_" (aka
`lexer <http://en.wikipedia.org/wiki/Lexical_analysis>`_ (aka
'scanner') to break the input up into "tokens". Each token returned by
the lexer includes a token type and potentially some metadata (e.g. the
numeric value of a number). First, we define the possibilities:
@ -243,10 +243,6 @@ ignoring whitespace between tokens:
string = string[1:]
continue
::
...

View file

@ -442,7 +442,6 @@ at this point. We'll fix this in `Chapter 5 <PythonLangImpl5.html>`_ :).
Once the insertion point is set up, we call the ``CodeGen`` method for
the root expression of the function. If no error happens, this emits
code to compute the expression into the entry block and returns the
@ -645,6 +644,8 @@ need to `download <../download.html>`_ and
Globals
-------
.. code-block:: python
# The LLVM module, which holds all the IR code.
g_llvm_module = Module.new('my cool jit')
@ -658,6 +659,8 @@ need to `download <../download.html>`_ and
Lexer
-----
.. code-block:: python
# The lexer yields one of these types for each token.
class EOFToken(object):
pass
@ -678,7 +681,8 @@ need to `download <../download.html>`_ and
class CharacterToken(object):
def __init__(self, char):
self.char = char def __eq__(self, other):
self.char = char
def __eq__(self, other):
return isinstance(other, CharacterToken)and self.char == other.char
def __ne__(self, other):
return not self == other
@ -728,6 +732,8 @@ need to `download <../download.html>`_ and
Abstract Syntax Tree (aka Parse Tree)
-------------------------------------
.. code-block:: python
# Base class for all expression nodes.
class ExpressionNode(object):
pass
@ -756,8 +762,10 @@ need to `download <../download.html>`_ and
# Expression class for a binary operator.
class BinaryOperatorExpressionNode(ExpressionNode):
def __init__(self, operator, left, right): self.operator = operator
self.left = left self.right = right
def __init__(self, operator, left, right):
self.operator = operator
self.left = left
self.right = right
def CodeGen(self):
left = self.left.CodeGen()
@ -869,6 +877,8 @@ need to `download <../download.html>`_ and
Parser
------
.. code-block:: python
class Parser(object):
def __init__(self, tokens, binop_precedence):
@ -877,13 +887,13 @@ need to `download <../download.html>`_ and
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
and # updates Parser.current with its results.
# parser is looking at. Parser.Next() reads another token from the lexer and
# updates Parser.current with its results.
def Next(self):
self.current = self.tokens.next()
# Gets the precedence of the current token, or -1 if the token is not a
binary # operator.
# Gets the precedence of the current token, or -1 if the token is not a binary
# operator.
def GetCurrentTokenPrecedence(self):
if isinstance(self.current, CharacterToken):
return self.binop_precedence.get(self.current.char, -1)
@ -1038,6 +1048,8 @@ need to `download <../download.html>`_ and
Main driver code.
-----------------
.. code-block:: python
def main():
# Install standard binary operators.
# 1 is lowest possible precedence. 40 is the highest.

View file

@ -400,9 +400,10 @@ example, we can create a C file with the following simple function:
.. code-block:: c
#include
#include <stdio.h>
double putchard(double x) { putchar((char)x); return 0; } {%
double putchard(double x) {
putchar((char)x); return 0; } {%
endhighlight %}
We can then compile this into a shared library with GCC: