Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Bird Programming Language: Part 1

, 1 Jan 2013 GPL3
A new general purpose language that aims to be fast, high level and simple to use.
Bird-noexe.zip
Bird
Archives
crt2.o
crtbegin.o
crtend.o
libadvapi32.a
libcomctl32.a
libcomdlg32.a
libgcc.a
libgdi32.a
libglu32.a
libkernel32.a
libmingw32.a
libmingwex.a
libmoldname.a
libmsvcrt.a
libopengl32.a
libshell32.a
libstdc++.a
libuser32.a
libwinmm.a
libwsock32.a
Libraries
BirdCore
Array.bird
BigInteger.bird
BinaryRW.bird
BirdCore.a
BirdCore.blib
CategoryData.dat
Console.bird
Convert.bird
Debug.bird
Entry.bird
Environment.bird
Exception.bird
Float.bird
LEB128.bird
Math.bird
Memory.bird
Object.bird
Random.bird
Reflection.bird
StandardC.bird
Stream.bird
String.bird
ToLowerData.dat
ToUpperData.dat
Types.bird
ValueType.bird
Win32.bird
x86Helper.bird
BlitzMax
.bmx
Launcher.bmx.gui.release.win32.x86.o
appstub.release.win32.x86.a
bank.release.win32.x86.a
bankstream.release.win32.x86.a
blitz.release.win32.x86.a
BlitzMax.a
BlitzMax.bird
BlitzMax.blib
d3d7max2d.release.win32.x86.a
d3d9max2d.release.win32.x86.a
directx.release.win32.x86.a
dxgraphics.release.win32.x86.a
event.release.win32.x86.a
filesystem.release.win32.x86.a
font.release.win32.x86.a
glgraphics.release.win32.x86.a
glmax2d.release.win32.x86.a
graphics.release.win32.x86.a
hook.release.win32.x86.a
keycodes.release.win32.x86.a
Launcher.bmx
libpng.release.win32.x86.a
linkedlist.release.win32.x86.a
math.release.win32.x86.a
max2d.release.win32.x86.a
opengl.release.win32.x86.a
pixmap.release.win32.x86.a
pngloader.release.win32.x86.a
polledinput.release.win32.x86.a
standardio.release.win32.x86.a
stdc.release.win32.x86.a
stream.release.win32.x86.a
system.release.win32.x86.a
textstream.release.win32.x86.a
win32.release.win32.x86.a
zlib.release.win32.x86.a
PrgLinec.bmx
Samples
Circles
Circles.bird
CppMain.bird
Fire
Fire.bird
Higher Order Functions
C#
Higher Order Functions.v11.suo
Properties
Test.bird
msvcrt.lib
Reflection
Reflection.bird
Squares
Squares.bird
Template
Template.bird
Source
Base
Bird.v11.suo
Expressions
Identifiers
Languages
NativeCode
Properties
Recognizers
Expressions
Scopes
x86
Thumbs.db
Bird.zip
crt2.o
crtbegin.o
crtend.o
libadvapi32.a
libcomctl32.a
libcomdlg32.a
libgcc.a
libgdi32.a
libglu32.a
libkernel32.a
libmingw32.a
libmingwex.a
libmoldname.a
libmsvcrt.a
libopengl32.a
libshell32.a
libstdc++.a
libuser32.a
libwinmm.a
libwsock32.a
Binaries
ar.exe
Bird.exe
fasm.exe
ld.exe
libiconv-2.dll
libintl-8.dll
Array.bird
BigInteger.bird
BinaryRW.bird
BirdCore.a
BirdCore.blib
CategoryData.dat
Console.bird
Convert.bird
Debug.bird
Entry.bird
Environment.bird
Exception.bird
Float.bird
LEB128.bird
Math.bird
Memory.bird
Object.bird
Random.bird
Reflection.bird
StandardC.bird
Stream.bird
String.bird
ToLowerData.dat
ToUpperData.dat
Types.bird
ValueType.bird
Win32.bird
x86Helper.bird
Launcher.bmx.gui.release.win32.x86.o
appstub.release.win32.x86.a
bank.release.win32.x86.a
bankstream.release.win32.x86.a
blitz.release.win32.x86.a
BlitzMax.a
BlitzMax.bird
BlitzMax.blib
d3d7max2d.release.win32.x86.a
d3d9max2d.release.win32.x86.a
directx.release.win32.x86.a
dxgraphics.release.win32.x86.a
event.release.win32.x86.a
filesystem.release.win32.x86.a
font.release.win32.x86.a
glgraphics.release.win32.x86.a
glmax2d.release.win32.x86.a
graphics.release.win32.x86.a
hook.release.win32.x86.a
keycodes.release.win32.x86.a
Launcher.bmx
libpng.release.win32.x86.a
linkedlist.release.win32.x86.a
math.release.win32.x86.a
max2d.release.win32.x86.a
opengl.release.win32.x86.a
pixmap.release.win32.x86.a
pngloader.release.win32.x86.a
polledinput.release.win32.x86.a
standardio.release.win32.x86.a
stdc.release.win32.x86.a
stream.release.win32.x86.a
system.release.win32.x86.a
textstream.release.win32.x86.a
win32.release.win32.x86.a
zlib.release.win32.x86.a
PrgLinec.bmx
PrgLinec.exe
Circles.bird
CppMain.bird
Fire.bird
Higher Order Functions.v11.suo
Test.bird
msvcrt.lib
Reflection.bird
Squares.bird
Template.bird
Bird.v11.suo
Thumbs.db
examples.zip
Examples
As.exe
AsLibs.a
PerfTest
Launcher.bmx
Squares
.bmx
Launcher.bmx
Template
Launcher.bmx
source.zip
Anonymus 7_1
Anonymus.csproj.user
Anonymus.idc
Anonymus.pidb
Anonymus.suo
Anonymus.userprefs
Base
Expressions
Lib
Long
LongDivTest.bmx
ULongConv.bmx
Math
MISZ
AsLibs.a
PerfTest
Launcher.bmx
Squares
Launcher.bmx
Template
Launcher.bmx
PrgLinec.bmx
PrgLinec.exe
Properties
Scopes
Txt
Asm.docx
Code.docx
Lib.aslib
~$Code.docx
x86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bird.Recognizers
{
	public class AlignModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string String = "align";

		public AlignModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var State = Container.State;
			CodeString Inside, Cutted;

			var Result = RecognizerHelper.ExtractBracket(State, String, '(', ref Code, out Inside, out Cutted);
			if (Result == SimpleRecResult.Succeeded)
			{
				var Params = RecognizerHelper.GetParamList(State, Inside, 1);
				if (Params == null) return SimpleRecResult.Failed;

				var Node = Constants.CreateCIntNode(Container, Params[0]);
				if (Node == null) return SimpleRecResult.Failed;

				var Align = (int)Node.Integer;
				if (!DataStoring.VerifyAlign(Align))
				{
					State.Messages.Add(MessageId.InvalidAlign, Cutted);
					return SimpleRecResult.Failed;
				}

				for (var i = 0; i < Out.Count; i++)
					if (Out[i] is AlignModifier)
					{
						State.Messages.Add(MessageId.NotExpected, Cutted);
						return SimpleRecResult.Failed;
					}

				Out.Add(new AlignModifier(Cutted, Align));
				return SimpleRecResult.Succeeded;
			}

			return Result;
		}
	}

	public class CallingConventionRecognizer : LanguageNode, IModRecognizer
	{
		public static string[] Strings = new string[] { "stdcall", "cdecl", "birdcall" };

		public CallingConventionRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));
			if (Result.Index != -1)
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, Result.String.Length);

				for (var i = 0; i < Out.Count; i++)
					if (Out[i] is CallingConventionModifier)
					{
						State.Messages.Add(MessageId.NotExpected, ModCode);
						return SimpleRecResult.Failed;
					}

				CallingConvention Conv;
				if (Result.Index == 0) Conv = CallingConvention.StdCall;
				else if (Result.Index == 1) Conv = CallingConvention.CDecl;
				else if (Result.Index == 2) Conv = CallingConvention.BirdCall;
				else throw new NotImplementedException();

				Out.Add(new CallingConventionModifier(ModCode, Conv));
				Code = Code.Substring(Result.String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}

		public string GetCallingConventionName(CallingConvention Conv)
		{
			if (Conv == CallingConvention.StdCall) return Strings[0];
			else if (Conv == CallingConvention.CDecl) return Strings[1];
			else if (Conv == CallingConvention.BirdCall) return Strings[2];
			else throw new NotImplementedException();
		}
	}

	public class AccessModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string[] Strings = new string[] { "public", "protected", "private", "internal" };

		public AccessModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));
			if (Result.Index != -1)
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, Result.String.Length);

				IdentifierAccess Access;
				if (Result.Index == 0) Access = IdentifierAccess.Public;
				else if (Result.Index == 1) Access = IdentifierAccess.Protected;
				else if (Result.Index == 2) Access = IdentifierAccess.Private;
				else if (Result.Index == 3) Access = IdentifierAccess.Internal;
				else throw new NotImplementedException();

				for (var i = 0; i < Out.Count; i++)
				{
					var AccessMod = Out[i] as AccessModifier;
					if (AccessMod != null)
					{
						var Allowed = false;
						if (Access == IdentifierAccess.Internal)
							Allowed = AccessMod.Access == IdentifierAccess.Protected;
						else if (Access == IdentifierAccess.Protected)
							Allowed = AccessMod.Access == IdentifierAccess.Internal;

						if (!Allowed)
						{
							State.Messages.Add(MessageId.NotExpected, ModCode);
							return SimpleRecResult.Failed;
						}
					}
				}

				Out.Add(new AccessModifier(ModCode, Access));
				Code = Code.Substring(Result.String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}
	}

	public class FlagModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string[] Strings = new string[]
		{
			"virtual", "override", "abstract", "sealed", "static", "extern", "readonly", "new"
		};

		public FlagModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));
			if (Result.Index != -1)
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, Result.String.Length);

				IdentifierFlags Flags;
				if (Result.Index == 0) Flags = IdentifierFlags.Virtual;
				else if (Result.Index == 1) Flags = IdentifierFlags.Override;
				else if (Result.Index == 2) Flags = IdentifierFlags.Abstract;
				else if (Result.Index == 3) Flags = IdentifierFlags.Sealed;
				else if (Result.Index == 4) Flags = IdentifierFlags.Static;
				else if (Result.Index == 5) Flags = IdentifierFlags.Extern;
				else if (Result.Index == 6) Flags = IdentifierFlags.ReadOnly;
				else if (Result.Index == 7) Flags = IdentifierFlags.HideBaseId;
				else throw new NotImplementedException();

				for (var i = 0; i < Out.Count; i++)
				{
					var FlagMod = Out[i] as FlagModifier;
					if (FlagMod != null && (FlagMod.Flags & Flags) != 0)
					{
						State.Messages.Add(MessageId.NotExpected, ModCode);
						return SimpleRecResult.Failed;
					}
				}

				Out.Add(new FlagModifier(ModCode, Flags));
				Code = Code.Substring(Result.String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}
	}

	public class ParamFlagModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string[] Strings = new string[] { "params" };

		public ParamFlagModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));
			if (Result.Index != -1)
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, Result.String.Length);

				ParameterFlags Flags;
				if (Result.Index == 0) Flags = ParameterFlags.ParamArray;
				else throw new NotImplementedException();

				for (var i = 0; i < Out.Count; i++)
				{
					var FlagMod = Out[i] as ParamFlagModifier;
					if (FlagMod != null && (FlagMod.Flags & Flags) != 0)
					{
						State.Messages.Add(MessageId.NotExpected, ModCode);
						return SimpleRecResult.Failed;
					}
				}

				Out.Add(new ParamFlagModifier(ModCode, Flags));
				Code = Code.Substring(Result.String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}
	}
	public class ConstModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string String = "const";

		public ConstModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			if (Code.StartsWith(String, new IdCharCheck(true)))
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, String.Length);
				
				for (var i = 0; i < Out.Count; i++)
					if (Out[i] is ConstModifier)
					{
						State.Messages.Add(MessageId.NotExpected, ModCode);
						return SimpleRecResult.Failed;
					}

				Out.Add(new ConstModifier(ModCode));
				Code = Code.Substring(String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}
	}

	public class AssemblyNameRecognizer : LanguageNode, IModRecognizer
	{
		public static string String = "asmname";

		public AssemblyNameRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			var State = Container.State;
			CodeString Inside, Cutted;

			var Result = RecognizerHelper.ExtractBracket(State, String, '(', ref Code, out Inside, out Cutted);
			if (Result == SimpleRecResult.Succeeded)
			{
				var Params = RecognizerHelper.GetParamList(State, Inside, 1);
				if (Params == null) return SimpleRecResult.Failed;

				var Node = Constants.CreateCStrNode(Container, Params[0]);
				if (Node == null) return SimpleRecResult.Failed;

				var AsmName = Node.String;
				if (string.IsNullOrEmpty(AsmName))
				{
					State.Messages.Add(MessageId.DeficientExpr, Params[0]);
					return SimpleRecResult.Failed;
				}

				for (var i = 0; i < Out.Count; i++)
					if (Out[i] is AssemblyNameModifier)
					{
						State.Messages.Add(MessageId.NotExpected, Cutted);
						return SimpleRecResult.Failed;
					}

				Out.Add(new AssemblyNameModifier(Cutted, AsmName));
				return SimpleRecResult.Succeeded;
			}

			return Result;
		}
	}

	public class NoBaseModifierRecognizer : LanguageNode, IModRecognizer
	{
		public static string String = "nobase";

		public NoBaseModifierRecognizer(LanguageNode Parent)
			: base(Parent)
		{
		}

		public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List<Modifier> Out)
		{
			if (Code.StartsWith(String, new IdCharCheck(true)))
			{
				var State = Container.State;
				var ModCode = Code.Substring(0, String.Length);

				for (var i = 0; i < Out.Count; i++)
					if (Out[i] is NoBaseModifier)
					{
						State.Messages.Add(MessageId.NotExpected, ModCode);
						return SimpleRecResult.Failed;
					}

				Out.Add(new NoBaseModifier(ModCode));
				Code = Code.Substring(String.Length).Trim();
				return SimpleRecResult.Succeeded;
			}

			return SimpleRecResult.Unknown;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Dávid Kocsis
Student
Hungary Hungary
I've been programming for 8 years. My first big project was a remake of a nice bomberman game called Dyna Blaster. When i was little i played a lot with it. Now i'm working on a new programming language and code generator.
I would like to work with someone, so feel free to contact me about it.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 1 Jan 2013
Article Copyright 2011 by Dávid Kocsis
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid