Lines Matching refs:we

15 Kaleidoscope language. Once we have a parser, we'll define and build an
19 The parser we will build uses a combination of `Recursive Descent
24 the former for everything else). Before we get to parsing though, lets
34 Kaleidoscope, we have expressions, a prototype, and a function object.
45 subclass which we use for numeric literals. The important thing to note
50 Right now we only create the AST, so there are no useful functions on
53 we'll use in the basic form of the Kaleidoscope language:
74 For our basic language, these are all of the expression nodes we'll
76 Turing-complete; we'll fix that in a later installment. The two things
77 we need next are a way to talk about the interface to a function, and a
96 With this scaffolding, we can now talk about parsing expressions and
102 Now that we have an AST to build, we need to define the parser code to
103 build it. The idea here is that we want to parse something like "x+y"
123 With these basic types and exceptions, we can implement the first piece
130 process. For each production in our grammar, we'll define a function
134 arbitrary primary expression, we need to determine what sort of
135 expression it is. For numeric literals, we have:
167 1) It shows how we use the ``Stream.Error`` exception. When called, this
172 to indicate that they happened. In our parser, we use the camlp4
178 by calling ``Parser.parse_primary`` (we will soon see that
182 construction of AST nodes themselves. While we could do it this way, the
225 We finish up by raising an exception if we received a token we didn't
232 Now that basic expressions are handled, we need to handle binary
241 definitions from mathematics, we expect the later parse, because "\*"
248 recursion. To start with, we need a table of precedences:
270 For the basic form of Kaleidoscope, we will only support 4 binary
280 With the helper above defined, we can now start parsing binary
327 * consume it, otherwise we are done. *)
331 if is too low. Because we defined invalid tokens to have a precedence of
333 stream runs out of binary operators. If this check succeeds, we know
345 (* Okay, we know this is a binop. *)
354 Now that we parsed the left-hand side of an expression and one pair of
355 the RHS sequence, we have to decide which way the expression associates.
356 In particular, we could have "(a+b) binop unparsed" or "a + (b binop
357 unparsed)". To determine this, we look ahead at "binop" to determine its
369 to the precedence of our current operator, then we know that the
371 operator is "+" and the next operator is "+", we know that they have the
372 same precedence. In this case we'll create the AST node for "a+b", and
416 At this point, we know that the binary operator to the RHS of our
417 primary has higher precedence than the binop we are currently parsing.
418 As such, we know that any sequence of pairs whose operators are all
420 "RHS". To do this, we recursively invoke the ``Parser.parse_bin_rhs``
428 non-trivial lines), we correctly handle fully general binary expression
433 This wraps up handling of expressions. At this point, we can point the
436 we need to handle function definitions, etc.
478 In addition, we support 'extern' to declare functions like 'sin' and
488 Finally, we'll also let the user type in arbitrary top-level expressions
500 Now that we have all the pieces, let's build a little driver that will
501 let us actually *execute* this code we've built!
544 The most interesting part of this is that we ignore top-level
557 non-blank code), we fully defined our minimal language, including a
580 installment <OCamlLangImpl3.html>`_, we will describe how to generate
769 * consume it, otherwise we are done. *)
777 (* Okay, we know this is a binop. *)