More expression types
This commit is contained in:
@@ -104,6 +104,9 @@ enum ConstructVariant {
|
|||||||
case EqualTo
|
case EqualTo
|
||||||
case NotEqualTo
|
case NotEqualTo
|
||||||
|
|
||||||
|
case LogicalAnd
|
||||||
|
case LogicalOr
|
||||||
|
|
||||||
// Unary operation variants
|
// Unary operation variants
|
||||||
case Negation
|
case Negation
|
||||||
case BitwiseCompliment
|
case BitwiseCompliment
|
||||||
@@ -111,6 +114,10 @@ enum ConstructVariant {
|
|||||||
|
|
||||||
// Expression variants
|
// Expression variants
|
||||||
case TermSequence
|
case TermSequence
|
||||||
|
case AdditiveExpressionSequence
|
||||||
|
case RelationalExpressionSequence
|
||||||
|
case EqualityExpressionSequence
|
||||||
|
case LogicalAndExpressionSequence
|
||||||
|
|
||||||
// Term variants
|
// Term variants
|
||||||
case FactorSequence
|
case FactorSequence
|
||||||
@@ -141,6 +148,8 @@ enum ConstructType {
|
|||||||
case AdditionPriorityOperator
|
case AdditionPriorityOperator
|
||||||
case InequalityPriorityOperator
|
case InequalityPriorityOperator
|
||||||
case EqualityPriorityOperator
|
case EqualityPriorityOperator
|
||||||
|
case LogicalAndPriorityOperator
|
||||||
|
case LogicalOrPriorityOperator
|
||||||
|
|
||||||
case Program
|
case Program
|
||||||
case Function
|
case Function
|
||||||
@@ -214,13 +223,55 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
.LogicalAndPriorityOperator: [
|
||||||
|
.LogicalAnd: [
|
||||||
|
.Token(type: .LOGICAL_AND),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
.LogicalOrPriorityOperator: [
|
||||||
|
.LogicalAnd: [
|
||||||
|
.Token(type: .LOGICAL_OR),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
// Expressions
|
||||||
.Expression: [
|
.Expression: [
|
||||||
|
.LogicalAndExpressionSequence: [
|
||||||
|
.Construct(type: .LogicalAndExpression),
|
||||||
|
.Loop(type: .LogicalOrPriorityOperator),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
.LogicalAndExpression: [
|
||||||
|
.EqualityExpressionSequence: [
|
||||||
|
.Construct(type: .EqualityExpression),
|
||||||
|
.Loop(type: .LogicalAndPriorityOperator),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
.EqualityExpression: [
|
||||||
|
.RelationalExpressionSequence: [
|
||||||
|
.Construct(type: .RelationalExpression),
|
||||||
|
.Loop(type: .EqualityPriorityOperator),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
.RelationalExpression: [
|
||||||
|
.AdditiveExpressionSequence: [
|
||||||
|
.Construct(type: .AdditiveExpression),
|
||||||
|
.Loop(type: .InequalityPriorityOperator),
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
.AdditiveExpression: [
|
||||||
.TermSequence: [
|
.TermSequence: [
|
||||||
.Construct(type: .Term),
|
.Construct(type: .Term),
|
||||||
.Loop(type: .AdditionPriorityOperator),
|
.Loop(type: .AdditionPriorityOperator),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Sub-expressions
|
||||||
.Term: [
|
.Term: [
|
||||||
.FactorSequence: [
|
.FactorSequence: [
|
||||||
.Construct(type: .Factor),
|
.Construct(type: .Factor),
|
||||||
@@ -243,6 +294,7 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Super-expressions
|
||||||
.Statement: [
|
.Statement: [
|
||||||
.ReturnInteger: [
|
.ReturnInteger: [
|
||||||
.Token(type: .RETURN),
|
.Token(type: .RETURN),
|
||||||
@@ -421,6 +473,30 @@ func generateOutput(_ node: SyntaxTreeNode) -> String {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case .LogicalAndExpressionSequence:
|
||||||
|
for child in node.children {
|
||||||
|
text += generateOutput(child)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case .EqualityExpressionSequence:
|
||||||
|
for child in node.children {
|
||||||
|
text += generateOutput(child)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case .RelationalExpressionSequence:
|
||||||
|
for child in node.children {
|
||||||
|
text += generateOutput(child)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case .AdditiveExpressionSequence:
|
||||||
|
for child in node.children {
|
||||||
|
text += generateOutput(child)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
case .TermSequence:
|
case .TermSequence:
|
||||||
var operation: ConstructVariant = .Error
|
var operation: ConstructVariant = .Error
|
||||||
let count = node.children.count
|
let count = node.children.count
|
||||||
@@ -678,49 +754,6 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if valid == .Invalid {
|
|
||||||
print("\(indent)Subconstruct validation failed")
|
|
||||||
return .Invalid
|
|
||||||
} else if valid == .Break {
|
|
||||||
print("\(indent)End validate subconstruct (variant \"\(validVariant) by breaking\")")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//print("\(indent)End validate subconstruct (variant \"\(validVariant)\")")
|
|
||||||
break
|
|
||||||
|
|
||||||
case .Token(let type):
|
|
||||||
if let token: Token = tokens.popLast() {
|
|
||||||
if type != token.type {
|
|
||||||
print("\(indent)VALIDATION FAILED FOR TOKEN \"\(token.content)\"")
|
|
||||||
return .Invalid
|
|
||||||
}
|
|
||||||
print("\(indent)Validated token \"\(token.content)\"")
|
|
||||||
|
|
||||||
if token.type == .LITERAL_INTEGER {
|
|
||||||
node.value = String(token.content)
|
|
||||||
}
|
|
||||||
else if token.type == .IDENTIFIER {
|
|
||||||
node.value = String(token.content)
|
|
||||||
}
|
|
||||||
|
|
||||||
continue
|
|
||||||
|
|
||||||
} else {
|
|
||||||
print("\(indent)RAN OUT OF TOKENS")
|
|
||||||
return .Invalid
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
case .Construct(let type):
|
case .Construct(let type):
|
||||||
print("\(indent)Begin validate subconstruct (type \"\(type)\")")
|
print("\(indent)Begin validate subconstruct (type \"\(type)\")")
|
||||||
|
|
||||||
@@ -752,12 +785,6 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if valid == .Invalid {
|
if valid == .Invalid {
|
||||||
print("\(indent)Subconstruct validation failed")
|
print("\(indent)Subconstruct validation failed")
|
||||||
return .Invalid
|
return .Invalid
|
||||||
|
|||||||
Reference in New Issue
Block a user