a2335a01ed
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
383 lines
5.9 KiB
Plaintext
383 lines
5.9 KiB
Plaintext
=========================
|
|
Simple If Statement (No Else)
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
if (true) {
|
|
};
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(true)
|
|
)
|
|
(statement
|
|
(blockStatement)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
|
|
=========================
|
|
Simple If Statement (Else)
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
if (true) {
|
|
} else {
|
|
};
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(true)
|
|
)
|
|
(statement
|
|
(blockStatement)
|
|
)
|
|
(else)
|
|
(statement
|
|
(blockStatement)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
|
|
=========================
|
|
Simple Assignment Statement (To Identifier)
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
string l = "testing";
|
|
l = "five";
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserLocalElements
|
|
(parserLocalElement
|
|
(variableDeclaration
|
|
(typeRef
|
|
(baseType
|
|
(string)
|
|
)
|
|
)
|
|
(identifier)
|
|
(assignment)
|
|
(expression
|
|
(string_literal)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserStatements
|
|
(parserStatement
|
|
(assignmentStatement
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(assignment)
|
|
(expression
|
|
(string_literal)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
|
|
=========================
|
|
Simple Conditional Statement
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
bool x = true;
|
|
if (x) {
|
|
x = false;
|
|
};
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserLocalElements
|
|
(parserLocalElement
|
|
(variableDeclaration
|
|
(typeRef
|
|
(baseType
|
|
(bool)
|
|
)
|
|
)
|
|
(identifier)
|
|
(assignment)
|
|
(expression
|
|
(true)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(statement
|
|
(blockStatement
|
|
(statements
|
|
(statement
|
|
(assignmentStatement
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(assignment)
|
|
(expression
|
|
(false)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
|
|
=========================
|
|
Simple Conditional Statement (with else)
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
bool x = true;
|
|
int y = 0;
|
|
if (x) {
|
|
y = 1;
|
|
} else {
|
|
y = 2;
|
|
};
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserLocalElements
|
|
(parserLocalElement
|
|
(variableDeclaration
|
|
(typeRef
|
|
(baseType
|
|
(bool)
|
|
)
|
|
)
|
|
(identifier)
|
|
(assignment)
|
|
(expression
|
|
(true)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
(parserLocalElement
|
|
(variableDeclaration
|
|
(typeRef
|
|
(baseType
|
|
(int)
|
|
)
|
|
)
|
|
(identifier)
|
|
(assignment)
|
|
(expression
|
|
(integer)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(statement
|
|
(blockStatement
|
|
(statements
|
|
(statement
|
|
(assignmentStatement
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(assignment)
|
|
(expression
|
|
(integer)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
(else)
|
|
(statement
|
|
(blockStatement
|
|
(statements
|
|
(statement
|
|
(assignmentStatement
|
|
(expression
|
|
(identifier)
|
|
)
|
|
(assignment)
|
|
(expression
|
|
(integer)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(semicolon)
|
|
)
|
|
|