Skip to content

Commit

Permalink
Fix parser so that priority can be used in expressions (#4053)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dodd authored Jul 8, 2023
1 parent a12f066 commit 64683c9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions frontends/parsers/p4/p4parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ inline std::ostream& operator<<(std::ostream& out, const P4::Token& t) {
%type<IR::Expression*> expression lvalue keysetExpression selectExpression
stateExpression optInitializer initializer
simpleKeysetExpression transitionStatement switchLabel
p4rtControllerType reducedSimpleKeysetExpression optEntryPriority
p4rtControllerType reducedSimpleKeysetExpression entryPriority
nonBraceExpression
%type<ConstType*> baseType typeOrVoid specializedType headerStackType
typeRef tupleType typeArg realTypeArg namedType p4listType
Expand Down Expand Up @@ -473,12 +473,12 @@ nonTypeName
| STATE { $$ = new IR::ID(@1, "state"); }
| ENTRIES { $$ = new IR::ID(@1, "entries"); }
| TYPE { $$ = new IR::ID(@1, "type"); }
| PRIORITY { $$ = new IR::ID(@1, "priority"); }
;

name
: nonTypeName { $$ = $1; }
| LIST { $$ = new IR::ID(@1, "list"); }
| PRIORITY { $$ = new IR::ID(@1, "priority"); }
| TYPE_IDENTIFIER { $$ = new IR::ID(@1, $1); }
;

Expand Down Expand Up @@ -1337,7 +1337,7 @@ actionRef
;

entry
: optCONST optEntryPriority keysetExpression ":" actionRef optAnnotations ";"
: optCONST entryPriority keysetExpression ":" actionRef optAnnotations ";"
// below we set the position starting at @3 because optional
// fields generate weird position information.
{ if (auto l = $3->to<IR::ListExpression>())
Expand All @@ -1348,11 +1348,21 @@ entry
new IR::ListExpression(@3, le), $5, true);
}
}
| optCONST keysetExpression ":" actionRef optAnnotations ";"
// below we set the position starting at @2 because optional
// fields generate weird position information.
{ if (auto l = $2->to<IR::ListExpression>())
$$ = new IR::Entry(@2+@5, $5, $1.isConst, nullptr, l, $4, false);
else { // if not a tuple, make it a list of 1
IR::Vector<IR::Expression> le($2);
$$ = new IR::Entry(@2+@5, $5, $1.isConst, nullptr,
new IR::ListExpression(@2, le), $4, true);
}
}
;

optEntryPriority
: %empty { $$ = nullptr; }
| PRIORITY "=" INTEGER ":" { $$ = new IR::Constant(parseConstantChecked(@3, $3)); }
entryPriority
: PRIORITY "=" INTEGER ":" { $$ = new IR::Constant(parseConstantChecked(@3, $3)); }
| PRIORITY "=" "(" expression ")" ":" { $$ = $4; }
;

Expand Down

0 comments on commit 64683c9

Please sign in to comment.