7c35b2b6e5
Add support for <, <=, >, >=, && and ||. Also, add support for grouping (with ( and )) in expressions. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
304 lines
4.9 KiB
Plaintext
304 lines
4.9 KiB
Plaintext
=========================
|
|
Simple boolean Equality
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
if (true == false) {
|
|
}
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(simple_expression
|
|
(binaryOperatorExpression
|
|
(binaryEqualOperatorExpression
|
|
(expression
|
|
(simple_expression
|
|
(booleanLiteralExpression
|
|
(true)
|
|
)
|
|
)
|
|
)
|
|
(double_equal)
|
|
(expression
|
|
(simple_expression
|
|
(booleanLiteralExpression
|
|
(false)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(statement
|
|
(blockStatement)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
=========================
|
|
Simple Integer Equality
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
if (1 == 2) {
|
|
}
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(conditionalStatement
|
|
(if)
|
|
(expression
|
|
(simple_expression
|
|
(binaryOperatorExpression
|
|
(binaryEqualOperatorExpression
|
|
(expression
|
|
(simple_expression
|
|
(integer)
|
|
)
|
|
)
|
|
(double_equal)
|
|
(expression
|
|
(simple_expression
|
|
(integer)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(statement
|
|
(blockStatement)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
=========================
|
|
Simple Array Access
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
undeclared_array[5];
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(expressionStatement
|
|
(expression
|
|
(simple_expression
|
|
(arrayAccessExpression
|
|
(expression
|
|
(simple_expression
|
|
(identifier)
|
|
)
|
|
)
|
|
(open_bracket)
|
|
(expression
|
|
(simple_expression
|
|
(integer)
|
|
)
|
|
)
|
|
(close_bracket)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
=========================
|
|
Simple Struct Access
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
abc.xyz;
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(expressionStatement
|
|
(expression
|
|
(simple_expression
|
|
(fieldAccessExpression
|
|
(expression
|
|
(simple_expression
|
|
(identifier)
|
|
)
|
|
)
|
|
(field_access)
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
=========================
|
|
Nested Struct Access
|
|
=========================
|
|
parser simple() {
|
|
state start {
|
|
abc.cde.xyz;
|
|
transition accept;
|
|
}
|
|
};
|
|
|
|
---
|
|
(p4program
|
|
(declaration
|
|
(parserDeclaration
|
|
(parserType
|
|
(parser)
|
|
(identifier)
|
|
)
|
|
(parserStates
|
|
(parserState
|
|
(state)
|
|
(identifier)
|
|
(parserStatements
|
|
(parserStatement
|
|
(expressionStatement
|
|
(expression
|
|
(simple_expression
|
|
(fieldAccessExpression
|
|
(expression
|
|
(simple_expression
|
|
(fieldAccessExpression
|
|
(expression
|
|
(simple_expression
|
|
(identifier)
|
|
)
|
|
)
|
|
(field_access)
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
(field_access)
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(parserTransitionStatement
|
|
(transition)
|
|
(transitionSelectionExpression
|
|
(identifier)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|