X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2Ftutorial%2FLangImpl2.html;h=292dd4e516cd68eaacfb8226ae62bb2e832026a4;hb=de86beae7d94ebb7f32940f34935d41d3416938a;hp=30215608a8ce53a109dec728c8dac10a178c7094;hpb=46c81814127e69e33ce60a461fbb02d6cd4657ac;p=oota-llvm.git diff --git a/docs/tutorial/LangImpl2.html b/docs/tutorial/LangImpl2.html index 30215608a8c..292dd4e516c 100644 --- a/docs/tutorial/LangImpl2.html +++ b/docs/tutorial/LangImpl2.html @@ -6,12 +6,12 @@
Welcome to Chapter 2 of the "Implementing a language with LLVM" tutorial. This chapter shows you how to use the lexer, built in @@ -61,10 +61,10 @@ Tree.
The AST for a program captures its behavior in such a way that it is easy for later stages of the compiler (e.g. code generation) to interpret. We basically @@ -84,7 +84,7 @@ public: class NumberExprAST : public ExprAST { double Val; public: - explicit NumberExprAST(double val) : Val(val) {} + NumberExprAST(double val) : Val(val) {} };
Now that we have an AST to build, we need to define the parser code to build it. The idea here is that we want to parse something like "x+y" (which is @@ -239,11 +239,10 @@ piece of our grammar: numeric literals.
We start with numeric literals, because they are the simplest to process. For each production in our grammar, we'll define a function which parses that @@ -333,9 +332,9 @@ static ExprAST *ParseIdentifierExpr() { ExprAST *Arg = ParseExpression(); if (!Arg) return 0; Args.push_back(Arg); - + if (CurTok == ')') break; - + if (CurTok != ',') return Error("Expected ')' or ',' in argument list"); getNextToken(); @@ -394,11 +393,10 @@ They are a bit more complex.
Binary expressions are significantly harder to parse because they are often ambiguous. For example, when given the string "x+y*z", the parser can choose @@ -617,10 +615,10 @@ handle function definitions, etc.
The next thing missing is handling of function prototypes. In Kaleidoscope, @@ -714,10 +712,10 @@ actually execute this code we've built!
The driver for this simply invokes all of the parsing pieces with a top-level dispatch loop. There isn't much interesting here, so I'll just include the @@ -753,10 +751,10 @@ type "4+5;", and the parser will know you are done.
With just under 400 lines of commented code (240 lines of non-comment, non-blank code), we fully defined our minimal language, including a lexer, @@ -790,10 +788,10 @@ Representation (IR) from the AST.
Here is the complete code listing for this and the previous chapter. @@ -803,10 +801,10 @@ course.) To build this, just compile with:
- # Compile - g++ -g -O3 toy.cpp - # Run - ./a.out +# Compile +clang++ -g -O3 toy.cpp +# Run +./a.out