I Made A Parser

I made a parser

I made a parser for ~ATH in addition to the interpreter. I might make the interpreter use the parser at some point in the future, or I might not. If I made the interpreter use the parser, the code for the interpreter would probably be a little cleaner, and possibly a little faster.

The parser is available from my github.

To use it, call tokenize on the text, and then read_all_from on the result of tokenize.

The output will be a list of lists

https://github.com/drocta/TILDE-ATH-Parser

(haven't updated lately because of other unrelated projects, and also other reasons that aren't necessary to describe)

More Posts from Learn-tilde-ath and Others

11 years ago
Learn ~ATH Turned 1 Today!

Learn ~ATH turned 1 today!

yaaaay!

So I think that my explanations of things hasn't been very clear so far, and while I can't promise that they will improve, I do intend to teach programming in person at my school, which might help me to know how to make this tutorial better. Maybe, maybe not. 

May things go well!


Tags
12 years ago

reading the contents of user input, and calculator improvement

This post will cover how to actually determine WHAT the user has typed, instead of just how long it is. It will also include how to interpret what the user enters as a binary number, so that its easier to type.

An Essential part of making it interpret binary numbers is making it double numbers repeatedly.

This actually has a few ways that can be done, so this is one of the first situations where coding style for this problem might differ from person to person. Because of this, I will say more than one way to do it.

The first way to do this it to copy the number twice, and then start from zero and add both of the copies. This is relatively inefficient, and would take

a copy thing, consisting of two bifurcates (which would take a little time)

where the size of the initial number is N, 2N normal bifurcates, 2N reverse bifurcates, and 4N lines relating to the actual loop

assuming each command takes the same amount of time (which is an oversimplification) this would take 9N+C line times. (C is a constant) This might be acceptable, but there is a more efficient and nicer looking way.

The second way is nicer looking, but still not the most effecient. However, when multiplying by a larger number(such as 3, or 4, or even large numbers), this method is part of what would be used.

The second method is essentially copying the number (using a reverse bifurcate and a normal bifurcate), and then adding the number to zero, except instead of each loop increasing the new number by one, it increases it by two. This is shorter, and it looks nicer. It also only takes half as many normal bifurcates. As a result, the number of steps it would take (again assuming each step is the same length) is 8N+C, instead of 9N+C 

this one I will write out, but it is still not the best way:

//N is the number initially BIFURCATE [NULL,NULL]2NULL; BIFURCATE [N,N]G; BIFURCATE G[NCOPY,JUNK]; BIFURCATE 2NULL[RESULT,JUNK]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,RESULT]RESULT; BIFURCATE [BLAH,RESULT]RESULT; } 

ok, so yeah. that takes N, and puts twice N into RESULT, but it is still inefficient.

A more efficient version is to copy the initial number, and add the number to itself. This way you only have to do half the number of reverse BIFURCATE statements. This is much more efficient, taking instead the steps:

a copy thing, consisting of two bifurcates (which would take a little time)

where the size of the initial number is N, N normal bifurcates, N reverse bifurcates, and 2N lines relating to the actual loop

This has 7N+C steps, which is a significant improvement. I think it is the fastest way to double a number in drocta ~ATH.

It is as follows (N is the number)

BIFURCATE [N,N]G; BIFURCATE G[NCOPY,RESULT]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,RESULT]RESULT; } 

This is shortest and fastest solution I have found. If you find a shorter or faster method, please tell me.

Ok. Now we can double numbers. That is good. That is an important step. But we still haven't gotten user input to be read in any reasonable way.

Hang on, I'm GETTING TO THAT. GEEZ. (I'm kidding, no one has been complaining about my taking so long, other than myself)

Ok, so here goes:

To interpret the binary number input and convert it to a "number", we can follow the following algorithm:

start with zero.(this is before the loop)

If there are any characters left, double the number that is being created.

remove the first character from the remaining characters. If it is "1" or whatever symbol (or alternatively if it is not "0"), add one to the number that is being created. Otherwise, continue onto step 4 without doing anything first.

go back to the start of the loop (step 2)

Ok. thats the algorithm we are going to use. But I STILL haven't explained how to recognize what the next character is. Seriously what is up with that?

What you do is you bifurcate the rest of the input into [the next character,the rest of the input].

Now you have the next character. Then what you do is you reverse bifurcate it with some other object, and then you check whether that object is already dead or not.

But how do you make it so the combination is already dead? How do you get the object for the character before the user has even inputed it?

Answer: You don't. Not in the current version of drocta ~ATH anyway. You will have to tell the user to enter all the characters they will be using ahead of time. Yes this is horrible and stupid. No its not exactly like that in the comic. Its ~ATH what do you expect? :P

that might change in future versions, but I will try to stay backwards compatible with that.

but anyway, back to comparing it:

so you say something along the lines of:

import comparingobject CMP1; othercodehere makeNEQ1besomethingalive BIFURCATE [CMP1,CHAR]EQ1; BIFURCATE [NULL,NULL]2NULL; ~ATH(EQ1){ print yep, they are equal; BIFURCATE 2NULL[EQ1,NEQ1]; } ~ATH(NEQ1){ print nope, they are not equal; BIFURCATE 2NULL[NEQ1,JUNK]; }  

in the othercodehere you get the character a head of time, and say BIFURCATE[CMP1,THECHARTHATMATCHESWITHCMP1]D; D.DIE();

That makes it so that it will go through the one section of code if the character is the right one, but something else if it is something else.

Which is what we want.

So to put it all together, and make the thing that interprets the input as a binary number(hold on tight(ok, what, why did I say that), this will be a long one(why am I talking like this?)):

import blah BLAH; print please enter whatever character you will be using for binary zero.; INPUT ZEROCHAR; BIFURCATE ZEROCHAR[ZEROCHAR,JUNK]; import chrcmp CMP0; BIFURCATE [CMP0,ZEROCHAR]D; D.DIE(); print please enter whatever character you will be using for binary one.; INPUT ONECHAR; BIFURCATE ONECHAR[ONECHAR,JUNK]; import chrcmp CMP1; BIFURCATE [CMP1,ONECHAR]D; D.DIE(); BIFURCATE [NULL,NULL]2NULL; BIFURCATE 2NULL[OUTNUM,JUNK]; print please input the binary number you want.(it will be converted to unary); INPUT BINNUM; ~ATH(BINNUM){ BIFURCATE [OUTNUM,OUTNUM]G; BIFURCATE G[NCOPY,OUTNUM]; ~ATH(NCOPY){ BIFURCATE NCOPY[JUNK,NCOPY]; BIFURCATE [BLAH,OUTNUM]OUTNUM; }  BIFURCATE BINNUM[CHAR,BINNUM]; BIFURCATE [CMP0,CHAR]NEQ0; ~ATH(NEQ0){ BIFURCATE [BLAH,OUTNUM]OUTNUM; BIFURCATE 2NULL[NEQ0,JUNK]; } } print ok, going to print it out in unary, with each digit on one line. If the number you entered was large you might want to close the program instead of hitting enter.; INPUT JUNK; BIFURCATE [OUTNUM,OUTNUM]GOUTNUM; BIFURCATE GOUTNUM[OUTNUMCOPY,JUNK]; ~ATH(OUTNUMCOPY){ BIFURCATE OUTNUMCOPY[JUNK,OUTNUMCOPY]; print 1; } print Am I a terrible person for writing this?; 

Oh gosh. I wish I could indent in tumblr. that is terrible to read. tumblr is a terrible source code editor.

One time someone called me a masochaist for writing this type of stuff.

And then we just have to put that together with the adding thing, and then maybe add a better way of outputting the number. maybe in binary.

HAHAHAHAH

ok, yeah, I'm going to put it together in the next post, not this one, because I have to homework now.(using the noun homework as a verb was intentional)

yeah. putting it together in the next post.

As always, if something was confusing, please ask for clarification.


Tags
12 years ago

Welcome.

If its not obvious, this blog will teach techniques in a version of ~ATH Specifically, drocta ~ATH. And yes, I'm serious. I believe that I probably am the author of the longest ( possibly up to third longest) ~ATH program. Specifically, bubble sort. Further, I believe I am the author of the first ~ATH interpreter. (I am the drocta of drocta ~ATH) Link here: http://www.mspaforums.com/showthread.php?50314-ATH-interpreter This blog is intended to serve as a tutorial on writing things in drocta ~ATH. First I will go over the syntax. Then how to make conditional like things. Then how to make finite loops. Then perhaps storing "numbers". Then copying "numbers" Then comparing "numbers" Then lists In such a way I intend to work our way up to you understanding how to write bubble sort in drocta ~ATH. After that, we might even implement brainf*** in it. Or a universal Turing machine. Of course, when I say "numbers", the quotes are there for a reason. Numbers are not built into drocta ~ATH. One has to build them. Now how do I tag things...? Ah, that's how. In case it wasn't clear, the interpreter for drocta ~ATH does not attempt the impossible. It cannot trigger the apocalypse. It's just a python script that interprets ~ATH scripts. Don't worry if you don't already know how to program. I intend to make the posts fairly accessible.


