Skip to content

Commit b955dce

Browse files
authoredJul 16, 2020
Add files via upload
1 parent b1853ee commit b955dce

28 files changed

+601
-0
lines changed
 
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Build started 4/20/2020 4:43:30 PM.
2+
1>Project "C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Exercise8\Exercise8.vcxproj" on node 2 (Build target(s)).
3+
1>ClCompile:
4+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"stdafx.h" /Fp"Debug\Exercise8.pch" /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt lexicalUnitt.cpp
5+
lexicalUnitt.cpp
6+
Link:
7+
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Debug\Exercise8.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Debug\Exercise8.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Debug\Exercise8.lib" /MACHINE:X86 Debug\binTree.obj
8+
Debug\descriptor.obj
9+
Debug\lexicalUnitt.obj
10+
Debug\main.obj
11+
Debug\stdafx.obj
12+
Exercise8.vcxproj -> C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Debug\Exercise8.exe
13+
1>Done Building Project "C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\Exercise8\Exercise8.vcxproj" (Build target(s)).
14+
15+
Build succeeded.
16+
17+
Time Elapsed 00:00:03.33
1.56 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
2+
Debug|Win32|C:\Users\malin\Desktop\Elly\OOP\LexicalUnit\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
162 KB
Binary file not shown.
139 KB
Binary file not shown.
158 KB
Binary file not shown.

‎LexicalUnit/Exercise8/Debug/main.obj

156 KB
Binary file not shown.
11.4 KB
Binary file not shown.

‎LexicalUnit/Exercise8/Debug/vc120.idb

371 KB
Binary file not shown.

‎LexicalUnit/Exercise8/Debug/vc120.pdb

404 KB
Binary file not shown.
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{8E6BD1B4-ACAF-4F7C-A5BD-781FF7D32E7D}</ProjectGuid>
15+
<Keyword>Win32Proj</Keyword>
16+
<RootNamespace>Exercise8</RootNamespace>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20+
<ConfigurationType>Application</ConfigurationType>
21+
<UseDebugLibraries>true</UseDebugLibraries>
22+
<PlatformToolset>v120</PlatformToolset>
23+
<CharacterSet>Unicode</CharacterSet>
24+
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26+
<ConfigurationType>Application</ConfigurationType>
27+
<UseDebugLibraries>false</UseDebugLibraries>
28+
<PlatformToolset>v120</PlatformToolset>
29+
<WholeProgramOptimization>true</WholeProgramOptimization>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33+
<ImportGroup Label="ExtensionSettings">
34+
</ImportGroup>
35+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37+
</ImportGroup>
38+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<PropertyGroup Label="UserMacros" />
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43+
<LinkIncremental>true</LinkIncremental>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46+
<LinkIncremental>false</LinkIncremental>
47+
</PropertyGroup>
48+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49+
<ClCompile>
50+
<PrecompiledHeader>Use</PrecompiledHeader>
51+
<WarningLevel>Level3</WarningLevel>
52+
<Optimization>Disabled</Optimization>
53+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
54+
<SDLCheck>true</SDLCheck>
55+
</ClCompile>
56+
<Link>
57+
<SubSystem>Console</SubSystem>
58+
<GenerateDebugInformation>true</GenerateDebugInformation>
59+
</Link>
60+
</ItemDefinitionGroup>
61+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62+
<ClCompile>
63+
<WarningLevel>Level3</WarningLevel>
64+
<PrecompiledHeader>Use</PrecompiledHeader>
65+
<Optimization>MaxSpeed</Optimization>
66+
<FunctionLevelLinking>true</FunctionLevelLinking>
67+
<IntrinsicFunctions>true</IntrinsicFunctions>
68+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
69+
<SDLCheck>true</SDLCheck>
70+
</ClCompile>
71+
<Link>
72+
<SubSystem>Console</SubSystem>
73+
<GenerateDebugInformation>true</GenerateDebugInformation>
74+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
75+
<OptimizeReferences>true</OptimizeReferences>
76+
</Link>
77+
</ItemDefinitionGroup>
78+
<ItemGroup>
79+
<ClInclude Include="binTree.h" />
80+
<ClInclude Include="descriptor.h" />
81+
<ClInclude Include="lexicalUnitt.h" />
82+
<ClInclude Include="stdafx.h" />
83+
<ClInclude Include="targetver.h" />
84+
</ItemGroup>
85+
<ItemGroup>
86+
<ClCompile Include="binTree.cpp" />
87+
<ClCompile Include="descriptor.cpp" />
88+
<ClCompile Include="lexicalUnitt.cpp" />
89+
<ClCompile Include="main.cpp" />
90+
<ClCompile Include="stdafx.cpp">
91+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
92+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
93+
</ClCompile>
94+
</ItemGroup>
95+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
96+
<ImportGroup Label="ExtensionTargets">
97+
</ImportGroup>
98+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="stdafx.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
<ClInclude Include="targetver.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
<ClInclude Include="descriptor.h">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
27+
<ClInclude Include="lexicalUnitt.h">
28+
<Filter>Header Files</Filter>
29+
</ClInclude>
30+
</ItemGroup>
31+
<ItemGroup>
32+
<ClCompile Include="stdafx.cpp">
33+
<Filter>Source Files</Filter>
34+
</ClCompile>
35+
<ClCompile Include="main.cpp">
36+
<Filter>Source Files</Filter>
37+
</ClCompile>
38+
<ClCompile Include="descriptor.cpp">
39+
<Filter>Source Files</Filter>
40+
</ClCompile>
41+
<ClCompile Include="lexicalUnitt.cpp">
42+
<Filter>Source Files</Filter>
43+
</ClCompile>
44+
</ItemGroup>
45+
</Project>

