44e93e4cda
Ultimately, the goal is to completely separate the compilation from the runtime to make it possible to have the interpreter/evaluator be "just another" entity that can perform meaningful work when given a parsed GP4 program. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
77 lines
1.9 KiB
Swift
77 lines
1.9 KiB
Swift
// p4rse, Copyright 2026, Will Hawkins
|
|
//
|
|
// This file is part of p4rse.
|
|
//
|
|
// This file is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
import Common
|
|
|
|
public struct Statement {}
|
|
|
|
public struct VariableDeclarationStatement {
|
|
public var initializer: P4Expression
|
|
public var identifier: TypedIdentifier
|
|
public init(identifier: TypedIdentifier, withInitializer initializer: P4Expression) {
|
|
self.identifier = identifier
|
|
self.initializer = initializer
|
|
}
|
|
}
|
|
|
|
public struct ConditionalStatement {
|
|
public var condition: P4Expression
|
|
public var thenn: P4Statement
|
|
public var elss: P4Statement?
|
|
|
|
public init(condition: P4Expression, withThen thenn: P4Statement) {
|
|
self.condition = condition
|
|
self.thenn = thenn
|
|
self.elss = .none
|
|
}
|
|
|
|
public init(
|
|
condition: P4Expression, withThen thenn: P4Statement,
|
|
andElse elss: P4Statement
|
|
) {
|
|
self.condition = condition
|
|
self.thenn = thenn
|
|
self.elss = elss
|
|
}
|
|
}
|
|
|
|
public struct BlockStatement {
|
|
public var statements: [P4Statement]
|
|
|
|
public init(_ statements: [P4Statement]) {
|
|
self.statements = statements
|
|
}
|
|
|
|
}
|
|
|
|
public struct ReturnStatement {
|
|
public let value: P4Expression
|
|
|
|
public init(_ value: P4Expression) {
|
|
self.value = value
|
|
}
|
|
}
|
|
|
|
public struct ApplyStatement {
|
|
public let body: BlockStatement?
|
|
|
|
public init() { self.body = .none }
|
|
public init(_ body: BlockStatement) {
|
|
self.body = body
|
|
}
|
|
}
|