blob: bfecef09aa3db92102e9e0d1d14ae96bde7ed35f [file] [log] [blame]
Chris Lattnerc951dae2006-08-10 04:23:57 +00001//===--- 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"
16using namespace llvm;
17using namespace clang;
18
Chris Lattnerc5e0d4a2006-08-10 19:06:03 +000019// C99 6.7.8
20void Parser::ParseInitializer() {
21 // FIXME: STUB.
22 ParseAssignmentExpression();
23}
24
25
26
Chris Lattnerc951dae2006-08-10 04:23:57 +000027Parser::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 Lattnerc5e0d4a2006-08-10 19:06:03 +000037// Expr that doesn't include commas.
38void Parser::ParseAssignmentExpression() {
39 ParseExpression();
40}
41
42/// primary-expression:
43/// identifier
44/// constant
45/// string-literal
46/// '(' expression ')'
47
Chris Lattnerc951dae2006-08-10 04:23:57 +000048
49/// ParseParenExpression - C99 c.5.1p5
50/// primary-expression:
51/// '(' expression ')'
52void 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}