diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-05-30 15:52:36 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-05-30 15:52:36 +0800 |
| commit | 30726a1872c92d40424d496fc52043ca452d935f (patch) | |
| tree | 86ce09251183ee544033ba8bfa9f51199aa58628 /Parser.y | |
| parent | 4c9d2d541c90968db2065260dc94c3be9e8adef9 (diff) | |
support for array access (partial)
Diffstat (limited to 'Parser.y')
| -rw-r--r-- | Parser.y | 50 |
1 files changed, 25 insertions, 25 deletions
@@ -228,7 +228,7 @@ l2_expression l3_expression : l4_operator l3_expression {$$=std::make_shared<pcc::UnaryExprNode>(ctx,$1,$2);} - | AT lvalue {$$=std::make_shared<pcc::GetAddressNode>(ctx, $2);} + | AT lvalue {$$=$2;} | standalone_expression {$$=$1;} ; @@ -239,6 +239,30 @@ standalone_expression | LPARENTHESIS expression RPARENTHESIS {$$=$2;} ; +lvalue + : IDENTIFIER {$$=std::make_shared<pcc::IdentifierNode>(ctx, $1);} + | lvalue LBRACKET expression RBRACKET {$$=std::make_shared<pcc::ArrayAccessNode>(ctx, $1, $3);} + | standalone_expression DOT IDENTIFIER + ; + +function_call + : IDENTIFIER LPARENTHESIS arguments RPARENTHESIS {$$=std::make_shared<pcc::FunctionCallNode>(ctx, $1, std::move($3));} + | IDENTIFIER LPARENTHESIS RPARENTHESIS {$$=std::make_shared<pcc::FunctionCallNode>(ctx, $1, std::list<std::shared_ptr<pcc::ExprNode>>());} + ; + +arguments + : arguments COMMA expression {$$=std::move($1); $$.push_back($3);} + | expression {$$.push_back($1);} + ; + +literal + : BOOLEAN_LITERAL {$$=std::make_shared<pcc::BooleanLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::BOOLEAN), $1);} + | CHAR_LITERAL {$$=std::make_shared<pcc::CharLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::CHAR), $1);} + | INTEGER_LITERAL {$$=std::make_shared<pcc::IntegerLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::INTEGER), $1);} + | REAL_LITERAL {$$=std::make_shared<pcc::RealLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::REAL), $1);} + | STRING_LITERAL {$$=std::make_shared<pcc::StringLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::STRING), $1);} + ; + l1_operator : LT {$$=pcc::BinaryOperator::LT;} | LE {$$=pcc::BinaryOperator::LE;} @@ -271,30 +295,6 @@ l4_operator | SUB {$$=pcc::UnaryOperator::NEG;} ; -lvalue - : IDENTIFIER {$$=std::make_shared<pcc::IdentifierNode>(ctx, $1);} - | standalone_expression LBRACKET expression RBRACKET {$$=std::make_shared<pcc::BinaryExprNode>(ctx, pcc::BinaryOperator::ARRAY_ACCESS, $1, $3);} - | standalone_expression DOT IDENTIFIER - ; - -function_call - : IDENTIFIER LPARENTHESIS arguments RPARENTHESIS {$$=std::make_shared<pcc::FunctionCallNode>(ctx, $1, std::move($3));} - | IDENTIFIER LPARENTHESIS RPARENTHESIS {$$=std::make_shared<pcc::FunctionCallNode>(ctx, $1, std::list<std::shared_ptr<pcc::ExprNode>>());} - ; - -arguments - : arguments COMMA expression {$$=std::move($1); $$.push_back($3);} - | expression {$$.push_back($1);} - ; - -literal - : BOOLEAN_LITERAL {$$=std::make_shared<pcc::BooleanLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::BOOLEAN), $1);} - | CHAR_LITERAL {$$=std::make_shared<pcc::CharLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::CHAR), $1);} - | INTEGER_LITERAL {$$=std::make_shared<pcc::IntegerLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::INTEGER), $1);} - | REAL_LITERAL {$$=std::make_shared<pcc::RealLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::REAL), $1);} - | STRING_LITERAL {$$=std::make_shared<pcc::StringLiteralNode>(ctx, ctx->GetTypeManager()->GetBuiltinType(BuiltinType::STRING), $1);} - ; - %% namespace pcc { |
