Stage 5 minus missing return support
This commit is contained in:
@@ -1,5 +1,65 @@
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct rxcc {
|
||||
var variables: Dictionary<String, Int> = [:]
|
||||
var stackIndex: Int = 0
|
||||
|
||||
static func main() {
|
||||
var compiler = rxcc()
|
||||
compiler.initialize()
|
||||
}
|
||||
|
||||
mutating func initialize() {
|
||||
if CommandLine.arguments.count < 2 {
|
||||
for testFile in getTestFiles() {
|
||||
print("Testing \(testFile.valid ? "valid" : "invalid") file \(testFile.name):")
|
||||
print(testFile.contents)
|
||||
variables = [:]
|
||||
stackIndex = 0
|
||||
let lexed: [Substring] = lex(string: testFile.contents)
|
||||
let output: String = parse(lexed: lexed)
|
||||
|
||||
if output.isEmpty {
|
||||
print()
|
||||
continue
|
||||
}
|
||||
|
||||
do {
|
||||
try output.write(to: URL(fileURLWithPath: "bin").appendingPathComponent("\(testFile.name.dropLast())s"), atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
print("Couldn't write file \"\(testFile.name.dropLast())s\"")
|
||||
}
|
||||
|
||||
print()
|
||||
}
|
||||
} else {
|
||||
var text = ""
|
||||
do {
|
||||
text = try String(contentsOf: URL(fileURLWithPath: CommandLine.arguments[1]), encoding: .utf8)
|
||||
} catch {
|
||||
print("Error reading file from command line argument")
|
||||
}
|
||||
print(CommandLine.arguments)
|
||||
|
||||
let lexed: [Substring] = lex(string: text)
|
||||
let output: String = parse(lexed: lexed)
|
||||
|
||||
if output.isEmpty {
|
||||
print("Failed to compile")
|
||||
}
|
||||
|
||||
var fileName = String(CommandLine.arguments[1].dropLast() + "s")
|
||||
fileName = URL(fileURLWithPath: fileName).lastPathComponent
|
||||
|
||||
do {
|
||||
try output.write(to: URL(fileURLWithPath: fileName), atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
print("Couldn't write file \"\(CommandLine.arguments[1].dropLast())s\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SyntaxTreeNode {
|
||||
var parent: SyntaxTreeNode?
|
||||
var children: [SyntaxTreeNode]
|
||||
@@ -38,6 +98,8 @@ class SyntaxTreeNode {
|
||||
var text: String = "\(variant)"
|
||||
if variant == .LiteralInteger {
|
||||
text += "(\(value))"
|
||||
} else if variant == .Variable {
|
||||
text += "(\(value))"
|
||||
}
|
||||
for child in children {
|
||||
text += "\n\(String(repeating: " ", count: level))└───\(child.text(level + 1))"
|
||||
@@ -74,6 +136,8 @@ enum TokenType {
|
||||
case GREATER_THAN
|
||||
case GREATER_THAN_OR_EQUAL_TO
|
||||
|
||||
case ASSIGNMENT
|
||||
|
||||
case UNDEFINED
|
||||
}
|
||||
|
||||
@@ -85,12 +149,19 @@ struct Token {
|
||||
typealias Construct = [Element]
|
||||
|
||||
enum Element {
|
||||
case Loop(type: ConstructType)
|
||||
case List(type: ConstructType)
|
||||
case OperatorLoop(type: ConstructType)
|
||||
case Construct(type: ConstructType)
|
||||
case Optional(type: TokenType)
|
||||
case Token(type: TokenType)
|
||||
}
|
||||
|
||||
enum ConstructVariant {
|
||||
case Variable
|
||||
case StandaloneVariable
|
||||
case IntegerVariableDeclaration
|
||||
case VariableAssignment
|
||||
|
||||
case Addition
|
||||
case Subtraction
|
||||
case Multiplication
|
||||
@@ -118,6 +189,8 @@ enum ConstructVariant {
|
||||
case RelationalExpressionSequence
|
||||
case EqualityExpressionSequence
|
||||
case LogicalAndExpressionSequence
|
||||
case LogicalOrExpressionSequence
|
||||
case VariableExpression
|
||||
|
||||
// Term variants
|
||||
case FactorSequence
|
||||
@@ -128,7 +201,11 @@ enum ConstructVariant {
|
||||
case ParenthesizedExpression
|
||||
|
||||
// Statement variants
|
||||
case ReturnInteger
|
||||
case StatementSequence
|
||||
|
||||
case ReturnExpression
|
||||
case DeclareVariable
|
||||
case StandaloneExpression
|
||||
|
||||
// Function Variants
|
||||
case Integer
|
||||
@@ -142,6 +219,10 @@ enum ConstructVariant {
|
||||
}
|
||||
|
||||
enum ConstructType {
|
||||
case VariableFactor
|
||||
case VariableDeclaration
|
||||
case VariableAssignment
|
||||
|
||||
case UnaryOperator
|
||||
|
||||
case MultiplicationPriorityOperator
|
||||
@@ -153,8 +234,10 @@ enum ConstructType {
|
||||
|
||||
case Program
|
||||
case Function
|
||||
case StatementList
|
||||
case Statement
|
||||
case Expression
|
||||
case LogicalOrExpression
|
||||
case LogicalAndExpression
|
||||
case EqualityExpression
|
||||
case RelationalExpression
|
||||
@@ -169,6 +252,26 @@ struct ConstructDefinitions {
|
||||
}
|
||||
|
||||
let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant, Construct>> = [
|
||||
.VariableFactor: [
|
||||
.Variable: [
|
||||
.Token(type: .IDENTIFIER),
|
||||
],
|
||||
],
|
||||
.VariableDeclaration: [
|
||||
.Variable: [
|
||||
.Token(type: .INT),
|
||||
.Token(type: .IDENTIFIER),
|
||||
.Optional(type: .ASSIGNMENT),
|
||||
.Construct(type: .Expression),
|
||||
],
|
||||
],
|
||||
.VariableAssignment: [
|
||||
.Variable: [
|
||||
.Token(type: .IDENTIFIER),
|
||||
.Token(type: .ASSIGNMENT),
|
||||
.Construct(type: .Expression),
|
||||
],
|
||||
],
|
||||
.UnaryOperator: [
|
||||
.Negation: [
|
||||
.Token(type: .NEGATION),
|
||||
@@ -237,37 +340,46 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
||||
|
||||
// Expressions
|
||||
.Expression: [
|
||||
.VariableExpression: [
|
||||
.Construct(type: .VariableAssignment)
|
||||
],
|
||||
.LogicalOrExpressionSequence: [
|
||||
.Construct(type: .LogicalOrExpression)
|
||||
],
|
||||
],
|
||||
|
||||
.LogicalOrExpression: [
|
||||
.LogicalAndExpressionSequence: [
|
||||
.Construct(type: .LogicalAndExpression),
|
||||
.Loop(type: .LogicalOrPriorityOperator),
|
||||
.OperatorLoop(type: .LogicalOrPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
.LogicalAndExpression: [
|
||||
.EqualityExpressionSequence: [
|
||||
.Construct(type: .EqualityExpression),
|
||||
.Loop(type: .LogicalAndPriorityOperator),
|
||||
.OperatorLoop(type: .LogicalAndPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
.EqualityExpression: [
|
||||
.RelationalExpressionSequence: [
|
||||
.Construct(type: .RelationalExpression),
|
||||
.Loop(type: .EqualityPriorityOperator),
|
||||
.OperatorLoop(type: .EqualityPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
.RelationalExpression: [
|
||||
.AdditiveExpressionSequence: [
|
||||
.Construct(type: .AdditiveExpression),
|
||||
.Loop(type: .InequalityPriorityOperator),
|
||||
.OperatorLoop(type: .InequalityPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
.AdditiveExpression: [
|
||||
.TermSequence: [
|
||||
.Construct(type: .Term),
|
||||
.Loop(type: .AdditionPriorityOperator),
|
||||
.OperatorLoop(type: .AdditionPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
@@ -275,7 +387,7 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
||||
.Term: [
|
||||
.FactorSequence: [
|
||||
.Construct(type: .Factor),
|
||||
.Loop(type: .MultiplicationPriorityOperator),
|
||||
.OperatorLoop(type: .MultiplicationPriorityOperator),
|
||||
]
|
||||
],
|
||||
|
||||
@@ -291,16 +403,33 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
||||
.Token(type: .PARENTHESIS_OPEN),
|
||||
.Construct(type: .Expression),
|
||||
.Token(type: .PARENTHESIS_CLOSE)
|
||||
],
|
||||
.StandaloneVariable: [
|
||||
.Construct(type: .VariableFactor)
|
||||
]
|
||||
],
|
||||
|
||||
// Super-expressions
|
||||
.StatementList: [
|
||||
.StatementSequence: [
|
||||
.List(type: .Statement)
|
||||
]
|
||||
],
|
||||
|
||||
.Statement: [
|
||||
.ReturnInteger: [
|
||||
.ReturnExpression: [
|
||||
.Token(type: .RETURN),
|
||||
.Construct(type: .Expression),
|
||||
.Token(type: .SEMICOLON)
|
||||
]
|
||||
],
|
||||
.StandaloneExpression: [
|
||||
.Construct(type: .Expression),
|
||||
.Token(type: .SEMICOLON)
|
||||
],
|
||||
.DeclareVariable: [
|
||||
.Construct(type: .VariableDeclaration),
|
||||
.Token(type: .SEMICOLON)
|
||||
],
|
||||
],
|
||||
|
||||
.Function: [
|
||||
@@ -310,7 +439,7 @@ let constructDefinitions: Dictionary<ConstructType, Dictionary<ConstructVariant,
|
||||
.Token(type: .PARENTHESIS_OPEN),
|
||||
.Token(type: .PARENTHESIS_CLOSE),
|
||||
.Token(type: .BRACE_OPEN),
|
||||
.Construct(type: .Statement),
|
||||
.Construct(type: .StatementList),
|
||||
.Token(type: .BRACE_CLOSE)
|
||||
]
|
||||
],
|
||||
@@ -339,62 +468,12 @@ struct TestFile {
|
||||
var valid: Bool
|
||||
}
|
||||
|
||||
@main
|
||||
struct rxcc {
|
||||
static func main() {
|
||||
if CommandLine.arguments.count < 2 {
|
||||
for testFile in getTestFiles() {
|
||||
print("Testing \(testFile.valid ? "valid" : "invalid") file \(testFile.name):")
|
||||
print(testFile.contents)
|
||||
let lexed: [Substring] = lex(string: testFile.contents)
|
||||
let output: String = parse(lexed: lexed)
|
||||
|
||||
if output.isEmpty {
|
||||
print()
|
||||
continue
|
||||
}
|
||||
|
||||
do {
|
||||
try output.write(to: URL(fileURLWithPath: "bin").appendingPathComponent("\(testFile.name.dropLast())s"), atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
print("Couldn't write file \"\(testFile.name.dropLast())s\"")
|
||||
}
|
||||
|
||||
print()
|
||||
}
|
||||
} else {
|
||||
var text = ""
|
||||
do {
|
||||
text = try String(contentsOf: URL(fileURLWithPath: CommandLine.arguments[1]), encoding: .utf8)
|
||||
} catch {
|
||||
print("Error reading file from command line argument")
|
||||
}
|
||||
print(CommandLine.arguments)
|
||||
|
||||
let lexed: [Substring] = lex(string: text)
|
||||
let output: String = parse(lexed: lexed)
|
||||
|
||||
if output.isEmpty {
|
||||
print("Failed to compile")
|
||||
}
|
||||
|
||||
var fileName = String(CommandLine.arguments[1].dropLast() + "s")
|
||||
fileName = URL(fileURLWithPath: fileName).lastPathComponent
|
||||
|
||||
do {
|
||||
try output.write(to: URL(fileURLWithPath: fileName), atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
print("Couldn't write file \"\(CommandLine.arguments[1].dropLast())s\"")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getTestFiles() -> [TestFile] {
|
||||
var testFiles: [TestFile] = [TestFile]()
|
||||
|
||||
let fileManager = FileManager.default
|
||||
let path = "c/tests/stage_4"
|
||||
let path = "c/tests/stage_5"
|
||||
|
||||
do {
|
||||
let validItems = try fileManager.contentsOfDirectory(atPath: path + "/valid")
|
||||
@@ -440,9 +519,11 @@ func lex(string: String) -> [Substring] {
|
||||
line = line.replacing("/", with: " / ")
|
||||
line = line.replacing("<", with: " < ")
|
||||
line = line.replacing(">", with: " > ")
|
||||
line = line.replacing("=", with: " = ")
|
||||
line = line.replacing("&&", with: " && ")
|
||||
line = line.replacing("||", with: " || ")
|
||||
line = line.replacing("==", with: " == ")
|
||||
line = line.replacing(/= +=/, with: " == ")
|
||||
line = line.replacing(/! *=/, with: " != ")
|
||||
line = line.replacing(/< *=/, with: " <= ")
|
||||
line = line.replacing(/> *=/, with: " >= ")
|
||||
@@ -458,7 +539,7 @@ func lex(string: String) -> [Substring] {
|
||||
return []
|
||||
}
|
||||
|
||||
func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
mutating func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
var text: String = ""
|
||||
switch node.variant {
|
||||
case .Root:
|
||||
@@ -467,12 +548,110 @@ func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
}
|
||||
break
|
||||
|
||||
case .StatementSequence:
|
||||
for child in node.children {
|
||||
text += generateOutput(child)
|
||||
}
|
||||
break
|
||||
|
||||
case .ParenthesizedExpression:
|
||||
for child in node.children {
|
||||
text += generateOutput(child)
|
||||
}
|
||||
break
|
||||
|
||||
case .StandaloneVariable:
|
||||
let count = node.children.count
|
||||
if count != 1 {
|
||||
print("ERROR: \(node.variant) with more or less than 1 child")
|
||||
break
|
||||
}
|
||||
//text += generateOutput(node.children[0])
|
||||
let variable: String = node.children[0].value
|
||||
if let index = variables[variable] {
|
||||
text += " movl\t\(index)(%ebp), %eax\n"
|
||||
} else {
|
||||
print("ERROR: \(variable) used before it was declared (in \(node.variant))")
|
||||
}
|
||||
break
|
||||
|
||||
case .DeclareVariable:
|
||||
let count = node.children.count
|
||||
if count != 1 {
|
||||
print("ERROR: \(node.variant) with more or less than 1 child")
|
||||
break
|
||||
}
|
||||
let variable: String = node.children[0].value
|
||||
|
||||
if variables.keys.contains(variable) {
|
||||
print("ERROR: Redefinition of variable \"\(variable)\"")
|
||||
break
|
||||
}
|
||||
|
||||
variables.updateValue(stackIndex, forKey: variable)
|
||||
stackIndex -= 4
|
||||
|
||||
let notInitialized: Bool = node.children[0].children.count == 0
|
||||
|
||||
//print("For variable \(variable), node children 0 children count == 0 : \(notInitialized)")
|
||||
|
||||
if notInitialized {
|
||||
text += " push\t$0\n"
|
||||
} else {
|
||||
text += generateOutput(node.children[0])
|
||||
text += " push\t%eax\n"
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
case .VariableExpression:
|
||||
let count = node.children.count
|
||||
if count != 1 {
|
||||
print("ERROR: \(node.variant) with more or less than 1 child")
|
||||
break
|
||||
}
|
||||
let variable: String = node.children[0].value
|
||||
|
||||
text += generateOutput(node.children[0])
|
||||
text += " push\t%eax\n"
|
||||
|
||||
break
|
||||
|
||||
case .Variable:
|
||||
let count = node.children.count
|
||||
if count > 1 {
|
||||
print("ERROR: \(node.variant) with more than 1 child")
|
||||
break
|
||||
}
|
||||
let variable: String = node.value
|
||||
|
||||
if !variables.keys.contains(variable) {
|
||||
print("ERROR: Variable \"\(variable)\" used before it was declared")
|
||||
break
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
text += generateOutput(node.children[0])
|
||||
}
|
||||
|
||||
text += " movl\t%eax, \(variables[variable]!)(%ebp)\n"
|
||||
|
||||
break
|
||||
|
||||
case .LogicalOrExpressionSequence:
|
||||
if node.children.count != 1 {
|
||||
print("Error: \(node.variant) with more or less than one child")
|
||||
}
|
||||
text += generateOutput(node.children[0])
|
||||
break
|
||||
|
||||
case .StandaloneExpression:
|
||||
if node.children.count != 1 {
|
||||
print("Error: \(node.variant) with more or less than one child")
|
||||
}
|
||||
text += generateOutput(node.children[0])
|
||||
break
|
||||
|
||||
case .LogicalAndExpressionSequence:
|
||||
var operation: ConstructVariant = .Error
|
||||
let count = node.children.count
|
||||
@@ -750,29 +929,32 @@ func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
}
|
||||
break
|
||||
|
||||
/*
|
||||
<CODE FOR e1 GOES HERE>
|
||||
push %eax ; save value of e1 on the stack
|
||||
<CODE FOR e2 GOES HERE>
|
||||
pop %ecx ; pop e1 from the stack into ecx
|
||||
addl %ecx, %eax ; add e1 to e2, save results in eax
|
||||
*/
|
||||
|
||||
case .Integer:
|
||||
text += " .globl \(node.value)\n\(node.value):\n"
|
||||
text += """
|
||||
.globl \(node.value)
|
||||
\(node.value):
|
||||
push\t%ebp
|
||||
movl\t%esp, %ebp
|
||||
|
||||
"""
|
||||
|
||||
for child in node.children {
|
||||
text += generateOutput(child)
|
||||
}
|
||||
break
|
||||
|
||||
case .ReturnInteger:
|
||||
case .ReturnExpression:
|
||||
if node.children.count != 1 {
|
||||
print("\(node.variant) cannot have more than one child node")
|
||||
return "[ERROR]"
|
||||
}
|
||||
|
||||
text += generateOutput(node.children[0])
|
||||
text += " ret\n"
|
||||
text += """
|
||||
movl\t%ebp, %esp
|
||||
pop \t%ebp
|
||||
ret\n
|
||||
"""
|
||||
break
|
||||
|
||||
case .UnaryOperation:
|
||||
@@ -812,7 +994,7 @@ func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
return text
|
||||
}
|
||||
|
||||
func parse(lexed: [Substring]) -> String {
|
||||
mutating func parse(lexed: [Substring]) -> String {
|
||||
var tokens: [Token] = [Token]()
|
||||
for token: Substring in lexed {
|
||||
let tokenType: TokenType = categorizeToken(token: token)
|
||||
@@ -858,7 +1040,7 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
let construct = constructDefinitions[type]![variant]!
|
||||
for element in construct {
|
||||
switch element {
|
||||
case .Loop(let constructType):
|
||||
case .OperatorLoop(let constructType):
|
||||
var valid: Validity = .Invalid
|
||||
var matchingOperator: Bool = false
|
||||
print("\(indent)Determining need to loop construct of type \(constructType)")
|
||||
@@ -867,7 +1049,13 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
let childNode = node.addChild(value: constructVariant)
|
||||
print("\(indent)Testing operator \(constructType)::\(constructVariant)")
|
||||
|
||||
valid = validateConstruct(type: constructType, variant: constructVariant, tokens: &tokens, node: childNode)
|
||||
valid = validateConstruct(
|
||||
type: constructType,
|
||||
variant: constructVariant,
|
||||
tokens: &tokens,
|
||||
node: childNode
|
||||
)
|
||||
|
||||
if valid == .Panic {
|
||||
print("\(indent)Fail: panic (variant \"\(constructVariant)\"))\n")
|
||||
return .Invalid
|
||||
@@ -876,6 +1064,7 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
_ = node.popLastChild()
|
||||
continue
|
||||
}
|
||||
|
||||
matchingOperator = true
|
||||
break
|
||||
}
|
||||
@@ -889,13 +1078,42 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
break
|
||||
}
|
||||
|
||||
case .Optional(let tokenType):
|
||||
print("\(indent)Determining need to continue. (Testing\(tokenType))")
|
||||
let tokenBackup: [Token] = tokens
|
||||
if let token: Token = tokens.popLast() {
|
||||
if token.type == tokenType {
|
||||
print("\(indent)\(tokenType) validated. Continuing")
|
||||
continue
|
||||
} else {
|
||||
print("\(indent)\(tokenType) NOT validated. Breaking")
|
||||
tokens = tokenBackup
|
||||
return .Valid
|
||||
}
|
||||
} else {
|
||||
print("No more tokens")
|
||||
return .Invalid
|
||||
}
|
||||
|
||||
case .Construct(let type):
|
||||
print("\(indent)Begin validate subconstruct (type \"\(type)\")")
|
||||
|
||||
var valid: Validity = .Invalid
|
||||
var validVariant: ConstructVariant = .Error
|
||||
let tokenBackup: [Token] = tokens
|
||||
for variant in constructDefinitions[type]!.keys {
|
||||
|
||||
|
||||
var constructVariants = Array(constructDefinitions[type]!.keys)
|
||||
if constructVariants.contains(.VariableExpression) {
|
||||
let index: Int = constructVariants.firstIndex(of: .VariableExpression)!
|
||||
let atZero: ConstructVariant = constructVariants[0]
|
||||
constructVariants[0] = constructVariants[index]
|
||||
constructVariants[index] = atZero
|
||||
print("\(indent)Put VariableExpression at the start of the array")
|
||||
}
|
||||
|
||||
|
||||
for variant in constructVariants {
|
||||
let childNode = node.addChild(value: variant)
|
||||
var loopable = false
|
||||
if variant == .FactorSequence || variant == .TermSequence {
|
||||
@@ -903,7 +1121,13 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
}
|
||||
|
||||
print("\(indent)Testing variant \(variant) (Loop = \(loop)) (Loopable = \(loopable))")
|
||||
valid = validateConstruct(type: type, variant: variant, tokens: &tokens, node: childNode)
|
||||
valid = validateConstruct(
|
||||
type: type,
|
||||
variant: variant,
|
||||
tokens: &tokens,
|
||||
node: childNode
|
||||
)
|
||||
|
||||
if valid == .Panic {
|
||||
print("\(indent)Fail: panic (variant \"\(variant)\"))\n")
|
||||
return .Invalid
|
||||
@@ -913,6 +1137,7 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
_ = node.popLastChild()
|
||||
continue
|
||||
}
|
||||
|
||||
print("\(indent)Success (variant \"\(variant)\")\n")
|
||||
validVariant = variant
|
||||
|
||||
@@ -931,11 +1156,63 @@ func validateConstruct(type: ConstructType, variant: ConstructVariant, tokens: i
|
||||
print("\(indent)End validate subconstruct (variant \"\(validVariant)\")")
|
||||
continue
|
||||
|
||||
case .List(let constructType):
|
||||
var valid: Validity = .Invalid
|
||||
var matching: Bool = false
|
||||
print("\(indent)Determining need to loop construct of type \(constructType)")
|
||||
let tokenBackup: [Token] = tokens
|
||||
|
||||
var constructVariants = Array(constructDefinitions[constructType]!.keys)
|
||||
if constructVariants.contains(.VariableExpression) {
|
||||
let index: Int = constructVariants.firstIndex(of: .VariableExpression)!
|
||||
let atZero: ConstructVariant = constructVariants[0]
|
||||
constructVariants[0] = constructVariants[index]
|
||||
constructVariants[index] = atZero
|
||||
print("\(indent)Put VariableExpression at the start of the array")
|
||||
}
|
||||
|
||||
for constructVariant in constructVariants {
|
||||
let childNode = node.addChild(value: constructVariant)
|
||||
print("\(indent)Testing \(constructType)::\(constructVariant)")
|
||||
|
||||
valid = validateConstruct(
|
||||
type: constructType,
|
||||
variant: constructVariant,
|
||||
tokens: &tokens,
|
||||
node: childNode
|
||||
)
|
||||
|
||||
if valid == .Panic {
|
||||
print("\(indent)Fail: panic (variant \"\(constructVariant)\"))\n")
|
||||
return .Invalid
|
||||
} else if valid == .Invalid {
|
||||
tokens = tokenBackup
|
||||
_ = node.popLastChild()
|
||||
continue
|
||||
}
|
||||
|
||||
matching = true
|
||||
break
|
||||
}
|
||||
|
||||
loop = matching
|
||||
|
||||
if loop {
|
||||
print("\(indent)Looping")
|
||||
} else {
|
||||
print("\(indent)Not looping")
|
||||
break
|
||||
}
|
||||
|
||||
case .Token(let type):
|
||||
if let token: Token = tokens.popLast() {
|
||||
if type != token.type {
|
||||
print("\(indent)VALIDATION FAILED FOR TOKEN \"\(token.content)\"")
|
||||
print("\(indent)AKA, \(type) not equal to \(token.type)")
|
||||
if token.type == .ASSIGNMENT && variant == .LogicalOrExpressionSequence {
|
||||
print("\(indent)Cannot encounter assignment in \(variant)")
|
||||
return .Invalid
|
||||
}
|
||||
else if type != token.type {
|
||||
print("\(indent)Failed to validate token \"\(token.content)\". Expected \"\(type)\"")
|
||||
//print("\(indent)AKA, \(type) not equal to \(token.type)")
|
||||
return .Invalid
|
||||
}
|
||||
print("\(indent)Validated token \"\(token.content)\"")
|
||||
@@ -984,7 +1261,8 @@ func categorizeToken(token: Substring) -> TokenType {
|
||||
else if token.firstMatch(of: /^<=$/) != nil { return .LESS_THAN_OR_EQUAL_TO }
|
||||
else if token.firstMatch(of: /^>$/) != nil { return .GREATER_THAN }
|
||||
else if token.firstMatch(of: /^>=$/) != nil { return .GREATER_THAN_OR_EQUAL_TO }
|
||||
else if token.firstMatch(of: /^=$/) != nil { return .ASSIGNMENT }
|
||||
|
||||
return .UNDEFINED
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
133
one
Normal file
133
one
Normal file
@@ -0,0 +1,133 @@
|
||||
Tokens:
|
||||
["int", "main", "(", ")", "{", "int", "tomas", ";", "tomas", "=", "2", ";", "return", "1", "+", "2", ";", "}"]
|
||||
Begin validate subconstruct (type "Function")
|
||||
Testing variant Integer (Loop = false) (Loopable = false)
|
||||
Validated token "int"
|
||||
Validated token "main"
|
||||
Validated token "("
|
||||
Validated token ")"
|
||||
Validated token "{"
|
||||
Begin validate subconstruct (type "StatementList")
|
||||
Testing variant StatementSequence (Loop = false) (Loopable = false)
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::ReturnExpression
|
||||
Failed to validate token "int". Expected "RETURN"
|
||||
Testing Statement::DeclareVariable
|
||||
Begin validate subconstruct (type "VariableDeclaration")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Validated token "int"
|
||||
Validated token "tomas"
|
||||
Determining need to continue. (TestingASSIGNMENT)
|
||||
ASSIGNMENT NOT validated. Breaking
|
||||
Success (variant "Variable")
|
||||
|
||||
End validate subconstruct (variant "Variable")
|
||||
Validated token ";"
|
||||
Looping
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::ReturnExpression
|
||||
Failed to validate token "tomas". Expected "RETURN"
|
||||
Testing Statement::DeclareVariable
|
||||
Begin validate subconstruct (type "VariableDeclaration")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "tomas". Expected "INT"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::StandaloneExpression
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Failed to validate token "tomas". Expected "LITERAL_INTEGER"
|
||||
Fail: no valid variants (variant "LiteralInteger")
|
||||
|
||||
Testing variant StandaloneVariable (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableFactor")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Validated token "tomas"
|
||||
Success (variant "Variable")
|
||||
|
||||
End validate subconstruct (variant "Variable")
|
||||
Success (variant "StandaloneVariable")
|
||||
|
||||
End validate subconstruct (variant "StandaloneVariable")
|
||||
Determining need to loop construct of type MultiplicationPriorityOperator
|
||||
Testing operator MultiplicationPriorityOperator::Division
|
||||
Failed to validate token "=". Expected "DIVISION"
|
||||
Testing operator MultiplicationPriorityOperator::Multiplication
|
||||
Failed to validate token "=". Expected "MULTIPLICATION"
|
||||
Not looping
|
||||
Success (variant "FactorSequence")
|
||||
|
||||
End validate subconstruct (variant "FactorSequence")
|
||||
Determining need to loop construct of type AdditionPriorityOperator
|
||||
Testing operator AdditionPriorityOperator::Subtraction
|
||||
Failed to validate token "=". Expected "NEGATION"
|
||||
Testing operator AdditionPriorityOperator::Addition
|
||||
Failed to validate token "=". Expected "ADDITION"
|
||||
Not looping
|
||||
Success (variant "TermSequence")
|
||||
|
||||
End validate subconstruct (variant "TermSequence")
|
||||
Determining need to loop construct of type InequalityPriorityOperator
|
||||
Testing operator InequalityPriorityOperator::GreaterThanOrEqualTo
|
||||
Failed to validate token "=". Expected "GREATER_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::LessThan
|
||||
Failed to validate token "=". Expected "LESS_THAN"
|
||||
Testing operator InequalityPriorityOperator::LessThanOrEqualTo
|
||||
Failed to validate token "=". Expected "LESS_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::GreaterThan
|
||||
Failed to validate token "=". Expected "GREATER_THAN"
|
||||
Not looping
|
||||
Success (variant "AdditiveExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "AdditiveExpressionSequence")
|
||||
Determining need to loop construct of type EqualityPriorityOperator
|
||||
Testing operator EqualityPriorityOperator::EqualTo
|
||||
Failed to validate token "=". Expected "EQUAL"
|
||||
Testing operator EqualityPriorityOperator::NotEqualTo
|
||||
Failed to validate token "=". Expected "NOT_EQUAL"
|
||||
Not looping
|
||||
Success (variant "RelationalExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "RelationalExpressionSequence")
|
||||
Determining need to loop construct of type LogicalAndPriorityOperator
|
||||
Testing operator LogicalAndPriorityOperator::LogicalAnd
|
||||
Failed to validate token "=". Expected "LOGICAL_AND"
|
||||
Not looping
|
||||
Success (variant "EqualityExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "EqualityExpressionSequence")
|
||||
Determining need to loop construct of type LogicalOrPriorityOperator
|
||||
Testing operator LogicalOrPriorityOperator::LogicalOr
|
||||
Failed to validate token "=". Expected "LOGICAL_OR"
|
||||
Not looping
|
||||
Success (variant "LogicalAndExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalAndExpressionSequence")
|
||||
Success (variant "LogicalOrExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalOrExpressionSequence")
|
||||
Failed to validate token "=". Expected "SEMICOLON"
|
||||
Not looping
|
||||
Success (variant "StatementSequence")
|
||||
|
||||
End validate subconstruct (variant "StatementSequence")
|
||||
Failed to validate token "tomas". Expected "BRACE_CLOSE"
|
||||
Fail: no valid variants (variant "Integer")
|
||||
|
||||
Subconstruct validation failed
|
||||
Distinct lack of success
|
||||
507
two
Normal file
507
two
Normal file
@@ -0,0 +1,507 @@
|
||||
Tokens:
|
||||
["int", "main", "(", ")", "{", "int", "tomas", ";", "tomas", "=", "2", ";", "return", "1", "+", "2", ";", "}"]
|
||||
Begin validate subconstruct (type "Function")
|
||||
Testing variant Integer (Loop = false) (Loopable = false)
|
||||
Validated token "int"
|
||||
Validated token "main"
|
||||
Validated token "("
|
||||
Validated token ")"
|
||||
Validated token "{"
|
||||
Begin validate subconstruct (type "StatementList")
|
||||
Testing variant StatementSequence (Loop = false) (Loopable = false)
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::StandaloneExpression
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "VariableExpression")
|
||||
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "LITERAL_INTEGER"
|
||||
Fail: no valid variants (variant "LiteralInteger")
|
||||
|
||||
Testing variant ParenthesizedExpression (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "PARENTHESIS_OPEN"
|
||||
Fail: no valid variants (variant "ParenthesizedExpression")
|
||||
|
||||
Testing variant StandaloneVariable (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableFactor")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "StandaloneVariable")
|
||||
|
||||
Testing variant UnaryOperation (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "UnaryOperator")
|
||||
Testing variant LogicalNegation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "LOGICAL_NEGATION"
|
||||
Fail: no valid variants (variant "LogicalNegation")
|
||||
|
||||
Testing variant BitwiseCompliment (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "BITWISE_COMPLIMENT"
|
||||
Fail: no valid variants (variant "BitwiseCompliment")
|
||||
|
||||
Testing variant Negation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "int". Expected "NEGATION"
|
||||
Fail: no valid variants (variant "Negation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "UnaryOperation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "FactorSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "TermSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "AdditiveExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "RelationalExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "EqualityExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalAndExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalOrExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::DeclareVariable
|
||||
Begin validate subconstruct (type "VariableDeclaration")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Validated token "int"
|
||||
Validated token "tomas"
|
||||
Determining need to continue. (TestingASSIGNMENT)
|
||||
ASSIGNMENT NOT validated. Breaking
|
||||
Success (variant "Variable")
|
||||
|
||||
End validate subconstruct (variant "Variable")
|
||||
Validated token ";"
|
||||
Looping
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::StandaloneExpression
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Validated token "tomas"
|
||||
Validated token "="
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "2". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "VariableExpression")
|
||||
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Validated token "2"
|
||||
Success (variant "LiteralInteger")
|
||||
|
||||
End validate subconstruct (variant "LiteralInteger")
|
||||
Determining need to loop construct of type MultiplicationPriorityOperator
|
||||
Testing operator MultiplicationPriorityOperator::Division
|
||||
Failed to validate token ";". Expected "DIVISION"
|
||||
Testing operator MultiplicationPriorityOperator::Multiplication
|
||||
Failed to validate token ";". Expected "MULTIPLICATION"
|
||||
Not looping
|
||||
Success (variant "FactorSequence")
|
||||
|
||||
End validate subconstruct (variant "FactorSequence")
|
||||
Determining need to loop construct of type AdditionPriorityOperator
|
||||
Testing operator AdditionPriorityOperator::Addition
|
||||
Failed to validate token ";". Expected "ADDITION"
|
||||
Testing operator AdditionPriorityOperator::Subtraction
|
||||
Failed to validate token ";". Expected "NEGATION"
|
||||
Not looping
|
||||
Success (variant "TermSequence")
|
||||
|
||||
End validate subconstruct (variant "TermSequence")
|
||||
Determining need to loop construct of type InequalityPriorityOperator
|
||||
Testing operator InequalityPriorityOperator::LessThan
|
||||
Failed to validate token ";". Expected "LESS_THAN"
|
||||
Testing operator InequalityPriorityOperator::GreaterThanOrEqualTo
|
||||
Failed to validate token ";". Expected "GREATER_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::LessThanOrEqualTo
|
||||
Failed to validate token ";". Expected "LESS_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::GreaterThan
|
||||
Failed to validate token ";". Expected "GREATER_THAN"
|
||||
Not looping
|
||||
Success (variant "AdditiveExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "AdditiveExpressionSequence")
|
||||
Determining need to loop construct of type EqualityPriorityOperator
|
||||
Testing operator EqualityPriorityOperator::EqualTo
|
||||
Failed to validate token ";". Expected "EQUAL"
|
||||
Testing operator EqualityPriorityOperator::NotEqualTo
|
||||
Failed to validate token ";". Expected "NOT_EQUAL"
|
||||
Not looping
|
||||
Success (variant "RelationalExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "RelationalExpressionSequence")
|
||||
Determining need to loop construct of type LogicalAndPriorityOperator
|
||||
Testing operator LogicalAndPriorityOperator::LogicalAnd
|
||||
Failed to validate token ";". Expected "LOGICAL_AND"
|
||||
Not looping
|
||||
Success (variant "EqualityExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "EqualityExpressionSequence")
|
||||
Determining need to loop construct of type LogicalOrPriorityOperator
|
||||
Testing operator LogicalOrPriorityOperator::LogicalOr
|
||||
Failed to validate token ";". Expected "LOGICAL_OR"
|
||||
Not looping
|
||||
Success (variant "LogicalAndExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalAndExpressionSequence")
|
||||
Success (variant "LogicalOrExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalOrExpressionSequence")
|
||||
Success (variant "Variable")
|
||||
|
||||
End validate subconstruct (variant "Variable")
|
||||
Success (variant "VariableExpression")
|
||||
|
||||
End validate subconstruct (variant "VariableExpression")
|
||||
Validated token ";"
|
||||
Looping
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::StandaloneExpression
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "VariableExpression")
|
||||
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "LITERAL_INTEGER"
|
||||
Fail: no valid variants (variant "LiteralInteger")
|
||||
|
||||
Testing variant ParenthesizedExpression (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "PARENTHESIS_OPEN"
|
||||
Fail: no valid variants (variant "ParenthesizedExpression")
|
||||
|
||||
Testing variant StandaloneVariable (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableFactor")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "StandaloneVariable")
|
||||
|
||||
Testing variant UnaryOperation (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "UnaryOperator")
|
||||
Testing variant LogicalNegation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "LOGICAL_NEGATION"
|
||||
Fail: no valid variants (variant "LogicalNegation")
|
||||
|
||||
Testing variant BitwiseCompliment (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "BITWISE_COMPLIMENT"
|
||||
Fail: no valid variants (variant "BitwiseCompliment")
|
||||
|
||||
Testing variant Negation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "NEGATION"
|
||||
Fail: no valid variants (variant "Negation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "UnaryOperation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "FactorSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "TermSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "AdditiveExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "RelationalExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "EqualityExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalAndExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalOrExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::DeclareVariable
|
||||
Begin validate subconstruct (type "VariableDeclaration")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "return". Expected "INT"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::ReturnExpression
|
||||
Validated token "return"
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "1". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "VariableExpression")
|
||||
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Validated token "1"
|
||||
Success (variant "LiteralInteger")
|
||||
|
||||
End validate subconstruct (variant "LiteralInteger")
|
||||
Determining need to loop construct of type MultiplicationPriorityOperator
|
||||
Testing operator MultiplicationPriorityOperator::Division
|
||||
Failed to validate token "+". Expected "DIVISION"
|
||||
Testing operator MultiplicationPriorityOperator::Multiplication
|
||||
Failed to validate token "+". Expected "MULTIPLICATION"
|
||||
Not looping
|
||||
Success (variant "FactorSequence")
|
||||
|
||||
End validate subconstruct (variant "FactorSequence")
|
||||
Determining need to loop construct of type AdditionPriorityOperator
|
||||
Testing operator AdditionPriorityOperator::Addition
|
||||
Validated token "+"
|
||||
Looping
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = true) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Validated token "2"
|
||||
Success (variant "LiteralInteger")
|
||||
|
||||
End validate subconstruct (variant "LiteralInteger")
|
||||
Determining need to loop construct of type MultiplicationPriorityOperator
|
||||
Testing operator MultiplicationPriorityOperator::Division
|
||||
Failed to validate token ";". Expected "DIVISION"
|
||||
Testing operator MultiplicationPriorityOperator::Multiplication
|
||||
Failed to validate token ";". Expected "MULTIPLICATION"
|
||||
Not looping
|
||||
Success (variant "FactorSequence")
|
||||
|
||||
End validate subconstruct (variant "FactorSequence")
|
||||
Determining need to loop construct of type AdditionPriorityOperator
|
||||
Testing operator AdditionPriorityOperator::Addition
|
||||
Failed to validate token ";". Expected "ADDITION"
|
||||
Testing operator AdditionPriorityOperator::Subtraction
|
||||
Failed to validate token ";". Expected "NEGATION"
|
||||
Not looping
|
||||
Success (variant "TermSequence")
|
||||
|
||||
End validate subconstruct (variant "TermSequence")
|
||||
Determining need to loop construct of type InequalityPriorityOperator
|
||||
Testing operator InequalityPriorityOperator::LessThan
|
||||
Failed to validate token ";". Expected "LESS_THAN"
|
||||
Testing operator InequalityPriorityOperator::GreaterThanOrEqualTo
|
||||
Failed to validate token ";". Expected "GREATER_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::LessThanOrEqualTo
|
||||
Failed to validate token ";". Expected "LESS_THAN_OR_EQUAL_TO"
|
||||
Testing operator InequalityPriorityOperator::GreaterThan
|
||||
Failed to validate token ";". Expected "GREATER_THAN"
|
||||
Not looping
|
||||
Success (variant "AdditiveExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "AdditiveExpressionSequence")
|
||||
Determining need to loop construct of type EqualityPriorityOperator
|
||||
Testing operator EqualityPriorityOperator::EqualTo
|
||||
Failed to validate token ";". Expected "EQUAL"
|
||||
Testing operator EqualityPriorityOperator::NotEqualTo
|
||||
Failed to validate token ";". Expected "NOT_EQUAL"
|
||||
Not looping
|
||||
Success (variant "RelationalExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "RelationalExpressionSequence")
|
||||
Determining need to loop construct of type LogicalAndPriorityOperator
|
||||
Testing operator LogicalAndPriorityOperator::LogicalAnd
|
||||
Failed to validate token ";". Expected "LOGICAL_AND"
|
||||
Not looping
|
||||
Success (variant "EqualityExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "EqualityExpressionSequence")
|
||||
Determining need to loop construct of type LogicalOrPriorityOperator
|
||||
Testing operator LogicalOrPriorityOperator::LogicalOr
|
||||
Failed to validate token ";". Expected "LOGICAL_OR"
|
||||
Not looping
|
||||
Success (variant "LogicalAndExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalAndExpressionSequence")
|
||||
Success (variant "LogicalOrExpressionSequence")
|
||||
|
||||
End validate subconstruct (variant "LogicalOrExpressionSequence")
|
||||
Validated token ";"
|
||||
Looping
|
||||
Determining need to loop construct of type Statement
|
||||
Testing Statement::StandaloneExpression
|
||||
Begin validate subconstruct (type "Expression")
|
||||
Testing variant VariableExpression (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableAssignment")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "VariableExpression")
|
||||
|
||||
Testing variant LogicalOrExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalOrExpression")
|
||||
Testing variant LogicalAndExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "LogicalAndExpression")
|
||||
Testing variant EqualityExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "EqualityExpression")
|
||||
Testing variant RelationalExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "RelationalExpression")
|
||||
Testing variant AdditiveExpressionSequence (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "AdditiveExpression")
|
||||
Testing variant TermSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Term")
|
||||
Testing variant FactorSequence (Loop = false) (Loopable = true)
|
||||
Begin validate subconstruct (type "Factor")
|
||||
Testing variant LiteralInteger (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "LITERAL_INTEGER"
|
||||
Fail: no valid variants (variant "LiteralInteger")
|
||||
|
||||
Testing variant ParenthesizedExpression (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "PARENTHESIS_OPEN"
|
||||
Fail: no valid variants (variant "ParenthesizedExpression")
|
||||
|
||||
Testing variant StandaloneVariable (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "VariableFactor")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "IDENTIFIER"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "StandaloneVariable")
|
||||
|
||||
Testing variant UnaryOperation (Loop = false) (Loopable = false)
|
||||
Begin validate subconstruct (type "UnaryOperator")
|
||||
Testing variant LogicalNegation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "LOGICAL_NEGATION"
|
||||
Fail: no valid variants (variant "LogicalNegation")
|
||||
|
||||
Testing variant BitwiseCompliment (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "BITWISE_COMPLIMENT"
|
||||
Fail: no valid variants (variant "BitwiseCompliment")
|
||||
|
||||
Testing variant Negation (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "NEGATION"
|
||||
Fail: no valid variants (variant "Negation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "UnaryOperation")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "FactorSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "TermSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "AdditiveExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "RelationalExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "EqualityExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalAndExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Fail: no valid variants (variant "LogicalOrExpressionSequence")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::DeclareVariable
|
||||
Begin validate subconstruct (type "VariableDeclaration")
|
||||
Testing variant Variable (Loop = false) (Loopable = false)
|
||||
Failed to validate token "}". Expected "INT"
|
||||
Fail: no valid variants (variant "Variable")
|
||||
|
||||
Subconstruct validation failed
|
||||
Testing Statement::ReturnExpression
|
||||
Failed to validate token "}". Expected "RETURN"
|
||||
Not looping
|
||||
Success (variant "StatementSequence")
|
||||
|
||||
End validate subconstruct (variant "StatementSequence")
|
||||
Validated token "}"
|
||||
Success (variant "Integer")
|
||||
|
||||
End validate subconstruct (variant "Integer")
|
||||
Success
|
||||
Reference in New Issue
Block a user