‎LexicalUnit/Exercise8/binTree.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include "stdafx.h"
2+
#include "lexicalUnitt.h"
3+
#include "binTree.h"
4+
#include <string.h>
5+
#include <iostream>
6+
7+
using namespace std;
8+
//--------------------------------------------------------------------------------------------------------
9+
btree::btree()
10+
{
11+
root = NULL;
12+
}
13+
//--------------------------------------------------------------------------------------------------------
14+
btree::~btree()
15+
{
16+
destroy_tree();
17+
}
18+
//--------------------------------------------------------------------------------------------------------
19+
void btree::insert(lexicalUnit &lu)
20+
{
21+
if (root != NULL)
22+
insert(lu, root);
23+
else
24+
{
25+
root = new node;
26+
root->key_value = lu;
27+
root->left = NULL;
28+
root->right = NULL;
29+
}
30+
}
31+
//--------------------------------------------------------------------------------------------------------
32+
void btree::insert(lexicalUnit &lu, node *leaf)
33+
{
34+
if (strcmp(lu.getIdentificator(), leaf->key_value.getIdentificator()) < 0)
35+
{
36+
if (leaf->left != NULL)
37+
insert(lu, leaf->left);
38+
else
39+
{
40+
leaf->left = new node;
41+
leaf->left->key_value = lu;
42+
leaf->left->left = NULL;
43+
leaf->left->right = NULL;
44+
}
45+
}
46+
else if (strcmp(lu.getIdentificator(), leaf->key_value.getIdentificator()) >= 0)
47+
{
48+
if (leaf->right != NULL)
49+
insert(lu, leaf->right);
50+
else
51+
{
52+
leaf->right = new node;
53+
leaf->right->key_value = lu;
54+
leaf->right->left = NULL;
55+
leaf->right->right = NULL;
56+
}
57+
}
58+
}
59+
//--------------------------------------------------------------------------------------------------------
60+
node *btree::search(char *pIdentificator)
61+
{
62+
return search(pIdentificator, root);
63+
}
64+
//--------------------------------------------------------------------------------------------------------
65+
node *btree::search(char *pIdentificator, node *leaf)
66+
{
67+
if (leaf != NULL)
68+
{
69+
if (strcmp(pIdentificator, leaf->lu.getIdentificator()) == 0)
70+
return leaf;
71+
if (strcmp(pIdentificator, leaf->lu.getIdentificator()) < 0)
72+
return search(pIdentificator, leaf->left);
73+
else
74+
return search(pIdentificator, leaf->right);
75+
}
76+
else return NULL;
77+
}
78+
//--------------------------------------------------------------------------------------------------------
79+
void btree::destroy_tree()
80+
{
81+
destroy_tree(root);
82+
}
83+
//--------------------------------------------------------------------------------------------------------
84+
void btree::destroy_tree(node *leaf)
85+
{
86+
if (leaf != NULL)
87+
{
88+
destroy_tree(leaf->left);
89+
destroy_tree(leaf->right);
90+
delete leaf;
91+
}
92+
}
93+
//--------------------------------------------------------------------------------------------------------
94+
void btree::print()
95+
{
96+
print(root, 0);
97+
}
98+
//--------------------------------------------------------------------------------------------------------
99+
void btree::print(node *leaf, int delta)
100+
{
101+
int i;
102+
if (leaf != NULL)
103+
{
104+
if (leaf->right)
105+
print(leaf->right, delta + 1);
106+
for (i = 1; i <= delta; i++)
107+
cout << "\t";
108+
leaf->key_value.print();
109+
cout << endl;
110+
if (leaf->left)
111+
print(leaf->left, delta + 1);
112+
}
113+
}
114+
//--------------------------------------------------------------------------------------------------------

‎LexicalUnit/Exercise8/binTree.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
#include "lexicalUnitt.h"
3+
4+
//--------------------------------------------------------------------------------------------------------
5+
struct node {
6+
lexicalUnit lu;
7+
lexicalUnit key_value;
8+
node *left;
9+
node *right;
10+
};
11+
class btree {
12+
private:
13+
void destroy_tree(node *leaf);
14+
void insert(lexicalUnit &lu, node *leaf);
15+
node *search(char *pIdentificator, node *leaf);
16+
void print(node *leaf, int delta);
17+
node *root;
18+
public:
19+
btree();
20+
~btree();
21+
void insert(lexicalUnit &lu);
22+
node *search(char *pIdentificator);
23+
void destroy_tree();
24+
void print();
25+
};

‎LexicalUnit/Exercise8/descriptor.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "stdafx.h"
2+
#include "descriptor.h"
3+
#include <string.h>
4+
#include <iostream>
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
8+
//--------------------------------------------------------------------------------------------------------
9+
descriptors::descriptors()
10+
{
11+
number = 0;
12+
}
13+
//--------------------------------------------------------------------------------------------------------
14+
descriptors::~descriptors()
15+
{
16+
}
17+
//--------------------------------------------------------------------------------------------------------
18+
int descriptors::add(lexicalUnit &lu)
19+
{
20+
if (number >= 100)
21+
return 0;
22+
if (!lu.isValid())
23+
return 0;
24+
if (search(lu.getIdentificator()) >= 0)
25+
return 0;
26+
else {
27+
table[number] = lu;
28+
number++;
29+
return 1;
30+
}
31+
}
32+
//--------------------------------------------------------------------------------------------------------
33+
int descriptors::del(char *pIdentificator)
34+
{
35+
if (number == 0)
36+
return 0;
37+
if (search(pIdentificator) >= 0)
38+
{
39+
for (int i = search(pIdentificator); i < number - 1; i++)
40+
{
41+
table[i] = table[i + 1];
42+
}
43+
number--;
44+
return 1;
45+
}
46+
return 0;
47+
}
48+
//--------------------------------------------------------------------------------------------------------
49+
int descriptors::search(char *pIdentificator)
50+
{
51+
for (int i = 0; i < number; i++)
52+
{
53+
if (strcmp(table[i].getIdentificator(), pIdentificator) == 0)
54+
return i;
55+
}
56+
return -1;
57+
}
58+
//--------------------------------------------------------------------------------------------------------
59+
void descriptors::print()
60+
{
61+
for (int i = 0; i < number; i++)
62+
table[i].print();
63+
}
64+
//--------------------------------------------------------------------------------------------------------

