Thursday, June 7, 2012

Your own Programming language - SCT

This is an article that gives a tutorial on redefining C++ syntax with SCT. The documentation is pretty straightforward, but this will show step-by-step how to make your own language in a few easy steps. Disclaimer: This is not really a programming language. You are just redefining some syntax here. If you TRULY want a programming language you should look into compiler design.

1) Download SCT
SCT is my own free product and I have it hosted here on Github. If you are on a debian-based system you can install the .deb (you may get a standard compliance warning if you use the Ubuntu software center. It's Okay to install this file. If you don't believe me, look at the source on Github). Otherwise, you will have to download the executable file ( in bin) and run it directly.

2) Make a langdefines.ldf
This is a type of file that holds a language. The syntax is old_new. You can use "$" for commenting, but not on its own line. For instance:
old_new$oldnew$
oldnew would not become part of this line. Here is how you could set it up to work with a hello world application for C++.

#include_import
std_txt
<<_<--
cout_say
endl_eol

3) Make a code file
You can now make a code file. It is just a normal text file that adheres to the langdefines rules. However, you can include strings that the langdefines does not know; they will just not be translated. In fact, this is the only way to get some characters into code.

import <iostream>
using namespace txt;
int main(){
say <-- "Hi!" <--eol;

Of course, this is an overly simplistic example. Langdefines can contain up to 10,000 lines.

4) Run sct
You should run "sct" from the command line (if you used the .deb) or just run the executable. Here is what to do at each prompt:

What is the total file path to the language definition file?
$ /home/yourname/example.ldf


this one is pretty self explanatory. Where is your langdefines?



Would you like the langdefines automatically ordered? y or n
$ y
This one causes some confusion. Before I explain what this does, take an example.
You have a langdefines that reroutes || to or like this: ||_or. However, below it you have this: for_door. This will become "do||" in the code, causing a massive error. Ordering the langdefines by line size helps to prevent this. Ordering is not foolproof, however. Comments are DELIBERATELY COUNTED. If you want a particular line to be longer than the other for this reason, it is a good way to do it. Be careful with comments for this reason.

Are you using a Noran Make File? y/n
$ n
A Noran Make File is like a make file, but it specifies a list of files to translate at one time. The syntax is infile_outfile_magichar for every line. infile is the code, outfile is the output filepath, and magichar is what character you used for translation comments. Translation comments allow strings that you KNOW will be translated be preserved. In our above example, you could save "door" by doing $door$ and using $ as your magichar. $ is the standard.

If you did not use a Noran Make File, this is what the rest of the program will be:
 What is the total file path to the code?
$ /home/yourname/excode
This is where your code is located.

What is the file path to the output file?
$ /home/yourname/whatever.cpp

Finally, this is where to put the translated code.


If you would like to easily call this form other programs, it can run in argument mode, but it does not support iterative compiling.


Congratulations. You have now redefined C++ syntax and converted code that you wrote in your own custom language into runnable C++.

PS: Here is what my language looks like:

import <iostream>
use nspace std;
number program() (*
itl(number index is 0; index lthen 10; index`incra`)
say <-- "$Hello world, Iteration $"<--index<--eol;
mail 0;
*)


Wednesday, June 6, 2012

What is ipv6 day?

Ipv6 is the next generation of IP addresses. Like going from 3g to 4g on cellular phones, there will be a slight increase in efficiency of data transfer. This is not the main goal of ipv6.

We are currently using ipv4, which uses 32 bit addresses. Due to the limited amount of spaces provided by ipv4, we are literally running out. ipv6 uses a 128-bit address, making the number of addresses that can be assigned much larger than ipv4 could ever dream of assigning. This will end the need for network  address translation, which was a hack thrown in to conserve space.

Ipv6 day is a worldwide release of the new protocol. Companies such as Google, Facebook, and Cisco will permanently give their users access to ipv6. This is a large step forward for ipv6, which is actually quite an old protocol (almost 13 years). The ipv6 will run alongside ipv4, so those stuck with ipv4 can still use the site's services.

Last year, there was a test of the protocol. It worked well, so the companies that participated began preparing for the final release of ipv6. This year, many companies are permanently dishing out ipv6 access.

http://ipv6-test.com/
This website will test to see if you truly have ipv6 enabled. If you don't it could be the fault of your internet service provider, of which many do not offer ipv6 yet. The Internet Society is urging people to contact their ISPs and recommend that they implement ipv6 as soon as possible.

Ipv6 may be a few more months or years away, depending on which internet service provider and type of computer you use. If you use Windows, you will need to upgrade beyond Windows 2000. The latest 3 versions of OS X are compatible. All versions of current Linux and BSD operating systems have ipv6 as they are commonly used for networking.

Saturday, June 2, 2012

How to make a website (Linux)

The internet is a hard subject to grasp if you do not understand networking. All it is is a system of servers connected by an internet service provider, which give you access to all of these servers. There is nothing special about a server, either. It is just a computer like the one you are using. You too can set up a website to use locally and over the internet. Here is how to do it in any variant of Gnu/Linux that has Apache and Kompozer (optional).

