Skip to content

Commit

Permalink
lab4
Browse files Browse the repository at this point in the history
lab4
  • Loading branch information
ddanilyuk authored Oct 29, 2020
2 parents bd9534f + df21a86 commit 043e0ae
Show file tree
Hide file tree
Showing 35 changed files with 363 additions and 323 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

### You can:

- Compile functions with local variables.
- Compile functions, blocs with local variables and ternary operators.

### Example:

![1](images/1.png)
![2](images/2.png)
![3](images/3.png)
![3](images/3.png)
![4](images/4.png)
![5](images/5.png)
![6](images/6.png)
293 changes: 139 additions & 154 deletions clangCompiler.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FCC19AF251A40AD00589EF7"
BuildableName = "clangCompiler.app"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -44,8 +44,8 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FCC19AF251A40AD00589EF7"
BuildableName = "clangCompiler.app"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
Expand All @@ -61,8 +61,8 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FCC19AF251A40AD00589EF7"
BuildableName = "clangCompiler.app"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "/Users/denisdanilyuk/clangCompiler/clangCompiler/4-07-Swift-IV-82-Danyliuk.swift"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5FBB1405254ACF5F00C49A43"
BuildableName = "clangCompiler"
BlueprintName = "clangCompiler"
ReferencedContainer = "container:clangCompiler.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "4EE075CF-52E2-4010-9177-654C2DA8B488"
uuid = "DA3516B2-44C2-4C18-B1F4-3D22621EE43D"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C8A0FA56-C175-4EA6-9EFD-1C2972570109"
uuid = "6874F0D7-B543-4AD6-AFC8-6F2DC385ECCD"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "lab1SP/Main/Parser.swift"
filePath = "clangCompiler/Source/Parser.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "99"
endingLineNumber = "99"
landmarkName = "parseReturn()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "ED418500-C3A9-4F54-80CB-2CFEC4265B08"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "clangCompiler/Main/Parser.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "314"
endingLineNumber = "314"
landmarkName = "parseFunctionDeclaration(valueType:identifier:)"
startingLineNumber = "157"
endingLineNumber = "157"
landmarkName = "parseExpression()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>clangCompiler2.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>5FCC19AF251A40AD00589EF7</key>
<key>5FBB1405254ACF5F00C49A43</key>
<dict>
<key>primary</key>
<true/>
Expand Down
82 changes: 0 additions & 82 deletions clangCompiler/AppDelegate.swift

This file was deleted.

29 changes: 29 additions & 0 deletions clangCompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
add_executable(4-07-Swift-IV-82-Danyliuk
4-07-Swift-IV-82-Danyliuk.swift)

# add_subdirectory(Sources)
target_sources(4-07-Swift-IV-82-Danyliuk PRIVATE
Source/Block.swift
Source/CompilerError.swift
Source/Extensions.swift
Source/Lexer.swift
Source/ProtocolsAndEnums.swift
Source/Parser.swift
Source/Token.swift

Source/Nodes/FunctionDefinitionNode.swift
Source/Nodes/NumberNode.swift
Source/Nodes/ReturnNode.swift
Source/Nodes/TernaryNode.swift
Source/Nodes/UnaryNegativeNode.swift
Source/Nodes/CustomIntNode.swift
Source/Nodes/BinaryOperationNode.swift
Source/Nodes/VariableNode.swift


Source/TreePrinter/TreePrinter.swift
Source/TreePrinter/TreeRepresentable.swift
)

target_compile_options(4-07-Swift-IV-82-Danyliuk PRIVATE -parse-as-library)
target_link_libraries(4-07-Swift-IV-82-Danyliuk PRIVATE SwiftWin32)
43 changes: 0 additions & 43 deletions clangCompiler/Info.plist

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Block: Node {
}
"""
case .function:
let esp = "\nsub esp, \(Parser.maxIdentifires * 4)\n"
let esp = Parser.maxIdentifires != 0 ? "\nsub esp, \(Parser.maxIdentifires * 4)\n" : "\n"
result += """
; Start function header
push ebp
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ extension Parser {

let node = try parseValue()

if checkToken() == Token.questionMark {
return try parseTernaryOperator(node: node)
if canCheckToken {
if checkToken() == Token.questionMark {
return try parseTernaryOperator(node: node)
} else {
return try parseInfixOperation(node: node)
}
} else {
return try parseInfixOperation(node: node)
throw CompilerError.unexpectedError(Parser.globalTokenIndex - 1)
}

}

func parseTernaryOperator(node: Node) throws -> Node {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ enum Token: Equatable {
"\\?": { _ in .questionMark },
"\\:": { _ in .colon },


/// For words and keywords
"[a-zA-Z_$][a-zA-Z_$0-9]*": {
if $0 == "return" {
Expand Down
Loading

0 comments on commit 043e0ae

Please sign in to comment.