├── OverScript
├── OS.ico
├── Expr.cs
├── Properties
│ └── PublishProfiles
│ │ └── FolderProfile.pubxml
├── OverScript.csproj
├── LocMark.cs
├── NullableObject.cs
├── LoopRange.cs
├── PressedKey.cs
├── CustomType.cs
├── ClassInstance.cs
├── CallStack.cs
├── PPDirective.cs
├── VarType.cs
├── CustomObject.cs
├── Executor.cs
├── TypeConverter.cs
├── Literals.cs
├── Script.cs
├── Program.cs
├── Variables.cs
├── EvalUnit.cs
├── CodeExecution.cs
└── ScriptClass.cs
├── .gitignore
├── LICENSE
├── README.md
└── OverScript.sln
/OverScript/OS.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/overscript-lang/OverScript/HEAD/OverScript/OS.ico
--------------------------------------------------------------------------------
/OverScript/Expr.cs:
--------------------------------------------------------------------------------
1 | namespace OverScript
2 | {
3 | public class Expr
4 | {
5 | public EvalUnit EU;
6 | public EvalUnit OrigEU;
7 | public Expr(EvalUnit eu, EvalUnit orig = null)
8 | {
9 | EU = eu;
10 | OrigEU = orig;
11 | }
12 | public override string ToString() => EU.ToString();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | #Ignore thumbnails created by Windows
3 | Thumbs.db
4 | #Ignore files built by Visual Studio
5 | *.obj
6 | *.exe
7 | *.pdb
8 | *.user
9 | *.aps
10 | *.pch
11 | *.vspscc
12 | *_i.c
13 | *_p.c
14 | *.ncb
15 | *.suo
16 | *.tlb
17 | *.tlh
18 | *.bak
19 | *.cache
20 | *.ilk
21 | *.log
22 | [Bb]in
23 | [Dd]ebug*/
24 | ExceptionsON*/
25 | *.lib
26 | *.sbr
27 | obj/
28 | [Rr]elease*/
29 | _ReSharper*/
30 | [Tt]est[Rr]esult*
31 | .vs/
32 | #Nuget packages folder
33 | packages/
34 |
--------------------------------------------------------------------------------
/OverScript/Properties/PublishProfiles/FolderProfile.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | Release
8 | Any CPU
9 | bin\Release\net6.0\publish\
10 | FileSystem
11 | net6.0
12 | false
13 |
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2022 Dmitry Trojan
4 |
5 | All rights reserved.
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # The OverScript Programming Language
2 |
3 | This is the source code repository for [OverScript]. This version is for .NET 6. Version for .NET Standard 2.1 [here].
4 | OverScript is a simple and powerful C-like statically-typed language written in C# and is great for both embedding in .NET programs and building standalone applications. The project was developed from scratch without looking back at traditional approaches to creating languages. The unique approach allows the language to go beyond the standard features and have great potential for improvement.
5 |
6 | [OverScript]: https://overscript.org/
7 | [here]: https://github.com/overscript-lang/OverScriptStandard
8 |
9 | Simple code example:
10 | ```cs
11 | Point[] arr = new Point[]{new Point(25, 77), new Point(122, 219)}; //creating an array of two instances
12 | int n; // 0 by default
13 | foreach(Point p in arr){ // iterating over all elements of an array
14 | n++;
15 | WriteLine($"{n}) {p.X}; {p.Y}"); // outputting values using string interpolation
16 | }
17 | //1) 25; 77
18 | //2) 122; 219
19 | ReadKey();
20 |
21 | class Point{
22 | public int X, Y;
23 | New(int x, int y){ // constructor
24 | X=x;
25 | Y=y;
26 | }
27 | }
28 | ```
29 |
30 |
31 |
--------------------------------------------------------------------------------
/OverScript/OverScript.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | Debug;Release;ExceptionsON
7 | OS.ico
8 | Copyright © 2022 Dmitry Trojan
9 | Dmitry Trojan
10 |
11 | https://overscript.org/
12 | 1.0.1.0
13 | 1.0.1.0
14 | 1.0.1
15 |
16 |
17 |
18 | TRACE;EXON
19 | false
20 | true
21 |
22 |
23 |
24 | TRACE;EXON
25 | false
26 |
27 |
28 |
29 | TRACE
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/OverScript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30804.86
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OverScript", "OverScript\OverScript.csproj", "{F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | ExceptionsON|Any CPU = ExceptionsON|Any CPU
12 | Release|Any CPU = Release|Any CPU
13 | EndGlobalSection
14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
15 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
17 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.ExceptionsON|Any CPU.ActiveCfg = ExceptionsON|Any CPU
18 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.ExceptionsON|Any CPU.Build.0 = ExceptionsON|Any CPU
19 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {F9C16F74-1036-4D09-AC4A-6F12D6EC94C0}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(SolutionProperties) = preSolution
23 | HideSolutionNode = FALSE
24 | EndGlobalSection
25 | GlobalSection(ExtensibilityGlobals) = postSolution
26 | SolutionGuid = {F33296E3-5C0C-40DC-9CAF-C2AC02807EC8}
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/OverScript/LocMark.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.Linq;
3 | using static OverScript.ScriptClass;
4 |
5 | namespace OverScript
6 | {
7 | public class LocMark
8 | {
9 | public CodeFile CFile;
10 | public int Line;
11 | public int Line2;
12 |
13 | static char[] CharsToTrim = new char[] { '\t', '\r', ' ' };
14 | const string LineBreak = @"\n";
15 | public LocMark(CodeFile File, int line, int line2 = -1)
16 | {
17 | Line = line;
18 | Line2 = line;
19 | CFile = File;
20 |
21 | }
22 | public string Code
23 | {
24 | get
25 | {
26 | string code = "";
27 | for (int i = Line; i <= Line2; i++)
28 | {
29 | string s = CFile.Lines[i];
30 |
31 | RemoveComments(ref s);
32 | code += s.Trim(CharsToTrim) + LineBreak;
33 |
34 | }
35 | if (code.EndsWith(LineBreak)) code = code.Remove(code.Length - 2, 2);
36 | return code;
37 | }
38 | }
39 | public string File => CFile.File;
40 |
41 | public LocMark Simplify() => new LocMark(CFile, Line2 < 0 ? Line : Line2);
42 |
43 | public static CodeFile NumToCodeFile(int num, Script script)
44 | {
45 | return script.CodeFiles.Where(x => x.Num == num).FirstOrDefault();
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/OverScript/NullableObject.cs:
--------------------------------------------------------------------------------
1 |
2 |
3 | namespace OverScript
4 | {
5 | public struct NullableObject
6 | {
7 |
8 | public bool IsNull;
9 | public T Item;
10 |
11 | private NullableObject(T item, bool isNull) : this()
12 | {
13 | IsNull = isNull;
14 | Item = item;
15 | }
16 |
17 | public NullableObject(T item) : this(item, item == null)
18 | {
19 | }
20 |
21 |
22 | public static implicit operator T(NullableObject nobj)
23 | {
24 | return nobj.Item;
25 | }
26 |
27 | public static implicit operator NullableObject(T item)
28 | {
29 | return new NullableObject(item);
30 | }
31 |
32 | public override string ToString() => Item?.ToString();
33 |
34 | public override bool Equals(object obj)
35 | {
36 | if (obj == null)
37 | return IsNull;
38 |
39 | if (!(obj is NullableObject nobj))
40 | return false;
41 | else
42 | {
43 |
44 |
45 | if (IsNull)
46 | return nobj.IsNull;
47 |
48 | if (nobj.IsNull)
49 | return false;
50 |
51 | return Item.Equals(nobj.Item);
52 | }
53 | }
54 |
55 | public override int GetHashCode()
56 | {
57 | if (IsNull)
58 | return 0;
59 |
60 | var result = Item.GetHashCode();
61 |
62 | if (result >= 0)
63 | result++;
64 |
65 | return result;
66 | }
67 | }
68 |
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/OverScript/LoopRange.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 |
3 | namespace OverScript
4 | {
5 | struct LoopRange : IEnumerable
6 | {
7 | public int Start, Stop, Step;
8 | public LoopRange(int start, int stop, int step)
9 | {
10 | Start = start;
11 | Stop = stop;
12 | Step = step;
13 | }
14 | public IEnumerator GetEnumerator()
15 | {
16 | return new RangeEnumerator(Start, Stop, Step);
17 | }
18 | public class RangeEnumerator : IEnumerator
19 | {
20 | public int Start, Stop, Step, CurrentValue;
21 | bool Reseted = false;
22 | public RangeEnumerator(int start, int stop, int step)
23 | {
24 | Start = start;
25 | Stop = stop;
26 | Step = step;
27 | Reset();
28 | }
29 |
30 | public bool MoveNext()
31 | {
32 | if (Reseted)
33 | {
34 | CurrentValue = Start;
35 | Reseted = false;
36 | }
37 | else
38 | CurrentValue += Step;
39 |
40 | return Step > 0 ? (CurrentValue < Stop) : (CurrentValue > Stop);
41 | }
42 |
43 | public void Reset()
44 | {
45 | CurrentValue = 0;
46 | Reseted = true;
47 | }
48 |
49 | object IEnumerator.Current
50 | {
51 | get
52 | {
53 | return Current;
54 | }
55 | }
56 |
57 | public int Current
58 | {
59 | get
60 | {
61 | return CurrentValue;
62 |
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/OverScript/PressedKey.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OverScript
4 | {
5 | struct PressedKey : IConvertible
6 | {
7 | public ConsoleKeyInfo KeyInfo { set; get; }
8 | public override string ToString() => KeyInfo.Key.ToString();
9 | public ConsoleKey Key { get { return KeyInfo.Key; } }
10 | public char KeyChar { get { return KeyInfo.KeyChar; } }
11 | public PressedKey(ConsoleKeyInfo k)
12 | {
13 | KeyInfo = k;
14 | }
15 | string IConvertible.ToString(IFormatProvider provider) => ToString();
16 | TypeCode IConvertible.GetTypeCode() { throw new NotImplementedException(); }
17 | bool IConvertible.ToBoolean(IFormatProvider provider) { throw new NotImplementedException(); }
18 | byte IConvertible.ToByte(IFormatProvider provider) => (Byte)KeyInfo.Key;
19 | DateTime IConvertible.ToDateTime(IFormatProvider provider) { throw new NotImplementedException(); }
20 | decimal IConvertible.ToDecimal(IFormatProvider provider) => (Decimal)KeyInfo.Key;
21 | double IConvertible.ToDouble(IFormatProvider provider) => (Double)KeyInfo.Key;
22 | short IConvertible.ToInt16(IFormatProvider provider) => (Int16)KeyInfo.Key;
23 | int IConvertible.ToInt32(IFormatProvider provider) => (Int32)KeyInfo.Key;
24 | long IConvertible.ToInt64(IFormatProvider provider) => (Int64)KeyInfo.Key;
25 | sbyte IConvertible.ToSByte(IFormatProvider provider) => (SByte)KeyInfo.Key;
26 | float IConvertible.ToSingle(IFormatProvider provider) => (Single)KeyInfo.Key;
27 | object IConvertible.ToType(Type conversionType, IFormatProvider provider) { throw new NotImplementedException(); }
28 | ushort IConvertible.ToUInt16(IFormatProvider provider) => (UInt16)KeyInfo.Key;
29 | uint IConvertible.ToUInt32(IFormatProvider provider) => (UInt32)KeyInfo.Key;
30 | ulong IConvertible.ToUInt64(IFormatProvider provider) => (UInt64)KeyInfo.Key;
31 | char IConvertible.ToChar(IFormatProvider provider) => KeyInfo.KeyChar;
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/OverScript/CustomType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using static OverScript.ScriptClass;
4 |
5 | namespace OverScript
6 | {
7 | public class CustomType
8 | {
9 | public string Name, FullName;
10 | public ScriptClass Class;
11 | public bool IsArray;
12 | public Script CurScript;
13 | public CustomType(string name, ScriptClass c)
14 | {
15 | FullName = name;
16 | Class = c;
17 | Name = name.Substring(name.LastIndexOf('.') + 1);
18 | IsArray = name.EndsWith("[]");
19 |
20 | }
21 | public bool IsOfType(object obj)
22 | {
23 | if (!(obj is CustomObject co)) return false;
24 | var ct = this;
25 |
26 | var t = co.Type;
27 | if (t == ct) return true;
28 | if (ct.IsArray != co.Type.IsArray) return false;
29 |
30 | return t.Class.Is(ct.Class);
31 | }
32 | public override string ToString() => FullName;
33 | public override bool Equals(object obj)
34 | {
35 |
36 | if (obj is CustomType) return obj == this;
37 | return base.Equals(obj);
38 | }
39 |
40 | static Dictionary Types = new Dictionary();
41 | public static CustomType Get(ScriptClass c, bool isArray = false)
42 | {
43 |
44 | string name = c.ClassFullName;
45 | if (isArray) name += "[]";
46 | CustomType t;
47 | if (Types.TryGetValue(name, out t)) return t;
48 | t = Types[name] = new CustomType(name, c);
49 | return t;
50 | }
51 |
52 | public override int GetHashCode()
53 | {
54 | return FullName.GetHashCode();
55 | }
56 |
57 | public object Call(Executor exec, string fnName, params object[] args)
58 | {
59 | if (!IsArray)
60 | return DynFuncCall(exec.GetStaticInstance(Class), fnName, args);
61 | else
62 | throw new InvalidOperationException("Cannot call a function on this type.");
63 |
64 | }
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/OverScript/ClassInstance.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OverScript
4 | {
5 | public class ClassInstance
6 | {
7 | public int Scope;
8 | public ScriptClass Class;
9 | public bool IsStatic;
10 | public CustomObject ThisObj;
11 | public Executor Exec;
12 |
13 | private ClassInstance()
14 | {
15 | Scope = -1;
16 | Exec = Executor.GetConstExecutor();
17 | }
18 | public static ClassInstance GetConstInst() => new ClassInstance();
19 |
20 | public ClassInstance(Executor exec, ScriptClass scriptClass, EvalUnit[] args = null, ClassInstance srcInst = null, int baseScope = -1, bool isStatic = false, bool ignoreConstructor = false, object constrFn = null)
21 | {
22 | Class = scriptClass;
23 | Scope = exec.NewScope();
24 |
25 | IsStatic = isStatic;
26 | Exec = exec;
27 |
28 | ClassInstance ci = this;
29 |
30 | CallStack cstack = null;
31 | if (!isStatic)
32 | {
33 |
34 | if (Class.InstanceFuncs != null)
35 | for (int i = 0; i < Class.InstanceFuncs.Length; i++) Class.InstanceFuncs[i](args, baseScope, srcInst, ci, cstack, null);
36 |
37 | if (!ignoreConstructor)
38 | {
39 | if (constrFn != null)
40 | {
41 |
42 | var fn = (ScriptClass.FuncToCall