瀏覽代碼

Initial Commit

XCBOSA - ITX 3 年之前
當前提交
d148c0052a
共有 34 個文件被更改,包括 1020 次插入0 次删除
  1. 8 0
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/DerivedSources/Entitlements.plist
  2. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-all-non-framework-target-headers.hmap
  3. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-all-target-headers.hmap
  4. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-generated-files.hmap
  5. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-own-target-headers.hmap
  6. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-project-headers.hmap
  7. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser.hmap
  8. 8 0
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser.xcent
  9. 1 0
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/Exp2_Parser.LinkFileList
  10. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/Exp2_Parser_dependency_info.dat
  11. 15 0
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.d
  12. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.dia
  13. 二進制
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.o
  14. 1 0
      Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/all-product-headers.yaml
  15. 56 0
      Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-buildRequest.json
  16. 二進制
      Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-desc.xcbuild
  17. 26 0
      Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-manifest.xcbuild
  18. 2 0
      Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-targetGraph.txt
  19. 二進制
      Build/Intermediates.noindex/XCBuildData/BuildDescriptionCacheIndex-c57e5debe3527044ca3af3d5811ffdad
  20. 0 0
      Build/Intermediates.noindex/XCBuildData/PIFCache/project/PROJECT@v11_mod=1651224753.275216_hash=a2a5c39cd8018f7d4504734868576d43-json
  21. 0 0
      Build/Intermediates.noindex/XCBuildData/PIFCache/project/PROJECT@v11_mod=1651226291.5419998_hash=a2a5c39cd8018f7d4504734868576d43-json
  22. 1 0
      Build/Intermediates.noindex/XCBuildData/PIFCache/target/TARGET@v11_hash=22a3206993d1377ff5e9c99e52366784-json
  23. 1 0
      Build/Intermediates.noindex/XCBuildData/PIFCache/workspace/WORKSPACE@v11_hash=0eb2f7b7a2919c850ff82c3940872271_subobjects=7d6cf5a0bcf772b5b61e811e605a38c4-json
  24. 1 0
      Build/Intermediates.noindex/XCBuildData/PIFCache/workspace/WORKSPACE@v11_hash=0eb2f7b7a2919c850ff82c3940872271_subobjects=f2abbe75483d47a85f9c813f21a421ce-json
  25. 二進制
      Build/Intermediates.noindex/XCBuildData/build.db
  26. 二進制
      Build/Products/Debug/Exp2_Parser
  27. 286 0
      Exp2_Parser.xcodeproj/project.pbxproj
  28. 7 0
      Exp2_Parser.xcodeproj/project.xcworkspace/contents.xcworkspacedata
  29. 8 0
      Exp2_Parser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
  30. 79 0
      Exp2_Parser.xcodeproj/xcshareddata/xcschemes/Exp2_Parser.xcscheme
  31. 22 0
      Exp2_Parser.xcodeproj/xcuserdata/xcbosa.xcuserdatad/xcschemes/xcschememanagement.plist
  32. 420 0
      Exp2_Parser/main.c
  33. 66 0
      Exp2_Parser/output.txt
  34. 12 0
      Exp2_Parser/testfile.txt

+ 8 - 0
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/DerivedSources/Entitlements.plist

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.security.get-task-allow</key>
+	<true/>
+</dict>
+</plist>

二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-all-non-framework-target-headers.hmap


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-all-target-headers.hmap


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-generated-files.hmap


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-own-target-headers.hmap


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser-project-headers.hmap


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser.hmap


+ 8 - 0
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Exp2_Parser.xcent

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.security.get-task-allow</key>
+	<true/>
+</dict>
+</plist>

+ 1 - 0
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/Exp2_Parser.LinkFileList

@@ -0,0 +1 @@
+/Users/xcbosa/Desktop/Exp2_Parser/Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.o

二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/Exp2_Parser_dependency_info.dat


+ 15 - 0
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.d

@@ -0,0 +1,15 @@
+dependencies: /Users/xcbosa/Desktop/Exp2_Parser/Exp2_Parser/main.c \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/xcselect.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/kcdata.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/uuid.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/netinet6.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/machine.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/device.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/mach_debug.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/mach_machine.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/mach.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/bank.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/darwin_posix_sys_types.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/netinet.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/net.modulemap \
+  /Applications/Xcode13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/darwin_cdefs.modulemap

二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.dia


二進制
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/Objects-normal/x86_64/main.o


+ 1 - 0
Build/Intermediates.noindex/Exp2_Parser.build/Debug/Exp2_Parser.build/all-product-headers.yaml