This article assumes that you have no knowledge of HTML (The Hypertext Markup Language), which is what websites are technically written in. Instead we will use a program called kompozer that is generates HTML similar to how blogger does.

Run these two commands to get started:

sudo apt-get install apache2
sudo apt-get install kompozer

The first command installs the server software and the second installs kompozer, the editor we will be using. After you install apache2, a directory named "www" will be created in /var. This is where you will place the file named "index.html".

You can link to other pages from the main one by making a link with the name of a file in /var/www or any other file on the computer.

Write the Webpage
 Run kompozer with root privileges. (sudo kompozer). You are going to be saving the file in /var/www which is a protected directory by default. Now, all you have to do is... write. Kompozer has all of the tools you will need to make your basic web page. Add text, links, bold text, italicized text, pictures, or whatever you need. If you need mroe power you can edit the HTML directly from the "source" tab if you must. When you are done writing your web page, save it.

The first dialog that will come up will ask you for a title. Name it whatever you want the name of this page to be. This will appear in tabs and on some window lists. Hit okay, and save it as "index.html" in /var/www.

Viewing
You now have a website available on your machine to the world wide web and to your local network. Find your ip address by typing

ifconfig

into the terminal. The wlan address is your IP address. Your local network can access the webpage from this address. To view it from anywhere in the world, you need to port forward your router. To do so, look up your router's manual on port forwarding. My router has an "advanced" dialog at 192.168.0.1, so that may be a good place to start looking. After the forwarding has been set up, you can go to http://your_public_ip to see your website. Typing "ip" into a google search will show you your public IP to use.

Open Source Development Model

Many people do not understand what the term "Free" (in the sense of libre) means to the fullest of its power when it relates to software. Many confuse it with free as in free beer, or "gratis" as Linux creator Linus Torvalds calls it. This is an in-depth comparison between the two terms and how it relates to software.

Common misconceptions
Whenever I bring up the subject of open-source software with somebody who does not write code, they always use the same argument. "So, what? You don't think that people should be rewarded for what they do?" In fact, this is why many people associate open-source supporters with the communist party. However, this is not the case. Projects where a lot of the code is open-source (such as OS X or Android) still generate tons of cash. Advertising also draws a huge monetary gain for open-source developers.  In all revisions of the GNU GPL selling free software is strongly encouraged, showing that it can and is done.

Simply releasing the code does not make a program free (in the definition of the Free Software Foundation). To be free it must be licensed under a license that stops it from becoming proprietary in the future. In my "travels" I met a man that was a fan of the BSD license, boasting that it was even more free than the GNU GPL. However, the project he was referencing was not original. Had it been a few years later that he decided to maintain the project, it may have already become depracted by a proprietary variant.

Unlimited Potential
The difference in the development models of proprietary and open source development is described in "The Cathedral and the Bazaar". They differ in one key area: who writes the code.

In a closed-source development model, a developer or team of developers work on one copy of a product and release it to the public. Only they can monitor the code and they are wholly responsible for fixing bugs and making the code more efficient. This costs man hours, and it is why a lot of payed programs are proprietary.

On the other hand, Open Source development happens in a much more community-esque fashion. An author or team of authors conceives a product and begin development, and either immediately or at a point where the barebones functionality has been met they release it to the public under a free license. Up to this point the style this happens is much like a closed-source model, but the magic of open source occurs at the next step. Any hobbyist or paid programmer (some companies actually pay developers to write free code) in the world (if it is hosted on the internet) can write bug fixes and new features for the program. They can also host their own variant of the program if they feel their addition changes the functionality or aesthetics too much.

The Downside
The weakness of the Open Source model is the same as its strength: anyone can see the source. Crackers, malaware authors, or anyone wishing to break a system can analyze the code, find the weaknesses, and write exploits for them. However, whenever a gap is released it is usually spotted and squashed within weeks.

Tuesday, May 29, 2012

Setting up and FTP server in Linux

This tutorial is for Gnu/Linux operating systems. Windows users can use the filezilla server: http://filezilla-project.org/download.php?type=server

A server is the name given to a piece of hardware running software that allows it to interact with client computers. All websites run on servers. This is a tutorial that uses a set of tools to configure a special type of server that uses FTP, the File Transfer Protocol. This is used for the transfer of files between computers. It is similar to what cloud storage services such as Dropbox or Skydrive offer.

The tools
To get the server running we will be using gadmin-proftpd. This is a GTK+ frontend to proftpd, the command line tool. Download it from sudo apt-get install gadmin-proftpd. Run it and enter the root password. The next few sections will describe each tab you need to fill in.

Servers
You need to fill in some of these blank fields. For Server Address use the inet addr from wlan of the ifconfig output in the terminal. The server name can be anything. Admin email should be your real email address. Skip down to where it says "signed certificate settings". You should fill this information in and use the "Apply" button to make a new certificate. Failure to complete this step of the setup process is what causes most errors with gadmin-proftpd.