Tags
12 years ago

Is drocta ~ATH case- and whitespace-sensitive? For instance, would "BIFURCATE 2NULL[JUNK,BLAH];" do the same thing as "bifurcate 2NULL [JUNK, BLAH];"? Also, is there a difference between calling .DIE() on an object and setting it to NULL? Your tutorials seem to be written as if there were a difference. And finally, I'm still unsure about what "BIFURCATE [CMP0,ZEROCHAR]D;" and "D.DIE();" are supposed to do in regards to interpreting the user-inputted character.

drocta ~ATH is case sensitive in most cases, and white space sensitive in some cases. line breaks/new lines are not neccessary for example.

if I said "bifurcate 2NUL[JUNK,BLAH]; that would by a typo on my part. It should be BIFURCATE.

if people want I could make it not case sensitive, but currently it is.

there is a VERY IMPORTANT (if subtle) difference between setting a variable to null and calling .DIE on an object.

in drocta ~ATH, there are variables and objects. Every variable "points to" or "references" an object. The object that a variable points to does not necessarily stay the same. if you have some variable "C", and then you say BIFURCATE SOMETHING[C,JUNK];

instead of pointing to what it was pointing to before, it points to the left half of whatever SOMETHING is pointing to.

This doesn't make the object no longer exist however. It might be that no variables point to it anymore, but it still is stored in memory.

More than one variable can point to a given object.

If variable A and B both initially point to the same object, and then you change A so that it points to a different object, B will still point to the object that they were pointing to at first.

so if A and B both point to some object (which is initially alive), and then A is made to point to the object initially pointed to by NULL (which is initially dead), then A will point to an object that is dead, but B will still point to an object that is alive.

In contrast, if D and F are pointing to the same object, which is initially alive, and one says "D.DIE();", the object that D points to will die (become dead). D and F still point to the same object, but this object is now dead. So both D and F point to a dead object.

about the user input part:

BIFURCATE [CMP0,ZEROCHAR]D;D.DIE();

determines some object, temporarily pointed to by D, which has the object pointed to by CMP0 as its left half, and the object pointed to by ZEROCHAR as its right half. It then kills this object.

the purpose of this, is so that if one has some character object (from the input statement), and wants to know if it is '0', then one can determine the object that has the object pointed to by CMP0 as the left half, and the object that you want to test as the right half. If the object you are testing IS '0', then the object that you get should be the same one that you killed, so it should be dead. If it is not '0' but rather, say, 'z' or just some object that doesn't have a corresponding character, it will result in some other object, which has not been killed, so it is still alive.

I hope I cleared up some of your questions.

3 years ago

Happy 10/25

Today is the 10 year anniversary of the destruction of the universe frog. Such an occasion is traditionally celebrated by destroying the universe.


Tags
10 years ago

Do you know of any ~ATH implementations or dialects besides yours and mine?

Actually, yes kinda. Sorta anyway. There is a compiler of sorts that is intended to be ~ATH based, though I don't think it matched canon all that well.

It did have one feature which I found interesting though. It had a command which would create a variable thing which was truthy iff there was a process currently running with a given name, so you could have in a ~ATH loop something that loops until another program is closed. It was a pretty cool feature, but the syntax for it was odd. The author misinterpreted the panel where Sollux deletes the different virus folders he had, so the command was called rm -rf or something like that.

It also had a command to run an executable (by file name) iirc.(which allowed for easy implementation of the robin hood and friar tuck programs)

It also was an editor of sorts, but it had a small window that I don't think was resizeable. It worked (iirc) by doing some string replacement to turn the program into a c(++?) program, which it then compiled.

I'll try to find it  so I can link it. I don't think it represents ~ATH all that accurately, but the using another program as one of the objects seemed like a neat and probably accurate feature (given the mobius double reacharound)

tl;dr yes

8 years ago

This blog still exists

