From 554f80ac5d01eb0ac218cf12540cd427763505a4 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Thu, 26 Mar 2015 15:19:07 +0100 Subject: [PATCH] Keeping track of locations in parser. --- src/Monicelli.ypp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Monicelli.ypp b/src/Monicelli.ypp index 408078a..9068d07 100644 --- a/src/Monicelli.ypp +++ b/src/Monicelli.ypp @@ -126,9 +126,10 @@ %type assign_stmt %type loop_stmt %type return_stmt -%type expression maybe_expression simple_expression var_init +%type expression maybe_expression simple_expression expression_inner +%type var_init %type call_arglist call_args -%type semi_expression +%type semi_expression semi_expression_inner %type variable %type numeric %type pointer @@ -196,6 +197,7 @@ statements: } | statements statement { if ($2 != nullptr) { + $2->setLocation(@2); $1->push_back($2); } $$ = $1; @@ -268,6 +270,7 @@ loop_stmt: ; branch_stmt: BRANCH_CONDITION variable BRANCH_BEGIN branch_body BRANCH_END { + $2->setLocation(@2); $$ = new Branch($2, $4); } ; @@ -329,6 +332,12 @@ assert_stmt: } ; expression: + expression_inner { + $1->setLocation(@1); + $$ = $1; + } +; +expression_inner: simple_expression { $$ = $1; } @@ -364,6 +373,12 @@ expression: } ; semi_expression: + semi_expression_inner { + $1->setLocation(@1); + $$ = $1; + } +; +semi_expression_inner: expression { $$ = new SemiExpEq($1); }