Work in progress
This commit is contained in:
196
src/ast.rs
196
src/ast.rs
@@ -1,76 +1,150 @@
|
||||
#[derive(Eq, Hash, PartialEq)]
|
||||
// Operators
|
||||
|
||||
pub enum BinaryOperator
|
||||
{
|
||||
Addition,
|
||||
Subtraction,
|
||||
Multiplication,
|
||||
Division,
|
||||
Modulo,
|
||||
Exponentiation,
|
||||
}
|
||||
|
||||
pub enum ComparisonOperator
|
||||
{
|
||||
Greater,
|
||||
Less,
|
||||
LessOrEqual,
|
||||
GreaterOrEqual,
|
||||
NotEqual,
|
||||
Equal,
|
||||
}
|
||||
|
||||
pub enum UnaryOperator
|
||||
{
|
||||
AbsoluteValue,
|
||||
Negation,
|
||||
}
|
||||
|
||||
// Primitives
|
||||
|
||||
pub struct FunctionDeclaration
|
||||
{
|
||||
pub name: String,
|
||||
pub arity: usize,
|
||||
}
|
||||
|
||||
pub struct PredicateDeclaration
|
||||
{
|
||||
pub name: String,
|
||||
pub arity: usize,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct Predicate
|
||||
{
|
||||
pub declaration: PredicateDeclaration,
|
||||
pub arguments: Vec<Term>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct Exists
|
||||
{
|
||||
pub parameters: Vec<VariableDeclaration>,
|
||||
pub argument: Box<Formula>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct ForAll
|
||||
{
|
||||
pub parameters: Vec<VariableDeclaration>,
|
||||
pub argument: Box<Formula>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Formula
|
||||
{
|
||||
Exists(Exists),
|
||||
ForAll(ForAll),
|
||||
Not(Box<Formula>),
|
||||
And(Vec<Box<Formula>>),
|
||||
Or(Vec<Box<Formula>>),
|
||||
Implies(Box<Formula>, Box<Formula>),
|
||||
Biconditional(Box<Formula>, Box<Formula>),
|
||||
Less(Term, Term),
|
||||
LessOrEqual(Term, Term),
|
||||
Greater(Term, Term),
|
||||
GreaterOrEqual(Term, Term),
|
||||
Equal(Term, Term),
|
||||
NotEqual(Term, Term),
|
||||
Boolean(bool),
|
||||
Predicate(Predicate),
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Domain
|
||||
{
|
||||
Program,
|
||||
Integer,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct VariableDeclaration
|
||||
{
|
||||
pub name: String,
|
||||
pub domain: Domain,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Term
|
||||
// Terms
|
||||
|
||||
pub struct BinaryOperation
|
||||
{
|
||||
pub operator: BinaryOperator,
|
||||
pub left: Box<Term>,
|
||||
pub right: Box<Term>,
|
||||
}
|
||||
|
||||
pub struct Function
|
||||
{
|
||||
pub declaration: std::rc::Rc<FunctionDeclaration>,
|
||||
pub arguments: Vec<Box<Term>>,
|
||||
}
|
||||
|
||||
pub enum SpecialInteger
|
||||
{
|
||||
Infimum,
|
||||
Supremum,
|
||||
Integer(i64),
|
||||
Symbolic(String),
|
||||
String(String),
|
||||
Variable(VariableDeclaration),
|
||||
Add(Box<Term>, Box<Term>),
|
||||
Subtract(Box<Term>, Box<Term>),
|
||||
Multiply(Box<Term>, Box<Term>),
|
||||
Negative(Box<Term>),
|
||||
}
|
||||
|
||||
pub struct UnaryOperation
|
||||
{
|
||||
pub operator: UnaryOperator,
|
||||
pub argument: Box<Term>,
|
||||
}
|
||||
|
||||
pub struct Variable
|
||||
{
|
||||
pub declaration: std::rc::Rc<VariableDeclaration>,
|
||||
}
|
||||
|
||||
// Formulas
|
||||
|
||||
pub struct Biconditional
|
||||
{
|
||||
pub left: Box<Formula>,
|
||||
pub right: Box<Formula>,
|
||||
}
|
||||
|
||||
pub struct Comparison
|
||||
{
|
||||
pub operator: ComparisonOperator,
|
||||
pub left: Box<Term>,
|
||||
pub right: Box<Term>,
|
||||
}
|
||||
|
||||
pub struct Exists
|
||||
{
|
||||
pub parameters: Vec<std::rc::Rc<VariableDeclaration>>,
|
||||
pub argument: Box<Formula>,
|
||||
}
|
||||
|
||||
pub struct ForAll
|
||||
{
|
||||
pub parameters: Vec<std::rc::Rc<VariableDeclaration>>,
|
||||
pub argument: Box<Formula>,
|
||||
}
|
||||
|
||||
pub struct Implies
|
||||
{
|
||||
pub antecedent: Box<Formula>,
|
||||
pub implication: Box<Formula>,
|
||||
}
|
||||
|
||||
pub struct Predicate
|
||||
{
|
||||
pub declaration: std::rc::Rc<PredicateDeclaration>,
|
||||
pub arguments: Vec<Box<Term>>,
|
||||
}
|
||||
|
||||
// Variants
|
||||
|
||||
pub enum Term
|
||||
{
|
||||
BinaryOperation(BinaryOperation),
|
||||
Boolean(bool),
|
||||
Function(Function),
|
||||
Integer(i32),
|
||||
SpecialInteger(SpecialInteger),
|
||||
String(String),
|
||||
Symbolic(String),
|
||||
UnaryOperation(UnaryOperation),
|
||||
Variable(Variable),
|
||||
}
|
||||
|
||||
pub type Terms = Vec<Box<Term>>;
|
||||
|
||||
pub enum Formula
|
||||
{
|
||||
And(Formulas),
|
||||
Biconditional(Biconditional),
|
||||
Boolean(bool),
|
||||
Comparison(Comparison),
|
||||
Exists(Exists),
|
||||
ForAll(ForAll),
|
||||
Implies(Implies),
|
||||
Not(Box<Formula>),
|
||||
Or(Formulas),
|
||||
Predicate(Predicate),
|
||||
}
|
||||
|
||||
pub type Formulas = Vec<Box<Formula>>;
|
||||
|
Reference in New Issue
Block a user