Skip to content

Commit a39c70a

Browse files
committedJun 29, 2023
Initial commit
0 parents  commit a39c70a

22 files changed

+1199
-0
lines changed
 

‎.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
34+
# Visual Studio
35+
.vs/
36+
Debug/
37+
Release/
38+
x64/

‎LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎OAT.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29318.209
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OAT", "OAT.vcxproj", "{0A9AE364-3219-425B-98E9-0F8028C757DD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Debug|x64.ActiveCfg = Debug|x64
17+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Debug|x64.Build.0 = Debug|x64
18+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Debug|x86.ActiveCfg = Debug|Win32
19+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Debug|x86.Build.0 = Debug|Win32
20+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Release|x64.ActiveCfg = Release|x64
21+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Release|x64.Build.0 = Release|x64
22+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Release|x86.ActiveCfg = Release|Win32
23+
{0A9AE364-3219-425B-98E9-0F8028C757DD}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {0D836D8F-2020-45E0-B22C-9DC3661F30D3}
30+
EndGlobalSection
31+
EndGlobal

‎OAT.vcxproj

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" 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+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClInclude Include="src\Constants.h" />
23+
<ClInclude Include="src\OAT.h" />
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClCompile Include="src\main.cpp" />
27+
<ClCompile Include="src\OAT.cpp" />
28+
</ItemGroup>
29+
<PropertyGroup Label="Globals">
30+
<VCProjectVersion>16.0</VCProjectVersion>
31+
<ProjectGuid>{0a9ae364-3219-425b-98e9-0f8028c757dd}</ProjectGuid>
32+
<Keyword>Win32Proj</Keyword>
33+
<RootNamespace>OAT</RootNamespace>
34+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
35+
</PropertyGroup>
36+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>true</UseDebugLibraries>
40+
<PlatformToolset>v142</PlatformToolset>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>false</UseDebugLibraries>
46+
<PlatformToolset>v142</PlatformToolset>
47+
<WholeProgramOptimization>true</WholeProgramOptimization>
48+
<CharacterSet>Unicode</CharacterSet>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
51+
<ConfigurationType>Application</ConfigurationType>
52+
<UseDebugLibraries>true</UseDebugLibraries>
53+
<PlatformToolset>v142</PlatformToolset>
54+
<CharacterSet>Unicode</CharacterSet>
55+
</PropertyGroup>
56+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
57+
<ConfigurationType>Application</ConfigurationType>
58+
<UseDebugLibraries>false</UseDebugLibraries>
59+
<PlatformToolset>v142</PlatformToolset>
60+
<WholeProgramOptimization>true</WholeProgramOptimization>
61+
<CharacterSet>Unicode</CharacterSet>
62+
</PropertyGroup>
63+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
64+
<ImportGroup Label="ExtensionSettings">
65+
</ImportGroup>
66+
<ImportGroup Label="Shared">
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
72+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
73+
</ImportGroup>
74+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
75+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
76+
</ImportGroup>
77+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
78+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
79+
</ImportGroup>
80+
<PropertyGroup Label="UserMacros" />
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
82+
<LinkIncremental>true</LinkIncremental>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
85+
<LinkIncremental>true</LinkIncremental>
86+
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
88+
<LinkIncremental>false</LinkIncremental>
89+
</PropertyGroup>
90+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
91+
<LinkIncremental>false</LinkIncremental>
92+
</PropertyGroup>
93+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
94+
<ClCompile>
95+
<PrecompiledHeader>
96+
</PrecompiledHeader>
97+
<WarningLevel>Level3</WarningLevel>
98+
<Optimization>Disabled</Optimization>
99+
<SDLCheck>true</SDLCheck>
100+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
101+
<ConformanceMode>true</ConformanceMode>
102+
<DisableLanguageExtensions>true</DisableLanguageExtensions>
103+
<TreatWarningAsError>true</TreatWarningAsError>
104+
<LanguageStandard>stdcpp17</LanguageStandard>
105+
</ClCompile>
106+
<Link>
107+
<SubSystem>Console</SubSystem>
108+
<GenerateDebugInformation>true</GenerateDebugInformation>
109+
</Link>
110+
</ItemDefinitionGroup>
111+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
112+
<ClCompile>
113+
<PrecompiledHeader>
114+
</PrecompiledHeader>
115+
<WarningLevel>Level3</WarningLevel>
116+
<Optimization>Disabled</Optimization>
117+
<SDLCheck>true</SDLCheck>
118+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119+
<ConformanceMode>true</ConformanceMode>
120+
<DisableLanguageExtensions>true</DisableLanguageExtensions>
121+
<TreatWarningAsError>true</TreatWarningAsError>
122+
<LanguageStandard>stdcpp17</LanguageStandard>
123+
</ClCompile>
124+
<Link>
125+
<SubSystem>Console</SubSystem>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
130+
<ClCompile>
131+
<PrecompiledHeader>
132+
</PrecompiledHeader>
133+
<WarningLevel>Level3</WarningLevel>
134+
<Optimization>MaxSpeed</Optimization>
135+
<FunctionLevelLinking>true</FunctionLevelLinking>
136+
<IntrinsicFunctions>true</IntrinsicFunctions>
137+
<SDLCheck>true</SDLCheck>
138+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139+
<ConformanceMode>true</ConformanceMode>
140+
<DisableLanguageExtensions>true</DisableLanguageExtensions>
141+
<TreatWarningAsError>true</TreatWarningAsError>
142+
<LanguageStandard>stdcpp17</LanguageStandard>
143+
</ClCompile>
144+
<Link>
145+
<SubSystem>Console</SubSystem>
146+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
147+
<OptimizeReferences>true</OptimizeReferences>
148+
<GenerateDebugInformation>true</GenerateDebugInformation>
149+
</Link>
150+
</ItemDefinitionGroup>
151+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
152+
<ClCompile>
153+
<PrecompiledHeader>
154+
</PrecompiledHeader>
155+
<WarningLevel>Level3</WarningLevel>
156+
<Optimization>MaxSpeed</Optimization>
157+
<FunctionLevelLinking>true</FunctionLevelLinking>
158+
<IntrinsicFunctions>true</IntrinsicFunctions>
159+
<SDLCheck>true</SDLCheck>
160+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
161+
<ConformanceMode>true</ConformanceMode>
162+
<DisableLanguageExtensions>true</DisableLanguageExtensions>
163+
<TreatWarningAsError>true</TreatWarningAsError>
164+
<LanguageStandard>stdcpp17</LanguageStandard>
165+
</ClCompile>
166+
<Link>
167+
<SubSystem>Console</SubSystem>
168+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
169+
<OptimizeReferences>true</OptimizeReferences>
170+
<GenerateDebugInformation>true</GenerateDebugInformation>
171+
</Link>
172+
</ItemDefinitionGroup>
173+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
174+
<ImportGroup Label="ExtensionTargets">
175+
</ImportGroup>
176+
</Project>

‎OAT.vcxproj.filters

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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;ipp;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="src\Constants.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
<ClInclude Include="src\OAT.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClCompile Include="src\main.cpp">
27+
<Filter>Source Files</Filter>
28+
</ClCompile>
29+
<ClCompile Include="src\OAT.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
</ItemGroup>
33+
</Project>

‎OAT.vcxproj.user

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# OAT v1.3.0
2+
## Command-line arguments
3+
`[OAT Executable] [anyfile.oa] [c/nc - compile/nocompile]`
4+
`nc` transcompiles the OA code into C++.
5+
`c` transcompiles the OA code into C++, then compiles that code into an executable.
6+
For the compile option you require g++.
7+
## Documentation
8+
* [v1.3.0](docs/1.3.0.md)
9+
* [v1.2.0](docs/1.2.0.md)
10+
* [v1.1.0](docs/1.1.0.md)
11+
* [v1.0.1](docs/1.0.1.md)

‎docs/1.0.1.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# OAT v1.0.1 Documentation
2+
## Variables
3+
`dec var_name var_value` - auto declares a variable
4+
`strdec` - declares a string, a must for concatenation
5+
`intdec` - declares an integer
6+
`chardec` - declares a char
7+
`floatdec` - declares a float
8+
`doubledec` - declares a double
9+
`booldec` - declares a boolean
10+
`mov a b` - copies the value of a into b
11+
12+
## Math
13+
`cat a b` - adds two strings together. converts b into a string
14+
`add a b` - adds a and b and stores it in a
15+
`sub a b` - subtracts b from a and stores it in a
16+
`mul a b` - multiplies a and b and stores it in a
17+
`div a b` - divides a and b and stores it in a
18+
`mod a b` - gets the modulus of a and b and stores it in a
19+
20+
## Input/Output
21+
`io out a` - prints out a to the console
22+
`io nlout a` - prints out a to the console with a newline
23+
`io in name` - declares name as a string, then gets the input and stores it in name
24+
25+
## Special Characters
26+
### Predefined variables
27+
`NEWLINE` - \n - The newline character
28+
`SPACE` - “ “ - a space
29+
`TRUE` - true
30+
`FALSE` - false
31+
32+
### Comments
33+
Comments start with a semicolon: “`;`”. Anything after the “`;`” will be ignored.
34+
35+
[Example Programs](https://github.com/kaubu/oa-transpiler/tree/main/examples)

‎docs/1.1.0.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# OAT v1.1.0 Documentation
2+
## Variables
3+
`dec var_name var_value` - auto declares a variable
4+
`strdec` - declares a string, a must for concatenation
5+
`intdec` - declares an integer
6+
`chardec` - declares a char
7+
`floatdec` - declares a float
8+
`doubledec` - declares a double
9+
`booldec` - declares a boolean
10+
`mov a b` - copies the value of a into b
11+
`def temp_var_name` - creates a temp value so that functions that use two arguments can send to a variable, like pow
12+
`conv 76 double` - converts a into b and places it into DEF. Uses static_cast<type>(x)
13+
`fconv a b` - converts a into a float and then places it in b. works on strings
14+
`dconv a b` - converts a into a double and then places it in b. works on strings
15+
16+
## Math
17+
`cat a b` - adds two strings together. converts b into a string
18+
`add a b` - adds a and b and stores it in a
19+
`sub a b` - subtracts b from a and stores it in a
20+
`mul a b` - multiplies a and b and stores it in a
21+
`div a b` - divides a and b and stores it in a
22+
`mod a b` - gets the modulus of a and b and stores it in a
23+
`pow a b` - gets the power of a and b and stores them in DEF or a custom def
24+
`ipow a b` - same as before, but more accurate
25+
`fpow a b` - more accurate powers for floats
26+
`dpow a b` - more accurate powers for doubles
27+
`round a b` - rounds a, and puts it into new variable b
28+
29+
## Input/Output
30+
`io out a` - prints out a to the console
31+
`io nlout a` - prints out a to the console with a newline
32+
`io in name` - declares name as a string, then gets the input and stores it in name
33+
34+
## Special Characters
35+
### Predefined variables
36+
`NEWLINE` - \n - The newline character
37+
`SPACE` - “ “ - a space
38+
`TRUE` - true
39+
`FALSE` - false
40+
41+
### Comments
42+
Comments start with a semicolon: “`;`”. Anything after the “`;`” will be ignored.
43+
44+
### Miscellaneous
45+
[Example Programs](https://github.com/kaubu/oa-transpiler/tree/main/examples)

‎docs/1.2.0.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# OAT v1.2.0 Documentation
2+
## Changes
3+
* You can now add comments after code instead of on its own line
4+
* You can now have spaces in strings
5+
## Variables
6+
`dec var_name var_value` - auto declares a variable
7+
`strdec` - declares a string, a must for concatenation
8+
`intdec` - declares an integer
9+
`chardec` - declares a char
10+
`floatdec` - declares a float
11+
`doubledec` - declares a double
12+
`booldec` - declares a boolean
13+
`mov a b` - copies the value of a into b
14+
`def temp_var_name` - creates a temp value so that functions that use two arguments can send to a variable, like pow
15+
`conv 76 double` - converts a into b and places it into DEF. Uses static_cast<type>(x)
16+
`fconv a b` - converts a into a float and then places it in b. works on strings
17+
`dconv a b` - converts a into a double and then places it in b. works on strings
18+
19+
## Math
20+
`cat a b` - adds two strings together. converts b into a string
21+
`add a b` - adds a and b and stores it in a
22+
`sub a b` - subtracts b from a and stores it in a
23+
`mul a b` - multiplies a and b and stores it in a
24+
`div a b` - divides a and b and stores it in a
25+
`mod a b` - gets the modulus of a and b and stores it in a
26+
`pow a b` - gets the power of a and b and stores them in DEF or a custom def
27+
`ipow a b` - same as before, but more accurate
28+
`fpow a b` - more accurate powers for floats
29+
`dpow a b` - more accurate powers for doubles
30+
`round a b` - rounds a, and puts it into new variable b
31+
32+
## Input/Output
33+
`io out a` - prints out a to the console
34+
`io nlout a` - prints out a to the console with a newline appended
35+
`io in name` - declares name as a string, then gets the input and stores it in name
36+
37+
## Special Characters
38+
### Predefined variables
39+
`NEWLINE` - \n - The newline character
40+
`SPACE` - “ “ - a space
41+
`TRUE` - true
42+
`FALSE` - false
43+
44+
### Comments
45+
Comments start with a semicolon: “`;`”. Anything after the “`;`” will be ignored.
46+
After v1.2.0, you can now add comments after code.
47+
48+
### Miscellaneous
49+
[Example Programs](https://github.com/kaubu/oa-transpiler/tree/main/examples)

‎docs/1.3.0.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# OAT v1.3.0 Documentation
2+
## Changes
3+
* Added a lot more functions
4+
* Changed comments so that you have to space comments from the code
5+
## Variables
6+
`dec var_name var_value` - auto declares a variable
7+
`sdec` - declares a string, a must for concatenation
8+
`idec` - declares an integer
9+
`cdec` - declares a char
10+
`fdec` - declares a float
11+
`ddec` - declares a double
12+
`bdec` - declares a boolean
13+
`mov a b` - copies the value of a into b
14+
`def temp_var_name` - creates a temp value so that functions that use two arguments can send to a variable, like pow
15+
`rdef used_var` - moves an already initialized variable into DEF
16+
`conv 76 double` - converts a into b and places it into DEF. Uses static_cast<type>(x)
17+
`iconv a b` - converts a into an inter and then stores it in b. works on strings
18+
`fconv a b` - converts a into a float and then places it in b. works on strings
19+
`dconv a b` - converts a into a double and then places it in b. works on strings
20+
21+
## Math
22+
`cat a b` - adds two strings together. converts b into a string
23+
`add a b` - adds a and b and stores it in a
24+
`sub a b` - subtracts b from a and stores it in a
25+
`mul a b` - multiplies a and b and stores it in a
26+
`div a b` - divides a and b and stores it in a
27+
`mod a b` - gets the modulus of a and b and stores it in a
28+
`pow a b` - gets the power of a and b and stores them in DEF or a custom def
29+
`rpow a b` - recursive power. calculates a^b, then stores it back into a
30+
`ipow a b` - same as before, but more accurate
31+
`fpow a b` - more accurate powers for floats
32+
`dpow a b` - more accurate powers for doubles
33+
`round a b` - rounds a, and puts it into new variable b
34+
`defadd` - adds a and b then stores it in DEF
35+
`defsub` - subtracts b from a then stores it in DEF
36+
`defmul` - multiplies a and b then stores it in DEF
37+
`defdiv` - divides a and b then stores it in DEF
38+
`defmod` - modulus of a and b is stored in DEF
39+
`defpow` - gets a^b then stores it in DEF
40+
41+
## Input/Output
42+
`io out a` - prints out a to the console
43+
`io nlout a` - prints out a to the console with a newline appended
44+
`io in name` - declares name as a string, then gets the input and stores it in name
45+
`io defin` - gets input, then stores it in DEF
46+
`io input message_var` - displays the message in message_var, then stores input in DEF
47+
48+
## Conditional statements
49+
### Assert
50+
`asserteq a b` - prints a == b to console. e.g. true or false
51+
`assertlt a b` - asserts if a < b
52+
`assertgt a b` - asserts if a > b
53+
`assertgteq a b` - asserts if a >= b
54+
`assertlteq a b` - asserts if a <= b
55+
56+
`fasserteq a b` - formatted print a == b to console. e.g. a == b = false
57+
`fassertlt a b` - format asserts if a < b
58+
`fassertgt a b` - format asserts if a > b
59+
`fassertgteq a b` - format asserts if a >= b
60+
`fassertlteq a b` - format asserts if a <= b
61+
62+
## Miscellaneous
63+
`cpp` - anything after here is C++ code. e.g. `cpp std::cout << “Hello World!\n”;`
64+
`include` - includes libraries that certain functions use, so that you just include these, then use C++ code.
65+
**Include libraries:**
66+
* `io` - for std::cout, etc
67+
* `string` - for string operations
68+
* `conv` - for conversions
69+
* `math` - for pow(), etc
70+
* `type` - for checking the type
71+
72+
## Special Characters
73+
### Predefined variables
74+
`NEWLINE` - \n - The newline character
75+
`SPACE` - “ “ - a space
76+
`TRUE` - true
77+
`FALSE` - false
78+
79+
### Comments
80+
Comments start with a semicolon: “`;`”. Anything after the “`;`” will be ignored.
81+
After v1.2.0, you can now add comments after code.
82+
After v1.3.0 comments must be have at least 1 space after code.
83+
84+
### Miscellaneous
85+
[Example Programs](https://github.com/kaubu/oa-transpiler/tree/main/examples)

‎examples/cpp.oa

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; C++ code example ; >= v1.3.0
2+
include io ; for the #include <iostream> header
3+
cpp std::cout << "Hello World!\n";

‎examples/fibonacci.oa

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; OAT v1.2.0 or above
2+
io out "What number of fibonacci would you like to go to?\n>> " ; Initial input
3+
4+
io in str_num ; Get number
5+
dconv str_num number ; Convert str_num to a double
6+
7+
def par2
8+
dpow 1.6180339 number ; 1.6180339^n
9+
10+
def par3
11+
dpow -0.6180339 number ; -0.6180339^n
12+
13+
sub par2 par3 ; (1.6180339^n) - (-0.6180339^n)
14+
div par2 2.236067977 ; ((1.6180339^n) - (-0.6180339^n)) / 2.236067977
15+
16+
round par2 result ; Round the result
17+
18+
io nlout result ; Display the result

‎examples/greeting.oa

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; 2-line input/output Greeting ; ver >= v1.3.0
2+
io input "Hello, what is your name? "
3+
io nlout "Welcome, " << DEF << "."

‎examples/hello_world.oa

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io nlout "Hello World!" ; v1.2.0 and above

‎examples/power_calculator.oa

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; v1.2.0 or above
2+
io nlout "Welcome!"
3+
4+
io out "Please enter your base: "
5+
io in in_base
6+
dconv in_base base
7+
8+
io out "Please enter your exponent: "
9+
io in in_exp
10+
dconv in_exp exp
11+
12+
def result
13+
dpow base exp ; base^exp, which is then stored in result
14+
15+
io out "Result: "
16+
io nlout result
17+
18+
; io nlout "Result: " << result ; This is a hacky way of doing it, which will input itself into the C++ code

‎examples/temperature.oa

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; >= 1.2.0
2+
io out "Please enter your temperature in either celcius or fahrenheit: "
3+
io in old_in_temp
4+
dconv old_in_temp in_temp
5+
6+
mov in_temp f ; Fahrenheit
7+
mov in_temp c ; Celcius
8+
9+
mul f 1.8
10+
add f 32.0
11+
12+
sub c 32.0
13+
mul c 0.5556
14+
15+
io nlout in_temp << " deg f to celcius: " << c
16+
io nlout in_temp << " deg c to fahrenheit: " << f

‎examples/test.oa

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
; Test file for OA, to check that it successfully compiles for you.
2+
3+
; Template:
4+
; Expected output:
5+
6+
; VARIABLES
7+
8+
dec test_dec 67.3
9+
; Expected output: 67.3
10+
io nlout test_dec
11+
12+
strdec string "Test"
13+
; Expected output: Test
14+
io nlout string
15+
16+
intdec num 25425
17+
; Expected output: 25425
18+
io nlout num
19+
20+
chardec x 'x'
21+
; Expected output: x
22+
io nlout x
23+
24+
floatdec float_num 57.4f
25+
; Expected output: 57.4
26+
io nlout float_num
27+
28+
doubledec double_num 852.42
29+
; Expected output: 852.42
30+
io nlout double_num
31+
32+
booldec winning FALSE
33+
; Expected output: false
34+
io nlout winning
35+
36+
; Should be double
37+
mov double_num test_dec_2
38+
; Expected output: 852.42
39+
io nlout test_dec_2
40+
41+
strdec str_test "a"
42+
cat str_test "b"
43+
cat str_test "c"
44+
; Expected output: abc
45+
io nlout str_test
46+
47+
; MATH
48+
49+
dec add_num 6
50+
add add_num 5
51+
; Expected output: 11
52+
io nlout add_num
53+
54+
dec sub_num 5
55+
sub sub_num 3
56+
; Expected output: 2
57+
io nlout sub_num
58+
59+
dec mul_num 5
60+
mul mul_num 6
61+
; Expected output: 30
62+
io nlout mul_num
63+
64+
dec div_num 21
65+
div div_num 7
66+
; Expected output: 3
67+
io nlout div_num
68+
69+
dec mod_num 6
70+
mod mod_num 6
71+
; Expected output: 0
72+
io nlout mod_num
73+
74+
dec mod_num_2 8
75+
mod mod_num_2 5
76+
; Expected output: 3
77+
io nlout mod_num_2
78+
79+
io out ">>"
80+
io out SPACE
81+
io in input
82+
; Expected output: What the user types
83+
io nlout input
84+
85+
; Expected output:
86+
; 67.3
87+
; Test
88+
; 25425
89+
; x
90+
; 57.4
91+
; 852.42
92+
; false OR 0
93+
; 852.42
94+
; abc
95+
; 11
96+
; 2
97+
; 30
98+
; 3
99+
; 0
100+
; What the user types

‎src/Constants.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef CONSTANTS_H
2+
#define CONSTANTS_H
3+
4+
#include <string>
5+
#include <vector>
6+
7+
using std::string;
8+
using std::vector;
9+
10+
namespace constants
11+
{
12+
// Config
13+
static constexpr bool DELETE_CPP_FILE{ true }; // false for debug, true for release
14+
15+
// Includes
16+
static vector<string> IO_INCLUDES{ "#include <iostream>\n" };
17+
static vector<string> STRING_INCLUDES{ "#include <string>" };
18+
static vector<string> CONV_INCLUDES{ "#include <string>\n", "#include <cstdlib>\n" };
19+
static vector<string> MATH_INCLUDES{ "#include <cmath>\n" };
20+
static vector<string> TYPE_INCLUDES{ "#include <type_traits>\n", "#include <typeinfo>\n", "#include <memory>\n", "#include <string>\n", "#include <cstdlib>\n", "#include <typeinfo>\n" };
21+
static vector<string> NONE_INCLUDE{ "" };
22+
23+
// Transpiler
24+
static const string FIRST_MAIN{ "int main()\n{\n" };
25+
static const string INDENTATION{ " " };
26+
static const string NEWLINE{ "\n" }; // Was char, had to change
27+
static const string LAST_MAIN{ INDENTATION + "return 0;\n}\n" };
28+
static const string DEFAULT{ "DEF" }; // Placeholder variable
29+
30+
// C Replacement
31+
static const string SPACE{ "\" \"" }; // Was char, had to change
32+
static const string NEWLINE_CHARACTER{ "\"\\n\"" };
33+
static const string TRUE{ "true" };
34+
static const string FALSE{ "false" };
35+
static const string NONE{ "" };
36+
37+
// Messages
38+
static const string HELP_MESSAGE{
39+
"Incorrect arguments.\n"
40+
"OAT Usage:\n"
41+
"[OAT Executable] [anyfile.oa] [c/nc - compile/nocompile]\n"
42+
"Warning: You need g++ to compile.\n"
43+
};
44+
45+
// Functions
46+
static const string TYPE_NAME{
47+
"#ifndef _MSC_VER\n"
48+
"# include <cxxabi.h>\n"
49+
"#endif\n"
50+
"\n"
51+
"template <class T> std::string type_name()\n"
52+
"{\n"
53+
" typedef typename std::remove_reference<T>::type TR;\n"
54+
" std::unique_ptr<char, void(*)(void *)> own\n"
55+
" (\n"
56+
"#ifndef _MSC_VER\n"
57+
" abi::__cxa_demangle(typeid(TR).name(), nullptr,\n"
58+
" nullptr, nullptr),\n"
59+
"#else\n"
60+
" nullptr,\n"
61+
"#endif\n"
62+
" std::free\n"
63+
" );\n"
64+
" std::string r = own != nullptr ? own.get() : typeid(TR).name();\n"
65+
" if (std::is_const<TR>::value) { r += \" const\"; }\n"
66+
" if (std::is_volatile<TR>::value) { r += \" volatile\"; }\n"
67+
" if (std::is_lvalue_reference<T>::value) { r += \"&\"; }\n"
68+
" else if (std::is_rvalue_reference<T>::value) { r += \"&&\"; }\n"
69+
" return r;\n"
70+
"}\n"
71+
};
72+
}
73+
74+
#endif // CONSTANTS_H

‎src/OAT.cpp

+274
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
#include "OAT.h"
2+
#include "Constants.h"
3+
4+
#include <cmath>
5+
#include <string>
6+
#include <vector>
7+
8+
using std::string;
9+
using std::vector;
10+
using IncludesVector = vector<string>;
11+
12+
namespace vars
13+
{
14+
static string def{ constants::DEFAULT };
15+
static bool def_reference{ false };
16+
static bool ipow_dec{ false };
17+
static bool fpow_dec{ false };
18+
static bool dpow_dec{ false };
19+
static bool type_dec{ false };
20+
}
21+
22+
string prefixCheck(string prefix = "")
23+
{
24+
if (vars::def_reference) { return ""; }
25+
else { return prefix; }
26+
}
27+
28+
// Variables
29+
string OAT::dec(string var_name, string var_value) { return "auto " + var_name + "{ " + var_value + " };\n"; }
30+
string OAT::dec(string var_name, string var_value, string type) { return type + " " + var_name + "{ " + var_value + " };\n"; }
31+
string OAT::mov(string l_var, string r_var) { return "auto " + r_var + "{ " + l_var + " };\n"; }
32+
string OAT::anydef(string var_name, bool reference)
33+
{
34+
vars::def = var_name;
35+
vars::def_reference = reference;
36+
return string("");
37+
}
38+
string OAT::conv(string var_name, string type) { return prefixCheck(type + " ") + vars::def + "{ static_cast<" + type + ">(" + var_name + ") };\n"; }
39+
string OAT::iconv(string old_var, string new_var) { return "int " + new_var + "{ std::stoi(" + old_var + ") };\n"; }
40+
string OAT::fconv(string old_var, string new_var) { return "float " + new_var + "{ strtof(" + old_var + ") };\n"; }
41+
string OAT::dconv(string old_var, string new_var) { return "double " + new_var + "{ atof(" + old_var + ".c_str()) };\n"; }
42+
string OAT::type(string var_name)
43+
{
44+
// Add
45+
return "";
46+
}
47+
string OAT::round(string l_var, string r_var) { return "auto " + r_var + "{ round(" + l_var + ") };\n"; }
48+
49+
// Math
50+
string OAT::math(string l_var, string r_var, string mode, bool def)
51+
{
52+
if (mode == "pow") { return prefixCheck("int ") + vars::def + " = pow(" + l_var + ", " + r_var + ");\n"; }
53+
else if (mode == "rpow") { return l_var + " = pow(" + l_var + ", " + r_var + ");\n"; }
54+
55+
if (def) { return prefixCheck("auto ") + vars::def + " {" + l_var + " " + mode + " " + r_var + "};\n"; }
56+
else { return l_var + " " + mode + "= " + r_var + ";\n"; }
57+
}
58+
string OAT::cat(string l_var, string r_var) { return l_var + " += " + "std::string(" + r_var + ");\n"; }
59+
60+
string OAT::mathpow(string base, string exp, string mode) { return prefixCheck("int ") + vars::def + " = " + mode + "pow(" + base + ", " + exp + ");\n"; } // mode == i, d, etc
61+
62+
// Input/Output
63+
string OAT::io(string mode, string var)
64+
{
65+
if (mode == "out") { return "std::cout << " + var + ";\n"; }
66+
else if (mode == "nlout") { return "std::cout << " + var + " << '\\n';\n"; }
67+
else if (mode == "in") { return "std::string " + var + "{};\n" + constants::INDENTATION + "std::cin >> " + var + ";\n"; }
68+
else if (mode == "input")
69+
{
70+
if (vars::def_reference)
71+
{
72+
return "std::cout << " + var + ";\n"
73+
"" + constants::INDENTATION + "std::cin >> " + vars::def + ";\n";
74+
}
75+
else
76+
{
77+
return "std::cout << " + var + ";\n"
78+
"std::string " + vars::def + " {};\n"
79+
"" + constants::INDENTATION + "std::cin >> " + vars::def + ";\n";
80+
}
81+
}
82+
else if (mode == "defin")
83+
{
84+
if (vars::def_reference)
85+
{
86+
return "std::cin >> " + vars::def + ";\n";
87+
}
88+
else
89+
{
90+
return "std::string " + vars::def + "{};\n" + constants::INDENTATION + "std::cin >> " + vars::def + ";\n";
91+
}
92+
}
93+
else { return string(""); }
94+
}
95+
96+
string OAT::assert(string l_var, string r_var, string mode, bool format)
97+
{
98+
if (format)
99+
{
100+
return "if (" + l_var + " " + mode + " " + r_var + ")"
101+
" { std::cout << \"" + l_var + " " + mode + " " + r_var + " = true\\n\"; }\n"
102+
"else { std::cout << \"" + l_var + " " + mode + " " + r_var + " = false\\n\"; }\n";
103+
}
104+
else
105+
{
106+
return "if (" + l_var + " " + mode + " " + r_var + ") { std::cout << \"true\\n\"; }\n"
107+
"else { std::cout << \"false\\n\";\n";
108+
}
109+
} // mode == "==", <, >, etc
110+
111+
string OAT::cpp(string b, string c) { return "" + b + c + '\n'; } // DANGEROUS
112+
113+
vector<string> getIncludes(string to_include)
114+
{
115+
if (to_include == "io") { return constants::IO_INCLUDES; }
116+
else if (to_include == "conv") { return constants::CONV_INCLUDES; }
117+
else if (to_include == "math") { return constants::MATH_INCLUDES; }
118+
else if (to_include == "string") { return constants::STRING_INCLUDES; }
119+
else if (to_include == "type") { return constants::TYPE_INCLUDES; }
120+
else { return constants::NONE_INCLUDE; }
121+
}
122+
123+
string OAT::process_c(string c)
124+
{
125+
// Removes " ;" and anything past it
126+
string cut_c{ c.substr(0, c.find(" ;", 0)) };
127+
128+
if (cut_c == "NEWLINE") { return constants::NEWLINE_CHARACTER; }
129+
else if (cut_c == "SPACE") { return constants::SPACE; }
130+
else if (cut_c == "TRUE") { return constants::TRUE; }
131+
else if (cut_c == "FALSE") { return constants::FALSE; }
132+
else if (cut_c == "NONE") { return constants::NONE; }
133+
else { return cut_c; };
134+
}
135+
136+
string OAT::process_line(string a, string b, string c, IncludesVector *include_vector)
137+
{
138+
if (a == "dec") { return OAT::dec(b, c); }
139+
else if (a == "sdec") // string
140+
{
141+
// Push #include <string> into vector
142+
include_vector->push_back("#include <string>\n");
143+
return OAT::dec(b, c, "std::string");
144+
}
145+
else if (a == "idec") { return OAT::dec(b, c, "int"); } // int
146+
else if (a == "cdec") { return OAT::dec(b, c, "char"); } // char
147+
else if (a == "fdec") { return OAT::dec(b, c, "float"); } // float
148+
else if (a == "ddec") { return OAT::dec(b, c, "double"); } // double
149+
else if (a == "bdec") { return OAT::dec(b, c, "bool"); } // bool
150+
else if (a == "cat")
151+
{
152+
include_vector->push_back("#include <string>\n");
153+
return OAT::cat(b, c);
154+
}
155+
else if (a == "mov") { return OAT::mov(b, c); }
156+
else if (a == "def") { return OAT::anydef(b, false); }
157+
else if (a == "rdef") { return OAT::anydef(b, true); }
158+
else if (a == "conv") { return OAT::conv(b, c); }
159+
else if (a == "iconv")
160+
{
161+
include_vector->push_back("#include <string>\n");
162+
return OAT::iconv(b, c);
163+
}
164+
else if (a == "fconv")
165+
{
166+
include_vector->push_back("#include <cstdlib>\n");
167+
return OAT::fconv(b, c);
168+
}
169+
else if (a == "dconv")
170+
{
171+
include_vector->push_back("#include <cstdlib>\n");
172+
return OAT::dconv(b, c);
173+
}
174+
else if (a == "add") { return OAT::math(b, c, "+", false); }
175+
else if (a == "sub") { return OAT::math(b, c, "-", false); }
176+
else if (a == "mul") { return OAT::math(b, c, "*", false); }
177+
else if (a == "div") { return OAT::math(b, c, "/", false); }
178+
else if (a == "mod") { return OAT::math(b, c, "%", false); }
179+
else if (a == "pow")
180+
{
181+
include_vector->push_back("#include <cmath>\n");
182+
return OAT::math(b, c, "pow", false);
183+
}
184+
else if (a == "rpow")
185+
{
186+
include_vector->push_back("#include <cmath>\n");
187+
return OAT::math(b, c, "rpow", false);
188+
}
189+
else if (a == "defadd") { return OAT::math(b, c, "+", true); }
190+
else if (a == "defsub") { return OAT::math(b, c, "-", true); }
191+
else if (a == "defmul") { return OAT::math(b, c, "*", true); }
192+
else if (a == "defdiv") { return OAT::math(b, c, "/", true); }
193+
else if (a == "defmod") { return OAT::math(b, c, "%", true); }
194+
else if (a == "defpow")
195+
{
196+
include_vector->push_back("#include <cmath>\n");
197+
return OAT::math(b, c, "pow", true);
198+
}
199+
else if (a == "ipow") { return OAT::mathpow(b, c, "i"); }
200+
else if (a == "fpow") { return OAT::mathpow(b, c, "f"); }
201+
else if (a == "dpow") { return OAT::mathpow(b, c, "d"); }
202+
else if (a == "round")
203+
{
204+
include_vector->push_back("#include <cmath>\n");
205+
return OAT::round(b, c);
206+
}
207+
else if (a == "io") {
208+
include_vector->push_back("#include <iostream>\n");
209+
return OAT::io(b, c);
210+
}
211+
else if (a == "asserteq") { return OAT::assert(b, c, "==", false); }
212+
else if (a == "fasserteq") { return OAT::assert(b, c, "==", true); }
213+
else if (a == "assertlt") { return OAT::assert(b, c, "<", false); }
214+
else if (a == "fassertlt") { return OAT::assert(b, c, "<", true); }
215+
else if (a == "assertgt") { return OAT::assert(b, c, ">", false); }
216+
else if (a == "fassertgt") { return OAT::assert(b, c, ">", true); }
217+
else if (a == "assertgteq") { return OAT::assert(b, c, ">=", false); }
218+
else if (a == "fassertgteq") { return OAT::assert(b, c, ">=", true); }
219+
else if (a == "assertlteq") { return OAT::assert(b, c, "<=", false); }
220+
else if (a == "fassertlteq") { return OAT::assert(b, c, "<=", true); }
221+
else if (a == "cpp") { return OAT::cpp(b, c); }
222+
else if (a == "include")
223+
{
224+
vector<string> includes{ getIncludes(b) };
225+
for (string include : includes) { include_vector->push_back(include); }
226+
return string();
227+
}
228+
else if (a == "type" || a == "ptype" || a == "fptype")
229+
{
230+
vector<string> includes{ getIncludes("type") };
231+
for (string include : includes) { include_vector->push_back(include); }
232+
if (a == "type")
233+
{
234+
return prefixCheck("auto ") + vars::def + "{ type_name<decltype(" + b + ")>() };\n";
235+
}
236+
else if (a == "ptype")
237+
{
238+
include_vector->push_back("#include <iostream>\n");
239+
return "std::cout << " + string() + " type_name<decltype(" + b + ")>() << '\\n';\n";
240+
}
241+
else if (a == "fptype")
242+
{
243+
include_vector->push_back("#include <iostream>\n");
244+
return "std::cout << \"variable '" + b + "' has type '\" << type_name<decltype(" + b + ")>() << \"'\\n\";\n";
245+
}
246+
else { return ""; }
247+
}
248+
else { return ""; }
249+
}
250+
251+
string OAT::declare_function(string function_name)
252+
{
253+
if (function_name == "ipow" && !(vars::ipow_dec))
254+
{
255+
vars::ipow_dec = true;
256+
return "int ipow(int base, int exp) { return exp == 0 ? 1 : base * ipow(base, exp - 1); }\n";
257+
}
258+
else if (function_name == "fpow" && !(vars::fpow_dec))
259+
{
260+
vars::fpow_dec = true;
261+
return "float fpow(float base, float exp) { return exp == 0 ? 1 : base * fpow(base, exp - 1); }\n";
262+
}
263+
else if (function_name == "dpow" && !(vars::dpow_dec))
264+
{
265+
vars::dpow_dec = true;
266+
return "double dpow(double base, double exp) { return exp == 0 ? 1 : base * dpow(base, exp - 1); }\n";
267+
}
268+
else if ((function_name == "type" || function_name == "ptype" || function_name == "fptype") && !(vars::type_dec))
269+
{
270+
vars::type_dec = true;
271+
return constants::TYPE_NAME; // Adds the template for type in source
272+
}
273+
else { return ""; }
274+
}

‎src/OAT.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef OAT_H
2+
#define OAT_H
3+
4+
#include <string>
5+
#include <vector>
6+
7+
using std::string;
8+
using std::vector;
9+
using IncludesVector = vector<string>;
10+
11+
class OAT
12+
{
13+
public:
14+
static string process_line(string a, string b, string c, IncludesVector *include_vector);
15+
static string process_c(string c);
16+
static string declare_function(string function_name);
17+
private:
18+
// Variables
19+
static string dec(string var_name, string var_value); // dec foo 5 - Uses auto unless specificed
20+
static string dec(string var_name, string var_value, string type); // dec foo 5 - Uses auto unless specificed
21+
static string mov(string l_var, string r_var); // mov foo bar
22+
static string anydef(string var_name, bool reference); // def name - Change default placeholder
23+
static string conv(string var_name, string type);
24+
static string iconv(string old_var, string new_var);
25+
static string fconv(string old_var, string new_var);
26+
static string dconv(string old_var, string new_var);
27+
static string type(string var_name);
28+
29+
// Math
30+
static string math(string l_var, string r_var, string mode, bool def); // Mode is +, -, *, /, etc
31+
static string cat(string l_var, string r_var); // Concatenate r_var to l_var. cat foo NEWLINE
32+
static string mathpow(string base, string exp, string mode);
33+
static string round(string l_var, string r_var);
34+
35+
// Input/Output
36+
static string io(string mode, string var = string("DEF")); // Mode could be out or in. Var is the message displayed.
37+
38+
// Conditional statements
39+
static string assert(string l_var, string r_var, string mode, bool format);
40+
41+
// Meta
42+
static string cpp(string b, string c);
43+
};
44+
45+
#endif // OAT_H

‎src/main.cpp

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include "Constants.h"
2+
#include "OAT.h"
3+
4+
#include <algorithm>
5+
#include <iostream>
6+
#include <fstream>
7+
#include <sstream>
8+
#include <string>
9+
#include <vector>
10+
#include <limits>
11+
12+
using std::string;
13+
using std::vector;
14+
using IncludesVector = vector<string>;
15+
16+
void displayHelpMessage()
17+
{
18+
std::cout << constants::HELP_MESSAGE;
19+
exit(0);
20+
}
21+
22+
int main(int argc, char **argv)
23+
{
24+
if (argc <= 1 || argc > 3) { displayHelpMessage(); }
25+
26+
/*
27+
OAT.exe [file.oa] [c/noc - compile/don't compile]
28+
Exe: [0]
29+
File: [1]
30+
Compile: [2]
31+
*/
32+
33+
string file{ argv[1] };
34+
35+
// Get rid of .oa extension
36+
size_t lastIndex = file.find_last_of(".");
37+
string fileName = file.substr(0, lastIndex);
38+
39+
string cppFile{ fileName + ".cpp" };
40+
string exeFile{ fileName + ".exe" };
41+
string compileVar{ argv[2] };
42+
43+
bool compileOption{};
44+
if (compileVar == "c") { compileOption = true; }
45+
else if (compileVar == "nc") { compileOption = false; }
46+
else { displayHelpMessage(); } // Exits automatically
47+
48+
string sourceFile{};
49+
sourceFile += constants::FIRST_MAIN;
50+
51+
std::ifstream infile(file);
52+
53+
string line{};
54+
IncludesVector includes{};
55+
while (std::getline(infile, line))
56+
{
57+
std::istringstream iss(line);
58+
string a{};
59+
string b{};
60+
string c{};
61+
62+
iss >> a >> b;
63+
std::getline(iss, c); // With this, you can have spaces now. E.g. io nlout "Hello World!"
64+
65+
if ((a == ";") || (a == "\n") || (a == "")) { continue; } // Comment/newline, don't do anything
66+
67+
sourceFile += constants::INDENTATION;
68+
c = OAT::process_c(c); // I need to process C so that it cuts off anything past a comment ;
69+
70+
sourceFile = OAT::declare_function(a) + sourceFile;
71+
sourceFile += OAT::process_line(a, b, c, &includes);
72+
}
73+
74+
sourceFile += constants::LAST_MAIN;
75+
76+
/*
77+
Sort through the includes vector to get rid of duplicates,
78+
then append the headers to eachother in a string, then append the sourceFile to the headers
79+
*/
80+
81+
std::sort( includes.begin(), includes.end() );
82+
includes.erase( unique( includes.begin(), includes.end() ), includes.end() );
83+
84+
// Append headers to eachother in a string
85+
string includesString{};
86+
for (size_t i = 0; i < includes.size(); ++i)
87+
{
88+
includesString += includes[i];
89+
}
90+
91+
string fullSource{ includesString + sourceFile };
92+
93+
// Write to file
94+
std::ofstream out(cppFile);
95+
out << fullSource;
96+
out.close();
97+
98+
if (compileOption)
99+
{
100+
string command{ "g++ " + cppFile + " -o " + exeFile };
101+
system(command.c_str());
102+
std::cout << "\"" << file << "\"" << " compiled to " << "\"" << exeFile << "\"" << '\n';
103+
}
104+
else
105+
{
106+
std::cout << "\"" << file << "\"" << " transcompiled to " << "\"" << cppFile << "\"" << '\n';
107+
}
108+
109+
if (constants::DELETE_CPP_FILE && compileOption)
110+
{
111+
if (std::remove(cppFile.c_str()) != 0)
112+
{
113+
std::cout << "Failed to delete \"" + cppFile + "\"\n";
114+
exit(1);
115+
}
116+
}
117+
118+
return 0;
119+
}

0 commit comments

Comments
 (0)
Please sign in to comment.