@@ -0,0 +1 @@
+{"case-sensitive":"false","roots":[],"version":0}

+ 56 - 0
Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-buildRequest.json

@@ -0,0 +1,56 @@
+{
+  "_buildCommand2" : {
+    "command" : "build",
+    "skipDependencies" : false,
+    "style" : "buildAndRun"
+  },
+  "buildCommand" : "build",
+  "configuredTargets" : [
+    {
+      "guid" : "a2a5c39cd8018f7d4504734868576d43c8f93b9c4283e32d040773ab4679ba50"
+    }
+  ],
+  "containerPath" : "/Users/xcbosa/Desktop/Exp2_Parser/Exp2_Parser.xcodeproj",
+  "continueBuildingAfterErrors" : false,
+  "enableIndexBuildArena" : false,
+  "hideShellScriptEnvironment" : false,
+  "parameters" : {
+    "action" : "build",
+    "activeArchitecture" : "x86_64",
+    "activeRunDestination" : {
+      "disableOnlyActiveArch" : false,
+      "platform" : "macosx",
+      "sdk" : "macosx12.1",
+      "sdkVariant" : "macos",
+      "supportedArchitectures" : [
+        "x86_64"
+      ],
+      "targetArchitecture" : "x86_64"
+    },
+    "arenaInfo" : {
+      "buildIntermediatesPath" : "/Users/xcbosa/Desktop/Exp2_Parser/Build/Intermediates.noindex",
+      "buildProductsPath" : "/Users/xcbosa/Desktop/Exp2_Parser/Build/Products",
+      "derivedDataPath" : "/Users/xcbosa/Library/Developer/Xcode/DerivedData",
+      "indexDataStoreFolderPath" : "/Users/xcbosa/Library/Developer/Xcode/DerivedData/Exp2_Parser-gfxvxmulypxgmofwlfbzrhyrhjnv/Index/DataStore",
+      "indexEnableDataStore" : true,
+      "indexPCHPath" : "/Users/xcbosa/Library/Developer/Xcode/DerivedData/Exp2_Parser-gfxvxmulypxgmofwlfbzrhyrhjnv/Index/PrecompiledHeaders",
+      "pchPath" : "/Users/xcbosa/Desktop/Exp2_Parser/Build/Intermediates.noindex/PrecompiledHeaders"
+    },
+    "configurationName" : "Debug",
+    "overrides" : {
+      "synthesized" : {
+        "table" : {
+          "ENABLE_PREVIEWS" : "NO"
+        }
+      }
+    }
+  },
+  "schemeCommand" : "launch",
+  "schemeCommand2" : "launch",
+  "shouldCollectMetrics" : false,
+  "showNonLoggedProgress" : true,
+  "useDryRun" : false,
+  "useImplicitDependencies" : true,
+  "useLegacyBuildLocations" : false,
+  "useParallelTargets" : true
+}

二進制
Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-desc.xcbuild


文件差異過大導致無法顯示
+ 26 - 0
Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-manifest.xcbuild


+ 2 - 0
Build/Intermediates.noindex/XCBuildData/9f653fe16f6cf604d538eab9757c55da-targetGraph.txt

@@ -0,0 +1,2 @@
+Target dependency graph (1 target)
+Exp2_Parser in Exp2_Parser, no dependencies

二進制
Build/Intermediates.noindex/XCBuildData/BuildDescriptionCacheIndex-c57e5debe3527044ca3af3d5811ffdad


文件差異過大導致無法顯示
+ 0 - 0
Build/Intermediates.noindex/XCBuildData/PIFCache/project/PROJECT@v11_mod=1651224753.275216_hash=a2a5c39cd8018f7d4504734868576d43-json


文件差異過大導致無法顯示
+ 0 - 0
Build/Intermediates.noindex/XCBuildData/PIFCache/project/PROJECT@v11_mod=1651226291.5419998_hash=a2a5c39cd8018f7d4504734868576d43-json


+ 1 - 0
Build/Intermediates.noindex/XCBuildData/PIFCache/target/TARGET@v11_hash=22a3206993d1377ff5e9c99e52366784-json