‎LexicalUnit/Exercise8/descriptor.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
#include "lexicalUnitt.h"
3+
4+
//--------------------------------------------------------------------------------------------------------
5+
class descriptors
6+
{
7+
lexicalUnit table[100];
8+
int number; //брой лексически единици
9+
public:
10+
descriptors();
11+
~descriptors();
12+
int add(lexicalUnit &lu); // връща 1, при успешно добавяне и 0 в противен случай
13+
int del(char *pIdentificator); // връща 1, при успешно изтриване и 0 в противен случай
14+
int search(char *pIdentificator); // връща позицията на лексическата единица в масива или -1 в противен случай
15+
void print();
16+
};
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include "stdafx.h"
2+
#include "lexicalUnitt.h"
3+
#include <string.h>
4+
#include <stdio.h>
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
lexicalUnit::lexicalUnit()
10+
{
11+
identificator[0] = 0;
12+
type[0] = 0;
13+
descriptor[0] = 0;
14+
address = 0;
15+
}
16+
//--------------------------------------------------------------------------------------------------------
17+
lexicalUnit::~lexicalUnit()
18+
{
19+
}
20+
//--------------------------------------------------------------------------------------------------------
21+
int lexicalUnit::setAddress(char *type)
22+
{
23+
address = newAddress; //полето на класа получава стойността на статичната променлива, след което тя се променя според типа
24+
int size = 0;
25+
if (strcmp(type, "int") == 0)
26+
size = 2;
27+
else if (strcmp(type, "char") == 0)
28+
size = 1;
29+
else if (strcmp(type, "float") == 0)
30+
size = 4;
31+
else if (strcmp(type, "double") == 0)
32+
size = 8;
33+
34+
newAddress += size;
35+
return newAddress;
36+
}
37+
//--------------------------------------------------------------------------------------------------------
38+
void lexicalUnit::setDescriptor()
39+
{
40+
sprintf_s(descriptor, "V%d", newDescriptor);
41+
newDescriptor++;
42+
}
43+
//--------------------------------------------------------------------------------------------------------
44+
lexicalUnit::lexicalUnit(char *pIdentificator, char *pType)
45+
{
46+
strcpy_s(identificator, pIdentificator);
47+
strcpy_s(type, pType);
48+
setDescriptor();
49+
setAddress(pType);
50+
}
51+
//--------------------------------------------------------------------------------------------------------
52+
lexicalUnit &lexicalUnit::operator=(lexicalUnit& lu)
53+
{
54+
strcpy_s(identificator, lu.identificator);
55+
strcpy_s(type, lu.type);
56+
strcpy_s(descriptor, lu.descriptor);
57+
address = lu.address;
58+
59+
return *this;
60+
}
61+
//--------------------------------------------------------------------------------------------------------
62+
char *lexicalUnit::getIdentificator()
63+
{
64+
return identificator;
65+
}
66+
//--------------------------------------------------------------------------------------------------------
67+
void lexicalUnit::print()
68+
{
69+
cout << identificator << "\t" << type << "\t" << descriptor << "\t" << address << endl;
70+
}
71+
//--------------------------------------------------------------------------------------------------------
72+
int lexicalUnit::isValid()
73+
{
74+
if (strcmp(type, "int") == 0)
75+
return 1;
76+
else if (strcmp(type, "char") == 0)
77+
return 1;
78+
else if (strcmp(type, "float") == 0)
79+
return 1;
80+
else if (strcmp(type, "double") == 0)
81+
return 1;
82+
else
83+
return 0;
84+
}
85+
//--------------------------------------------------------------------------------------------------------

‎LexicalUnit/Exercise8/lexicalUnitt.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
//--------------------------------------------------------------------------------------------------------
4+
class lexicalUnit
5+
{
6+
char identificator[20];
7+
char type[20];
8+
char descriptor[5];
9+
int address;
10+
public:
11+
static int newAddress; // статична променлива, указваща адреса, на който да се запише текущата единица
12+
static int newDescriptor; // статична променлива, указваща текущия дескриптор
13+
lexicalUnit();
14+
lexicalUnit(char *pIdentificator, char *pType);
15+
lexicalUnit& operator=(lexicalUnit& lu);
16+
~lexicalUnit();
17+
int setAddress(char *type); // метод, който задава адреса и генерира следващия свободен адрес,
18+
//според типа,който има тази лексическа единица
19+
void setDescriptor(); // метод, който задава дескриптора и генерира следващия
20+
char* getIdentificator(); // метод, който връща идентификатора
21+
void print();
22+
int isValid();
23+
};