Hi, I haven’t posted much here in quite some time.

So, is this blog abandoned? I wouldn’t say so. I intend to post more ~ATH content here at some point. I have other projects and obligations, which is why I’ve been not doing as much with it recently (”recently”: understatement of the year), but if anyone has any questions about drocta ~ATH, or would like to request that I do something in particular with it, I think I’ll probably respond within a reasonable amount of time.

Right now though I thought I would link to two blogs that I think you are likely to appreciate if you like this blog.

The first is @sbahjsic http://sbahjsic.tumblr.com/ which is for a programming language and assorted connected software meant to be, well, sbahjsic . like sweet bro and h---- jeff. (Warning though, that blog has some javascript alerts when you view it. Also it has moving parts which might be bad if you get nauseous easily or something? idk.) The blog theme there is a work of art to behold. This is likely to appeal because it is also a homestuck related programming language, and also it is great.

The second is @tilde-he which is where I post most of my non ~ATH related tumblr posts. This is somewhat likely to maybe appeal because it is by the same person as this blog (me).

Again, if you have any questions or comments about my version of ~ATH, or, really, any version that you can point out, feel free to send them, and I’ll try to respond within a reasonable amount of time.

Alright, cheers


Tags
12 years ago

Syntax explanation post completed, and Hello, World.

I have completed the syntax explanation post, and I think it is fairly clear now.

If you find any part of the post to be unclear, and that it requires further explanation,  please say so so that I can improve it.

Now that that post is in an acceptable form, We can get on to writing our first few ~ATH programs.

print Hello, World.; THIS.DIE(); 

That wasn't so hard, was it?

I feel I should note that the syntax of the print command is not entirely finalized, it might change sometime later.

EXPLANATION:

The first line of the program says to output the text "Hello, World." 

The 2nd line of the program says to end the program. This is because the variable THIS initially points to a object that is only alive when the program is running. If the object is ever not alive, the program stops.

oh gosh why is this a bullet-ed list I am not good with tumblr

To run a drocta ~ATH program, you need the interpreter (available from the github), and python 2.7 (the interpreter can be easily modified to run with python 3, but it is written to work in 2.7)

Open interp_2.py with python, and when the program comes up, type in the filename of the ~ATH program, and hit enter, this will run the ~ATH program.

With this example, it should output the text

Hello, World.

Now, of course, this is a relatively simple program, but at least its something.

Depending on how you are running the interpreter, the program might close immediately after outputting the text.

That might not be what we want.

To make the program not close until we specifically tell it to, we use the following:

print Hello, World.; ~ATH(THIS){ } THIS.DIE(); 

EXPLANATION:

The first line is the same as in the first program. It outputs "Hello, World."

The second line is different, this says to start a loop, which will continue until the object pointed to by the variable THIS is dead.

The third line says to go back to the corresponding ~ATH statement.

The fourth line is never executed, because the loop above it will continue until the object pointed to by THIS dies, and if that object dies the program ends. If it were to be executed it would make the object pointed to by THIS die, and the program would end as a result.

This program should be the same, except that it will keep running until you close it manually.

Now you have hello world written in two different ways!


Tags
12 years ago

How often should I post stuff?

I am still here, and I am wondering what my update schedule for this tutorial should be.

Its been a week or two since I last posted part of the tutorial, so I feel like I probably should have posted during that time, but I haven't.

I will probably post one today.

Do you have any suggestions for what type of update schedule I should keep on this tutorial?

12 years ago

ok, made some small commits...

(no features added, but cleaned up some code and added example programs)

yup.

it has the basis for how I am going to make functions if I make them, and cleaned up the code for BIFURCATEion, and removed some lines that were commented out.

if you want the new version it is on the github.

no real difference when it runs though.

(if something you wrote doesn't work with the new version, try using BIFFURCATE instead of BIFURCATE to use the old code. You probably won't need to, though. It works fine for me. and you probably haven't written anything in it anyway, because you kind of have to uh, want to, I guess)


Tags
Loading...
End of content
No more pages to load
  • learn-tilde-ath
    learn-tilde-ath reblogged this · 11 years ago
learn-tilde-ath - Learn ~ATH
Learn ~ATH

News and tutorials on drocta ~ATH by drocta. interpreter here A brief summary of how to write code in the language (but also see the table of contents)

38 posts

Explore Tumblr Blog
Search Through Tumblr Tags