From aa56f016f73063371431b8b2587538c79af97bd9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 15 Dec 2015 20:08:53 -0700 Subject: support addressof operator and struct pointer field access --- src/parser.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 572309bed7..3231cc0d2f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1153,12 +1153,13 @@ static PrefixOp tok_to_prefix_op(Token *token) { case TokenIdBang: return PrefixOpBoolNot; case TokenIdDash: return PrefixOpNegation; case TokenIdTilde: return PrefixOpBinNot; + case TokenIdAmpersand: return PrefixOpAddressOf; default: return PrefixOpInvalid; } } /* -PrefixOp : token(Not) | token(Dash) | token(Tilde) +PrefixOp : token(Not) | token(Dash) | token(Tilde) | (token(Ampersand) option(token(Const))) */ static PrefixOp ast_parse_prefix_op(ParseContext *pc, int *token_index, bool mandatory) { Token *token = &pc->tokens->at(*token_index); @@ -1171,6 +1172,15 @@ static PrefixOp ast_parse_prefix_op(ParseContext *pc, int *token_index, bool man } } *token_index += 1; + + if (result == PrefixOpAddressOf) { + Token *token = &pc->tokens->at(*token_index); + if (token->id == TokenIdKeywordConst) { + *token_index += 1; + result = PrefixOpConstAddressOf; + } + } + return result; } -- cgit v1.2.3