@@ -0,0 +1 @@
+{"buildConfigurations":[{"buildSettings":{"CODE_SIGN_STYLE":"Automatic","DEVELOPMENT_TEAM":"QM43SUA9CG","ENABLE_HARDENED_RUNTIME":"YES","PRODUCT_NAME":"$(TARGET_NAME)"},"guid":"a2a5c39cd8018f7d4504734868576d430192063197f9eac135caa847c374ed9e","name":"Debug"},{"buildSettings":{"CODE_SIGN_STYLE":"Automatic","DEVELOPMENT_TEAM":"QM43SUA9CG","ENABLE_HARDENED_RUNTIME":"YES","PRODUCT_NAME":"$(TARGET_NAME)"},"guid":"a2a5c39cd8018f7d4504734868576d43ccd6ee589bfc0138be83e305e73ce2a0","name":"Release"}],"buildPhases":[{"buildFiles":[{"fileReference":"a2a5c39cd8018f7d4504734868576d43d6a07a7c83ac276359e2074d32186090","guid":"a2a5c39cd8018f7d4504734868576d43d1a9d1f71566f225c5104a0ee12f5ee8"}],"guid":"a2a5c39cd8018f7d4504734868576d43c98f44072bc7cf5edf0a833c9cbb6b24","type":"com.apple.buildphase.sources"},{"buildFiles":[],"guid":"a2a5c39cd8018f7d4504734868576d43b1663211da23c5bd687b4f296448bdd3","type":"com.apple.buildphase.frameworks"},{"buildFiles":[],"destinationSubfolder":"","destinationSubpath":"/usr/share/man/man1/","guid":"a2a5c39cd8018f7d4504734868576d43b57f8562d6b2887624a9170f658008f5","runOnlyForDeploymentPostprocessing":"true","type":"com.apple.buildphase.copy-files"}],"buildRules":[],"dependencies":[],"guid":"a2a5c39cd8018f7d4504734868576d43c8f93b9c4283e32d040773ab4679ba50","name":"Exp2_Parser","predominantSourceCodeLanguage":"Xcode.SourceCodeLanguage.C","productReference":{"guid":"a2a5c39cd8018f7d4504734868576d4378b7adc366e87941df8d5376396d51d4","name":"Exp2_Parser","type":"product"},"productTypeIdentifier":"com.apple.product-type.tool","provisioningSourceData":[{"bundleIdentifierFromInfoPlist":"","configurationName":"Debug","legacyTeamID":"","provisioningStyle":0},{"bundleIdentifierFromInfoPlist":"","configurationName":"Release","legacyTeamID":"","provisioningStyle":0}],"type":"standard"}

+ 1 - 0
Build/Intermediates.noindex/XCBuildData/PIFCache/workspace/WORKSPACE@v11_hash=0eb2f7b7a2919c850ff82c3940872271_subobjects=7d6cf5a0bcf772b5b61e811e605a38c4-json

@@ -0,0 +1 @@
+{"guid":"fa6be6e0302a19ec445fb3da8cd2677a","name":"Exp2_Parser","path":"/Users/xcbosa/Desktop/Exp2_Parser/Exp2_Parser.xcodeproj/project.xcworkspace","projects":["PROJECT@v11_mod=1651224753.275216_hash=a2a5c39cd8018f7d4504734868576d43"]}

+ 1 - 0
Build/Intermediates.noindex/XCBuildData/PIFCache/workspace/WORKSPACE@v11_hash=0eb2f7b7a2919c850ff82c3940872271_subobjects=f2abbe75483d47a85f9c813f21a421ce-json

@@ -0,0 +1 @@
+{"guid":"fa6be6e0302a19ec445fb3da8cd2677a","name":"Exp2_Parser","path":"/Users/xcbosa/Desktop/Exp2_Parser/Exp2_Parser.xcodeproj/project.xcworkspace","projects":["PROJECT@v11_mod=1651226291.5419998_hash=a2a5c39cd8018f7d4504734868576d43"]}

二進制
Build/Intermediates.noindex/XCBuildData/build.db


二進制
Build/Products/Debug/Exp2_Parser


+ 286 - 0
Exp2_Parser.xcodeproj/project.pbxproj

@@ -0,0 +1,286 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 55;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		75BCCDB2281BE831008E8808 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 75BCCDB1281BE831008E8808 /* main.c */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+		75BCCDAC281BE831008E8808 /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = /usr/share/man/man1/;
+			dstSubfolderSpec = 0;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+		755B1F1D281BEE330068C50B /* testfile.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = testfile.txt; sourceTree = "<group>"; };
+		75BCCDAE281BE831008E8808 /* Exp2_Parser */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Exp2_Parser; sourceTree = BUILT_PRODUCTS_DIR; };
+		75BCCDB1281BE831008E8808 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		75BCCDAB281BE831008E8808 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		75BCCDA5281BE831008E8808 = {
+			isa = PBXGroup;
+			children = (
+				75BCCDB0281BE831008E8808 /* Exp2_Parser */,
+				75BCCDAF281BE831008E8808 /* Products */,
+			);
+			sourceTree = "<group>";
+		};
+		75BCCDAF281BE831008E8808 /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				75BCCDAE281BE831008E8808 /* Exp2_Parser */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		75BCCDB0281BE831008E8808 /* Exp2_Parser */ = {
+			isa = PBXGroup;
+			children = (
+				75BCCDB1281BE831008E8808 /* main.c */,
+				755B1F1D281BEE330068C50B /* testfile.txt */,
+			);
+			path = Exp2_Parser;
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+		75BCCDAD281BE831008E8808 /* Exp2_Parser */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 75BCCDB5281BE831008E8808 /* Build configuration list for PBXNativeTarget "Exp2_Parser" */;
+			buildPhases = (
+				75BCCDAA281BE831008E8808 /* Sources */,
+				75BCCDAB281BE831008E8808 /* Frameworks */,
+				75BCCDAC281BE831008E8808 /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = Exp2_Parser;
+			productName = Exp2_Parser;
+			productReference = 75BCCDAE281BE831008E8808 /* Exp2_Parser */;
+			productType = "com.apple.product-type.tool";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		75BCCDA6281BE831008E8808 /* Project object */ = {
+			isa = PBXProject;
+			attributes = {
+				BuildIndependentTargetsInParallel = 1;
+				LastUpgradeCheck = 1320;
+				TargetAttributes = {
+					75BCCDAD281BE831008E8808 = {
+						CreatedOnToolsVersion = 13.2.1;
+					};
+				};
+			};
+			buildConfigurationList = 75BCCDA9281BE831008E8808 /* Build configuration list for PBXProject "Exp2_Parser" */;
+			compatibilityVersion = "Xcode 13.0";
+			developmentRegion = en;
+			hasScannedForEncodings = 0;
+			knownRegions = (
+				en,
+				Base,
+			);
+			mainGroup = 75BCCDA5281BE831008E8808;
+			productRefGroup = 75BCCDAF281BE831008E8808 /* Products */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				75BCCDAD281BE831008E8808 /* Exp2_Parser */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+		75BCCDAA281BE831008E8808 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				75BCCDB2281BE831008E8808 /* main.c in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+		75BCCDB3281BE831008E8808 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INFINITE_RECURSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				COPY_PHASE_STRIP = NO;
+				DEBUG_INFORMATION_FORMAT = dwarf;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				ENABLE_TESTABILITY = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 11.6;
+				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+				MTL_FAST_MATH = YES;
+				ONLY_ACTIVE_ARCH = YES;
+				SDKROOT = macosx;
+			};
+			name = Debug;
+		};
+		75BCCDB4281BE831008E8808 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_ANALYZER_NONNULL = YES;
+				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_ENABLE_OBJC_WEAK = YES;
+				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_COMMA = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INFINITE_RECURSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
+				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+				CLANG_WARN_STRICT_PROTOTYPES = YES;
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
+				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				COPY_PHASE_STRIP = NO;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				ENABLE_NS_ASSERTIONS = NO;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu11;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 11.6;
+				MTL_ENABLE_DEBUG_INFO = NO;
+				MTL_FAST_MATH = YES;
+				SDKROOT = macosx;
+			};
+			name = Release;
+		};
+		75BCCDB6281BE831008E8808 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				CODE_SIGN_STYLE = Automatic;
+				DEVELOPMENT_TEAM = QM43SUA9CG;
+				ENABLE_HARDENED_RUNTIME = YES;
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Debug;
+		};
+		75BCCDB7281BE831008E8808 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				CODE_SIGN_STYLE = Automatic;
+				DEVELOPMENT_TEAM = QM43SUA9CG;
+				ENABLE_HARDENED_RUNTIME = YES;
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		75BCCDA9281BE831008E8808 /* Build configuration list for PBXProject "Exp2_Parser" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				75BCCDB3281BE831008E8808 /* Debug */,
+				75BCCDB4281BE831008E8808 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		75BCCDB5281BE831008E8808 /* Build configuration list for PBXNativeTarget "Exp2_Parser" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				75BCCDB6281BE831008E8808 /* Debug */,
+				75BCCDB7281BE831008E8808 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 75BCCDA6281BE831008E8808 /* Project object */;
+}

+ 7 - 0
Exp2_Parser.xcodeproj/project.xcworkspace/contents.xcworkspacedata

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:">
+   </FileRef>
+</Workspace>

+ 8 - 0
Exp2_Parser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>IDEDidComputeMac32BitWarning</key>
+	<true/>
+</dict>
+</plist>

+ 79 - 0
Exp2_Parser.xcodeproj/xcshareddata/xcschemes/Exp2_Parser.xcscheme

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "1320"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "75BCCDAD281BE831008E8808"
+               BuildableName = "Exp2_Parser"
+               BlueprintName = "Exp2_Parser"
+               ReferencedContainer = "container:Exp2_Parser.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"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "YES"
+      customWorkingDirectory = "/Users/xcbosa/Desktop/Exp2_Parser/Exp2_Parser"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "75BCCDAD281BE831008E8808"
+            BuildableName = "Exp2_Parser"
+            BlueprintName = "Exp2_Parser"
+            ReferencedContainer = "container:Exp2_Parser.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "75BCCDAD281BE831008E8808"
+            BuildableName = "Exp2_Parser"
+            BlueprintName = "Exp2_Parser"
+            ReferencedContainer = "container:Exp2_Parser.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 22 - 0
Exp2_Parser.xcodeproj/xcuserdata/xcbosa.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>SchemeUserState</key>
+	<dict>
+		<key>Exp2_Parser.xcscheme_^#shared#^_</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>0</integer>
+		</dict>
+	</dict>
+	<key>SuppressBuildableAutocreation</key>
+	<dict>
+		<key>75BCCDAD281BE831008E8808</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+	</dict>
+</dict>
+</plist>

+ 420 - 0
Exp2_Parser/main.c

@@ -0,0 +1,420 @@
+//
+//  main.c
+//  Exp2_Parser
+//
+//  Created by xcbosa on 2022/4/29.
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define true 1
+#define false 0
+
+typedef char *String;
+typedef int Bool;
+
+Bool stringEquals(String left, String right) {
+    if (left == right) {
+        // 常量可以直接判断地址,地址相等串内容一定相等,加速比较
+        return true;
+    }
+    return strcmp(left, right) == 0;
+}
+
+String stringFromStackString(String stackString) {
+    String str = (String)calloc(strlen(stackString) + 1, sizeof(char));
+    strcpy(str, stackString);
+    return str;
+}
+
+// MARK: - 手动带缓存的File,C的File居然不能回退字符...
+
+typedef struct {
+    FILE *fp;
+    char buf[1024];
+    int bufSize;
+} CachedFile;
+
+typedef struct {
+    fpos_t fpos;
+    CachedFile lastState;
+} CachedFileFPos;
+
+CachedFile *cached_fopen(const String file) {
+    FILE *fp = fopen(file, "r");
+    CachedFile *cached = (CachedFile *)calloc(1, sizeof(CachedFile));
+    cached->fp = fp;
+    cached->bufSize = 0;
+    return cached;
+}
+
+char cached_fgetc(CachedFile *file) {
+    if (file->bufSize > 0) {
+        char ch = file->buf[file->bufSize - 1];
+        file->bufSize--;
+        return ch;
+    }
+    return fgetc(file->fp);
+}
+
+void cached_fputc(char ch, CachedFile *file) {
+    file->buf[file->bufSize] = ch;
+    file->bufSize++;
+}
+
+int cached_fgetpos(CachedFile *file, CachedFileFPos *pos) {
+    fpos_t fpos;
+    int ret = fgetpos(file->fp, &fpos);
+    pos->fpos = fpos;
+    pos->lastState = *file;
+    return ret;
+}
+
+int cached_fsetpos(CachedFile *file, CachedFileFPos *pos) {
+    memcpy(file->buf, pos->lastState.buf, 1024);
+    file->bufSize = pos->lastState.bufSize;
+    return fsetpos(file->fp, &pos->fpos);
+}
+
+// MARK: - Definitions
+
+// 根据指导书的常量串
+const String IDENFR = "IDENFR";
+const String INTCON = "INTCON";
+const String CHARCON = "CHARCON";
+const String STRCON = "STRCON";
+const String CONSTTK = "CONSTTK";
+const String INTTK = "INTTK";
+const String CHARTK = "CHARTK";
+const String VOIDTK = "VOIDTK";
+const String MAINTK = "MAINTK";
+const String IFTK = "IFTK";
+const String DOTK = "DOTK";
+
+const String ELSETK = "ELSETK";
+const String SWITCHTK = "SWITCHTK";
+const String CASETK = "CASETK";
+const String DEFAULTTK = "DEFAULTTK";
+const String WHILETK = "WHILETK";
+const String FORTK = "FORTK";
+const String SCANFTK = "SCANFTK";
+const String PRINTFTK = "PRINTFTK";
+const String RETURNTK = "RETURNTK";
+const String PLUS = "PLUS";
+
+const String MINU = "MINU";
+const String MULT = "MULT";
+const String DIV = "DIV";
+const String LSS = "LSS";
+const String LEQ = "LEQ";
+const String GRE = "GRE";
+const String GEQ = "GEQ";
+const String EQL = "EQL";
+const String NEQ = "NEQ";
+const String COLON = "COLON";
+
+const String ASSIGN = "ASSIGN";
+const String SEMICN = "SEMICN";
+const String COMMA = "COMMA";
+const String LPARENT = "LPARENT";
+const String RPARENT = "RPARENT";
+const String LBRACK = "LBRACK";
+const String RBRACK = "RBRACK";
+const String LBRACE = "LBRACE";
+const String RBRACE = "RBRACE";
+
+const String EOFTK = "EOF";
+
+struct Token;
+struct TokenRule;
+
+struct Token TokenEOF;
+
+// Token解析代码块,返回NULL代表规则无法解析
+typedef struct Token(*TokenBodyProviderBlock)(CachedFile*, struct TokenRule);
+
+typedef struct TokenRule {
+    String tokenBody;
+    String tokenTy;
+    // 解析规则
+    TokenBodyProviderBlock tokenBodyProvider;
+} TokenRule;
+
+typedef struct Token {
+    String tokenBody;
+    String tokenTy;
+    Bool isEmpty;
+} Token;
+
+const Token TokenEmpty = { NULL, NULL, true };
+
+/// 解析EOF
+/// @param file File
+/// @param rule 触发规则
+Token lexEOF(CachedFile *file, TokenRule rule);
+
+/// 字母单词解析,后边必须接一个非字母,防止局部认对(int -> in)
+/// @param file File
+/// @param rule 触发规则
+Token lexWords(CachedFile *file, TokenRule rule);
+
+/// 符号单词解析,后边无要求,需要确保rules中的顺序为先长后短防止局部认对(<= -> <)
+/// @param file File
+/// @param rule 触发规则
+Token lexSymbols(CachedFile *file, TokenRule rule);
+
+Token lexIDENFR(CachedFile *file, TokenRule rule);
+Token lexINTCON(CachedFile *file, TokenRule rule);
+Token lexCHARCON(CachedFile *file, TokenRule rule);
+Token lexSTRCON(CachedFile *file, TokenRule rule);
+
+TokenRule *rules;
+
+void doInitialization(void) {
+    TokenRule _rules[] = {
+        { NULL, EOFTK, &lexEOF },
+        { NULL, INTCON, &lexINTCON },
+        { NULL, CHARCON, &lexCHARCON },
+        { NULL, STRCON, &lexSTRCON },
+        { "const", CONSTTK, &lexWords },
+        { "int", INTTK, &lexWords },
+        { "char", CHARTK, &lexWords },
+        { "void", VOIDTK, &lexWords },
+        { "main", MAINTK, &lexWords },
+        { "if", IFTK, &lexWords },
+        { "do", DOTK, &lexWords },
+        { "else", ELSETK, &lexWords },
+        { "default", DEFAULTTK, &lexWords },
+        { "while", WHILETK, &lexWords },
+        { "for", FORTK, &lexWords },
+        { "scanf", SCANFTK, &lexWords },
+        { "printf", PRINTFTK, &lexWords },
+        { "return", RETURNTK, &lexWords },
+        { NULL, IDENFR, &lexIDENFR },
+        { "+", PLUS, &lexSymbols },
+        { "-", MINU, &lexSymbols },
+        { "*", MULT, &lexSymbols },
+        { "/", DIV, &lexSymbols },
+        { "<=", LEQ, &lexSymbols },
+        { "<", LSS, &lexSymbols },
+        { ">=", GEQ, &lexSymbols },
+        { ">", GRE, &lexSymbols },
+        { "==", EQL, &lexSymbols },
+        { "!=", NEQ, &lexSymbols },
+        { ":", COLON, &lexSymbols },
+        { "=", ASSIGN, &lexSymbols },
+        { ";", SEMICN, &lexSymbols },
+        { ",", COMMA, &lexSymbols },
+        { "(", LPARENT, &lexSymbols },
+        { ")", RPARENT, &lexSymbols },
+        { "[", LBRACK, &lexSymbols },
+        { "]", RBRACK, &lexSymbols },
+        { "{", LBRACE, &lexSymbols },
+        { "}", RBRACE, &lexSymbols },
+        { NULL, NULL, NULL }
+    };
+    rules = calloc(sizeof(_rules), 1);
+    memcpy(rules, _rules, sizeof(_rules));
+    TokenEOF.tokenTy = EOFTK;
+    TokenEOF.tokenBody = "";
+    TokenEOF.isEmpty = false;
+}
+
+Bool isAlphaOrNumberOrUnderline(char ch) {
+    return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_';
+}
+
+Bool isAlphaOrUnderline(char ch) {
+    return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_';
+}
+
+Bool isNumberOrXOrEOrPoint(char ch) {
+    return (ch >= '0' && ch <= '9') || ch == 'X' || ch == 'x' || ch == 'E' || ch == 'e' || ch == '.';
+}
+
+Bool isEmptyWord(char ch) {
+    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
+}
+
+// MARK: - Lex Implementation
+
+/// 按规则解析下一个单词
+/// @param file File
+Token lexNext(CachedFile *file) {
+    TokenRule *ruleIterator = &rules[0];
+    while (ruleIterator->tokenTy) {
+        char ch = '\0';
+        while (isEmptyWord(ch = cached_fgetc(file))) ;
+        cached_fputc(ch, file);
+        CachedFileFPos fpos;
+        cached_fgetpos(file, &fpos);
+        Token result = ruleIterator->tokenBodyProvider(file, *ruleIterator);
+        if (result.isEmpty) {
+            cached_fsetpos(file, &fpos);
+        } else {
+            return result;
+        }
+        ruleIterator++;
+    }
+    return TokenEmpty;
+}
+
+Token lexEOF(CachedFile *file, TokenRule rule) {
+    char ch = cached_fgetc(file);
+    if (ch == '\0') {
+        return TokenEOF;
+    }
+    cached_fputc(ch, file);
+    return TokenEmpty;
+}
+
+Token lexWords(CachedFile *file, TokenRule rule) {
+    char ch = '\0';
+    char *pexp = &rule.tokenBody[0];
+    while ((ch = cached_fgetc(file)) != '\0') {
+        if (*pexp == '\0') {
+            // 需要接非字母和数字
+            if (isAlphaOrNumberOrUnderline(ch)) {
+                return TokenEmpty;
+            }
+            cached_fputc(ch, file);
+            Token tk = { rule.tokenBody, rule.tokenTy, false };
+            return tk;
+        }
+        if (ch != *pexp) {
+            return TokenEmpty;
+        }
+        pexp++;
+    }
+    return TokenEOF;
+}
+
+Token lexSymbols(CachedFile *file, TokenRule rule) {
+    char ch = '\0';
+    char *pexp = &rule.tokenBody[0];
+    while ((ch = cached_fgetc(file)) != '\0') {
+        if (*pexp == '\0') {
+            cached_fputc(ch, file);
+            Token tk = { rule.tokenBody, rule.tokenTy, false };
+            return tk;
+        }
+        if (ch != *pexp) {
+            return TokenEmpty;
+        }
+        pexp++;
+    }
+    return TokenEOF;
+}
+
+Token lexIDENFR(CachedFile *file, TokenRule rule) {
+    char ch = '\0';
+    Bool first = true;
+    char tmp[1024], *pt = &tmp[0];
+    while ((ch = cached_fgetc(file)) != '\0') {
+        if (first) {
+            if (!isAlphaOrUnderline(ch)) {
+                return TokenEmpty;
+            }
+            first = false;
+        }
+        if (!isAlphaOrNumberOrUnderline(ch)) {
+            cached_fputc(ch, file);
+            if (pt != &tmp[0]) {
+                *(pt++) = '\0';
+                Token tk = { stringFromStackString(tmp), IDENFR, false };
+                return tk;
+            }
+        }
+        *(pt++) = ch;
+    }
+    return TokenEOF;
+}
+
+Token lexINTCON(CachedFile *file, TokenRule rule) {
+    char ch = '\0';
+    Bool first = true;
+    char tmp[1024], *pt = &tmp[0];
+    while ((ch = cached_fgetc(file)) != '\0') {
+        if (first) {
+            if (!(ch >= '0' && ch <= '9')) {
+                return TokenEmpty;
+            }
+            first = false;
+        }
+        if (!isNumberOrXOrEOrPoint(ch)) {
+            cached_fputc(ch, file);
+            if (pt != &tmp[0]) {
+                *(pt++) = '\0';
+                Token tk = { stringFromStackString(tmp), INTCON, false };
+                return tk;
+            }
+        }
+        *(pt++) = ch;
+    }
+    return TokenEOF;
+}
+
+Token lexCHARCON(CachedFile *file, TokenRule rule) {
+    char tmp[1024], *pt = &tmp[0];
+    if (cached_fgetc(file) != '\'') {
+        return TokenEmpty;
+    }
+    //*(pt++) = '\'';
+    char c1 = cached_fgetc(file);
+    *(pt++) = c1;
+    if (c1 == '\\') {
+        *(pt++) = cached_fgetc(file);
+    }
+    char end = cached_fgetc(file);
+    if (end == '\'') {
+        //*(pt++) = end;
+        *(pt++) = '\0';
+        Token tk = { stringFromStackString(tmp), CHARCON, false };
+        return tk;
+    }
+    printf("Error: Un breaking char constant: Expect ', but got %c", end);
+    exit(-1);
+}
+
+Token lexSTRCON(CachedFile *file, TokenRule rule) {
+    char tmp[1024], *pt = &tmp[0];
+    if (cached_fgetc(file) != '\"') {
+        return TokenEmpty;
+    }
+    //*(pt++) = '\"';
+    while (true) {
+        char ch = cached_fgetc(file);
+        if (ch != '\"')
+            *(pt++) = ch;
+        if (ch == '\\') {
+            char ch2 = cached_fgetc(file);
+            *(pt++) = ch2;
+        }
+        if (ch == '\"') {
+            break;
+        }
+        if (ch == '\0' || ch == '\n') {
+            printf("Error: Un breaking string constant, expect \", but got nothing");
+            exit(-1);
+        }
+    }
+    *(pt++) = '\0';
+    Token tk = { stringFromStackString(tmp), STRCON, false };
+    return tk;
+}
+
+int main(int argc, const char * argv[]) {
+    doInitialization();
+    CachedFile *fp = cached_fopen("testfile.txt");
+    FILE *wp = fopen("output.txt", "w+");
+    Token currentWord;
+    while (!(currentWord = lexNext(fp)).isEmpty) {
+        if (stringEquals(currentWord.tokenTy, EOFTK)) {
+            return 0;
+        }
+        fprintf(wp, "%s %s\n", currentWord.tokenTy, currentWord.tokenBody);
+    }
+    return 0;
+}

+ 66 - 0
Exp2_Parser/output.txt

@@ -0,0 +1,66 @@
+CONSTTK const
+INTTK int
+IDENFR const1
+ASSIGN =
+INTCON 1
+COMMA ,
+IDENFR const2
+ASSIGN =
+MINU -
+INTCON 100
+SEMICN ;
+CONSTTK const
+CHARTK char
+IDENFR const3
+ASSIGN =
+CHARCON _
+SEMICN ;
+INTTK int
+IDENFR change1
+SEMICN ;
+CHARTK char
+IDENFR change3
+SEMICN ;
+INTTK int
+IDENFR gets1
+LPARENT (
+INTTK int
+IDENFR var1
+COMMA ,
+INTTK int
+IDENFR var2
+RPARENT )
+LBRACE {
+IDENFR change1
+ASSIGN =
+IDENFR var1
+PLUS +
+IDENFR var2
+SEMICN ;
+RETURNTK return
+LPARENT (
+IDENFR change1
+RPARENT )
+SEMICN ;
+RBRACE }
+VOIDTK void
+MAINTK main
+LPARENT (
+RPARENT )
+LBRACE {
+PRINTFTK printf
+LPARENT (
+STRCON Hello World
+RPARENT )
+SEMICN ;
+PRINTFTK printf
+LPARENT (
+IDENFR gets1
+LPARENT (
+INTCON 10
+COMMA ,
+INTCON 20
+RPARENT )
+RPARENT )
+SEMICN ;
+RBRACE }

+ 12 - 0
Exp2_Parser/testfile.txt

@@ -0,0 +1,12 @@
+const int const1 = 1, const2 = -100;
+const char const3 = '_';
+int change1;
+char change3;
+int gets1(int var1,int var2){
+    change1 = var1 + var2;
+    return (change1);
+}
+void main(){
+    printf("Hello World");
+    printf(gets1(10, 20));
+}

部分文件因文件數量過多而無法顯示