Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions frontends/parsers/p4/p4parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,16 @@ using namespace P4;
%type<IR::IndexedVector<IR::Declaration_ID>> identifierList
%type<IR::SelectCase*> selectCase
%type<IR::Vector<IR::SelectCase>> selectCaseList
%type<IR::Statement*> statement emptyStatement returnStatement
%type<IR::Statement*> statement parserStatement emptyStatement returnStatement
switchStatement exitStatement
assignmentOrMethodCallStatement conditionalStatement
assignmentOrMethodCallStatement conditionalStatement parserConditionalStatement
assignmentOrMethodCallStatementWithoutSemicolon
forStatement breakStatement continueStatement
%type<IR::BlockStatement*> blockStatement parserBlockStatement controlBody
optObjInitializer
%type<IR::StatOrDecl*> statementOrDeclaration parserStatement
%type<IR::StatOrDecl*> statementOrDeclaration parserStatementOrDeclaration
declOrAssignmentOrMethodCallStatement
%type<IR::IndexedVector<IR::StatOrDecl>> objDeclarations statOrDeclList parserStatements
%type<IR::IndexedVector<IR::StatOrDecl>> objDeclarations statOrDeclList parserStatOrDeclList
forInitStatements forInitStatementsNonEmpty
forUpdateStatements forUpdateStatementsNonEmpty
%type<IR::SwitchCase*> switchCase
Expand Down Expand Up @@ -859,29 +859,41 @@ parserStates

parserState
: optAnnotations STATE name { driver.structure->pushContainerType($3, false); }
"{" parserStatements transitionStatement "}" {
"{" parserStatOrDeclList transitionStatement "}" {
driver.structure->pop();
$$ = new IR::ParserState(@3, std::move($3), std::move($1), std::move($6), $7); }
;

parserStatements
: %empty { $$ = {}; }
| parserStatements parserStatement { ($$ = std::move($1)).push_back($2); $$.srcInfo = @1 + @2; }
;

parserStatement
: assignmentOrMethodCallStatement { $$ = $1; }
| emptyStatement { $$ = $1; }
| variableDeclaration { $$ = $1; }
| constantDeclaration { $$ = $1; }
| parserBlockStatement { $$ = $1; }
| conditionalStatement { $$ = $1; }
| parserConditionalStatement { $$ = $1; }
;

parserStatementOrDeclaration
: variableDeclaration { $$ = $1; }
| constantDeclaration { $$ = $1; }
| parserStatement { $$ = $1; }
;

parserStatOrDeclList
: %empty { $$ = {}; }
| parserStatOrDeclList parserStatementOrDeclaration { ($$ = std::move($1)).push_back($2);
$$.srcInfo = @1 + @2; }
;

parserBlockStatement
: optAnnotations "{" { driver.structure->pushNamespace(@2, false); }
parserStatements "}" { driver.structure->pop();
$$ = new IR::BlockStatement(@1+@5, std::move($1), std::move($4)); }
: optAnnotations "{" { driver.structure->pushNamespace(@2, false); }
parserStatOrDeclList "}" { driver.structure->pop();
$$ = new IR::BlockStatement(@1+@5, std::move($1), std::move($4)); }
;

parserConditionalStatement
: IF "(" expression ")" parserStatement %prec THEN
{ $$ = new IR::IfStatement(@1, $3, $5, nullptr); }
| IF "(" expression ")" parserStatement ELSE parserStatement %prec THEN
{ $$ = new IR::IfStatement(@1, $3, $5, $7); }
;

transitionStatement
Expand Down
Loading