Users
Users is the last tab you should have to fill out.  Fill in the username and password as you want them. Others will need to fill in this information, so make it reasonable. Go to the bottom and click "Add Directory". You should make a directory in /var/www called ftp (it can be called whatever you want it to be) that will act as this new user's directory. This will become the root ftp directory for that user (kind of like / for a normal user). If you want full access over a machine, make this "/".  Click "New User". This user will now be created.

Afterwards
 At the top of the application, click "Activate". The server will then be running. To access the server, go to your browser and type: "ftp://[your ip]" where [your ip] is you full ip address. To add directories and upload data you will need a program like bareftp, (sudo apt-get install bareftp) filezilla (which doesn't play nice with proftpd servers), or a windows program like coreftpd.

Extras
This is a local server only. You can make it point to the internet in your router settings. Your router setup (the ip address of your router, sometimes 192.168.0.1) should have some type of "advanced" dialog where you can set up your server. FTP runs on port 21, so you would need to fill in the protocol, port, and IP address wherever the dialog may ask for it. If it asks for a name like our D-link router does, fill it in with the name of your computer. Now, when you visit your external ip address (find this with "ip" on google) using the ftp protocol it will go to your server.

You can also use a no-ip.com host (which are free) to avoid the need to remember the ip address of the server.

Saturday, May 26, 2012

SCT - A custom language code translator

I have been hard at work working on a translator. At last, it has been complete. The translator is a very lightweight program that analyzes a file and a dictionary to translate them between user specified languages. This means that every user on the planet can have their own custom programming language and still be able to convert it into C++. Here is how it works:

 SCT - The translator
Specific Code Translator, SCT for short, analyzes two files. One is called a langdefines. The other is the code written in the language specified in the langdefines file. Here is how it works:

Every langdefines file has this syntax: old_new. So, if we wanted to specify the keyword "void" being "nothing" in a new language the syntax would be: void_nothing in the langdefines. Commenting and newlines are not yet supported in the langdefines file, but support for both are coming in future updates.Whitespace is readable.

Then, the translator will pick apart the langdefines and parse each individual side into two separate arrays. After setup, translation happens.

The translator will read a code file specified by the user as well as reading in the output file and a magichar. More about those two later, though.

The translator will replace new strings with old strings, thus converting it back into the language on the left. However, this is very specific, which is why Specific is the first word of the program. What may seem like design flaws are actually features to enable maximum usage of the translator.

The translator will replace EVERY string matching in the arrays. To avoid things like cout << "torch" from becoming cout << "t||rch" you have to use the sensitive strings feature. Sensitive strings in the code are not parsed, which gives them safety. Output, comments, variable names, etc. should all go in sensitive strings. You use a magichar to specify a sensitive string. The sensitive string goes in between two magichars specified at run time, like so: cout << "$torch$"
Neither torch nor the "$"s will appear in the code.

Advantages
You can use this program in a number of ways, including fixing massive spelling mistakes in documents, creating a custom syntax for a programming language, or for just showing off to your friends your new language. The way SCT works allows for "inline" coding, meaning that if you were to use it to add some pizazz to C++'s syntax you could still use C++ if you wanted to.

Future Plans
There are a few more plans in store for the program. I want to make reverse translation easier than messing with the code directly and I want to improve the syntax of the langdefines file.

The necessary files are all at my github. My custom langdefines is for a language I call NRSL. Some people that I have asked have Really hated the syntax, so go ahead and judge for yourself.

Thursday, May 10, 2012

C++ - Understanding Pointers

Pointers are a shockingly complex yet very simple thing to master in C++. The idea of a pointer is easy for most, yet the implementation can be a bit tricky for some.

Below is a quick example showcasing pointers. Comments are lingual representations of each line.

int x = 10; //Initialize integer x to 10.
int *px=&x; //Point variable px to the memory address (&) of x.

cout << px <<endl;/*Output the value of px, which is the numeral string representing the memory address of x.*/

cout << *px<<endl;/*Output the value of what px is pointing to.*/

int **ppx=&px;/*Initialize pointer ppx to point at the memory address of px, the pointer of x.*/

cout << *ppx<<endl;/*Output the contents of what ppx holds, which is the memory address of x.*/

cout << **ppx<<endl;/*Output the value of what the pointer this pointer points to is pointing at*/

**ppx+=1;/*The chain of pointers as displayed in the comment above happens and assigns variable x to 1. This is the same as *px=1; and x=1;*/

So, as you can see, pointers are a somewhat confusing concept. Your next question may be "Why even use them?" Well, the answer is: you shouldn't. Only use pointers in situations when they are required by the language or for a considerable performance gain, such as function parameters. This is called passing by reference since you give the reference to a variable's memory address rather than the value of the variable itself. This means that functions do not have to work with copies. You can make functions look like they take value rather than reference by doing something like this:

void doStuff(int &param){}  
This passes by reference because of the "&" operator, which returns the memory address of the parameter rather than the parameter itself. Now, the function can be called exactly like it were pass by value, like so:

doStuff(arg);  

 Pointers are not useless. They are extremely useful since you can have multiple pointers pointing to the same variable and even pointers pointing to other pointers. This comes in especially handy with multithreading.