Lines Matching +full:- +full:- +full:user +full:- +full:token

20 `Operator-Precedence
21 Parsing <http://en.wikipedia.org/wiki/Operator-precedence_parser>`_ to
36 .. code-block:: c++
38 /// ExprAST - Base class for all expression nodes.
44 /// NumberExprAST - Expression class for numeric literals like "1.0".
64 .. code-block:: c++
66 /// VariableExprAST - Expression class for referencing a variable, like "a".
74 /// BinaryExprAST - Expression class for a binary operator.
85 /// CallExprAST - Expression class for function calls.
96 This is all (intentionally) rather straight-forward: variables capture
106 Turing-complete; we'll fix that in a later installment. The two things
110 .. code-block:: c++
112 /// PrototypeAST - This class represents the "prototype" for a function,
126 /// FunctionAST - This class represents a function definition itself.
154 .. code-block:: c++
163 .. code-block:: c++
165 /// CurTok/getNextToken - Provide a simple token buffer. CurTok is the current
166 /// token the parser is looking at. getNextToken reads another token from the
173 This implements a simple token buffer around the lexer. This allows us
174 to look one token ahead at what the lexer is returning. Every function
175 in our parser will assume that CurTok is the current token that needs to
178 .. code-block:: c++
181 /// LogError* - These are little helper functions for error handling.
193 best and is not particular user-friendly, but it will be enough for our
207 .. code-block:: c++
217 token is a ``tok_number`` token. It takes the current number value,
218 creates a ``NumberExprAST`` node, advances the lexer to the next token,
223 production and returns the lexer buffer with the next token (which is
228 .. code-block:: c++
247 expects that the current token is a '(' token, but after parsing the
249 if the user types in "(4 x" instead of "(4)", the parser should emit an
266 .. code-block:: c++
305 to be called if the current token is a ``tok_identifier`` token). It
307 that it uses *look-ahead* to determine if the current identifier is a
309 It handles this by checking to see if the token after the identifier is
310 a '(' token, constructing either a ``VariableExprAST`` or
313 Now that we have all of our simple expression-parsing logic in place, we
317 tutorial <LangImpl06.html#user-defined-unary-operators>`_. In order to parse an arbitrary
320 .. code-block:: c++
329 return LogError("unknown token when expecting an expression");
341 look-ahead to determine which sort of expression is being inspected, and
357 to use `Operator-Precedence
358 Parsing <http://en.wikipedia.org/wiki/Operator-precedence_parser>`_.
362 .. code-block:: c++
364 /// BinopPrecedence - This holds the precedence for each binary operator that is
368 /// GetTokPrecedence - Get the precedence of the pending binary operator token.
371 return -1;
375 if (TokPrec <= 0) return -1;
384 BinopPrecedence['-'] = 20;
392 the current token, or -1 if the token is not a binary operator. Having a
396 ``GetTokPrecedence`` function. (Or just use a fixed-size array).
412 .. code-block:: c++
431 current token is "+".
440 .. code-block:: c++
455 This code gets the precedence of the current token and checks to see if
457 -1, this check implicitly knows that the pair-stream ends when the token
459 that the token is a binary operator and that it will be included in this
462 .. code-block:: c++
477 Now that we parsed the left-hand side of an expression and one pair of
484 .. code-block:: c++
498 .. code-block:: c++
510 next iteration of the loop, with "+" as the current token. The code
523 .. code-block:: c++
551 non-trivial lines), we correctly handle fully general binary expression
557 parser at an arbitrary token stream and build an expression from it,
558 stopping at the first token that is not part of the expression. Next up
567 straight-forward and not very interesting (once you've survived
570 .. code-block:: c++
600 .. code-block:: c++
614 'cos' as well as to support forward declaration of user functions. These
617 .. code-block:: c++
625 Finally, we'll also let the user type in arbitrary top-level expressions
629 .. code-block:: c++
648 top-level dispatch loop. There isn't much interesting here, so I'll just
649 include the top-level loop. See `below <#full-code-listing>`_ for full code in the
650 "Top-Level Parsing" section.
652 .. code-block:: c++
661 case ';': // ignore top-level semicolons.
677 The most interesting part of this is that we ignore top-level
681 could type "def foo..." in which case 4+5 is the end of a top-level
683 the expression. Having top-level semicolons allows you to type "4+5;",
689 With just under 400 lines of commented code (240 lines of non-comment,
690 non-blank code), we fully defined our minimal language, including a
695 .. code-block:: bash
702 Parsed a top-level expr
705 Error: unknown token when expecting an expression
721 .. code-block:: bash
724 clang++ -g -O3 toy.cpp