Chris Lattner | c951dae | 2006-08-10 04:23:57 +0000 | [diff] [blame] | 1 | //===--- Expression.cpp - Expression Parsing ------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Expression parsing implementation. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
| 15 | #include "clang/Basic/Diagnostic.h" |
| 16 | using namespace llvm; |
| 17 | using namespace clang; |
| 18 | |
Chris Lattner | c5e0d4a | 2006-08-10 19:06:03 +0000 | [diff] [blame] | 19 | // C99 6.7.8 |
| 20 | void Parser::ParseInitializer() { |
| 21 | // FIXME: STUB. |
| 22 | ParseAssignmentExpression(); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | |
Chris Lattner | c951dae | 2006-08-10 04:23:57 +0000 | [diff] [blame] | 27 | Parser::ExprTy Parser::ParseExpression() { |
| 28 | if (Tok.getKind() == tok::numeric_constant) { |
| 29 | ConsumeToken(); |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | Diag(Tok, diag::err_parse_error); |
| 34 | return 0; |
| 35 | } |
| 36 | |
Chris Lattner | c5e0d4a | 2006-08-10 19:06:03 +0000 | [diff] [blame] | 37 | // Expr that doesn't include commas. |
| 38 | void Parser::ParseAssignmentExpression() { |
| 39 | ParseExpression(); |
| 40 | } |
| 41 | |
| 42 | /// primary-expression: |
| 43 | /// identifier |
| 44 | /// constant |
| 45 | /// string-literal |
| 46 | /// '(' expression ')' |
| 47 | |
Chris Lattner | c951dae | 2006-08-10 04:23:57 +0000 | [diff] [blame] | 48 | |
| 49 | /// ParseParenExpression - C99 c.5.1p5 |
| 50 | /// primary-expression: |
| 51 | /// '(' expression ')' |
| 52 | void Parser::ParseParenExpression() { |
| 53 | assert(Tok.getKind() == tok::l_paren && "Not a paren expr!"); |
| 54 | SourceLocation OpenLoc = Tok.getLocation(); |
| 55 | ConsumeParen(); |
| 56 | |
| 57 | ParseExpression(); |
| 58 | |
| 59 | if (Tok.getKind() == tok::r_paren) { |
| 60 | ConsumeParen(); |
| 61 | } else { |
| 62 | Diag(Tok, diag::err_expected_rparen); |
| 63 | Diag(OpenLoc, diag::err_matching); |
| 64 | } |
| 65 | } |