‎LexicalUnit/Exercise8/main.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Exercise8.cpp : Defines the entry point for the console application.
2+
//
3+
4+
#include "stdafx.h"
5+
#include <iostream>
6+
#include <fstream>
7+
#include <stdlib.h>
8+
#include <stdio.h>
9+
#include "descriptor.h"
10+
#include "lexicalUnitt.h"
11+
#include "binTree.h"
12+
13+
using namespace std;
14+
15+
int lexicalUnit::newAddress = 0; // инициализация на статична променлива
16+
int lexicalUnit::newDescriptor = 1; // инициализация на статична променлива
17+
18+
int isValid(char *type);
19+
//--------------------------------------------------------------------------------------------------------
20+
int _tmain(int argc, _TCHAR* argv[])
21+
{
22+
btree D;
23+
24+
FILE* inFile;
25+
char buffer[50];
26+
char typ[20];
27+
char ident[20];
28+
errno_t err;
29+
30+
err = fopen_s(&inFile, "C:\\Users\\malin\\Desktop\\Elly\\OOP\\LexicalUnit\\file.txt", "r");
31+
if (err != 0) {
32+
cout << "Unable to open file file.txt" << endl;
33+
exit(1); // call system to stop
34+
}
35+
36+
while (!feof(inFile)) {
37+
fgets(buffer, 49, inFile);
38+
int i = 0;
39+
while (buffer[i] != ' ') {
40+
typ[i] = buffer[i];
41+
i++;
42+
}
43+
typ[i] = '\0';
44+
i++;
45+
int j = 0;
46+
while (buffer[i] != ';') {
47+
ident[j] = buffer[i];
48+
i++;
49+
j++;
50+
}
51+
ident[j] = '\0';
52+
if (isValid(typ))
53+
{
54+
lexicalUnit lu(ident, typ);
55+
D.insert(lu);
56+
}
57+
}
58+
59+
D.print();
60+
D.destroy_tree();
61+
cout << endl;
62+
D.print();
63+
cout << endl;
64+
fclose(inFile);
65+
return 0;
66+
}
67+
//--------------------------------------------------------------------------------------------------------
68+
int isValid(char *type)
69+
{
70+
if (strcmp(type, "int") == 0)
71+
return 1;
72+
else if (strcmp(type, "char") == 0)
73+
return 1;
74+
else if (strcmp(type, "float") == 0)
75+
return 1;
76+
else if (strcmp(type, "double") == 0)
77+
return 1;
78+
else
79+
return 0;
80+
}
81+
//--------------------------------------------------------------------------------------------------------

‎LexicalUnit/Exercise8/stdafx.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// stdafx.cpp : source file that includes just the standard includes
2+
// Exercise8.pch will be the pre-compiled header
3+
// stdafx.obj will contain the pre-compiled type information
4+
5+
#include "stdafx.h"
6+
7+
// TODO: reference any additional headers you need in STDAFX.H
8+
// and not in this file

‎LexicalUnit/Exercise8/stdafx.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// stdafx.h : include file for standard system include files,
2+
// or project specific include files that are used frequently, but
3+
// are changed infrequently
4+
//
5+
6+
#pragma once
7+
8+
#include "targetver.h"
9+
10+
#include <stdio.h>
11+
#include <tchar.h>
12+
13+
14+
15+
// TODO: reference additional headers your program requires here

‎LexicalUnit/Exercise8/targetver.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
// Including SDKDDKVer.h defines the highest available Windows platform.
4+
5+
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6+
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7+
8+
#include <SDKDDKVer.h>

0 commit comments

Comments
 (0)
Please sign in to comment.