We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › That's it! I'm writing my own language!
Page Index Toggle Pages: 1
That's it! I'm writing my own language! (Read 1390 times)
That's it! I'm writing my own language!
Sep 11th, 2005, 6:54pm
 
This has got to be the stupidest project I've ever undertaken.

I did it because I'm not clever enough to figure out how to do some high level things in Java. I figured out though that if I wrote a language within a language then it would be possible to do what I want.

(And no one would want to use it.)

It's actually very educational trying to build a language from scratch (and very pointless too). The only thing I've really achieved is self-duplicating scripts and self re-writing code. It was interesting learning how to build an online interface. I'm stumped at how I'm supposed to handle algebraic operations. That grinds my project to a halt but I'd still like to polish up my discoveries in "lowest-tier-coding" so the string handling code is there to go back to.

http://www.robotacid.com/PBeta/automat.html

I haven't got my try/catch statement right on the execution applet though:
Code:

String [] manifest;
try{
manifest = loadStrings("manifest,txt");
}
catch(Exception e)
println(e);
text("bad manifest",10,100);
}

How do I get it to display an error message on the applet without crashing the applet? I need to catch that exception but I can't reach it somehow.
Re: That's it! I'm writing my own language!
Reply #1 - Sep 16th, 2005, 9:21am
 
An idea:

Code:


class loadException{
loadException(String file)
{
// is online? need location?
// Look inside Processing source (it will help you)
String location = folder + File.separator + "data";

File archivo = new File(location, file);
if (archivo.exists()) {
manifest = loadStrings(archivo); // reuse for the other files
return;
}
else {
fill(0);
text("bad manifest",20,100);
return;
}
}
}



I hope this help.
One saludo!

Re: That's it! I'm writing my own language!
Reply #2 - Sep 16th, 2005, 3:12pm
 
I use a similar function for loading the text files into the text editor with PHP:
Code:

function loadToString ($filename){
//returns an array read from a file named $filename
if (!is_readable($filename)){
echo $filename." not found<br>";
return "";
}else{
$file = fopen ($filename , "r") or die ("Can't open $filename") ;
$fstring = fread ($file , filesize ($filename)) ;
fclose($file) ;
return $fstring;
}
}

I can use the same method then in Processing. Thanks for pointing this out, it didn't occur to me.
Re: That's it! I'm writing my own language!
Reply #3 - Sep 18th, 2005, 2:02am
 
I take it back. I can't make a Java version of this function at all. It works only from the API. Any reference to System properties crashes any applet I try to make. I've tried every combination of folder and file name to reference. Nothing works. I've looked up and down the Processing source but there is nothing at all that I can find which checks for the existence of a file - the API concentrates on throwing exceptions. It's not designed keep annoying secrets about bugs like Flash does.

The main issue is that code with that class in won't even compile properly.

Which is pretty bloody annoying because there's another post in Syntax trying to sidestep file search exceptions.

Sad
Re: That's it! I'm writing my own language!
Reply #4 - Sep 18th, 2005, 3:29am
 
Sorry, st33d: the class loadException was only a suggestion. I think it can solved with a function.
The real reference: Master FRY.
Source (Processing):
-[Processing video library] Movie.java
-Public constructor Movie(PApplet parent, String filename, int ifps).
I think Fry's method could be used for your example.
Anyway I'll post a possible solution later [.·ºoO].
Re: That's it! I'm writing my own language!
Reply #5 - Sep 18th, 2005, 9:20am
 
I think this works (I'm a snail in java even copying Fry's source):

Code:


//
String[] loadWithoutException(String filename)
{
 URL url = null;
 try {
   url = new URL(filename);
   if (url != null) {
     loaded = true;
     return loadStrings(filename);
   }
 }
 catch (MalformedURLException e) {
 }  // ignored
 url = getClass().getResource(filename);
 if (url != null) {
   loaded = true;
   return loadStrings(filename);
 }

 url = getClass().getResource("data/" + filename);
 if (url != null) {
   loaded = true;
   return loadStrings(filename);
 }        

 try {
   try {
     // look inside the sketch folder (if set)
     String location = this.folder + File.separator + "data";
     File file = new File(location, filename);
     if (file.exists()) {
       loaded = true;
       return loadStrings(file);
     }
   }
   catch (Exception e) {
   }  // ignored

   try {
     File file = new File("data", filename);
     if (file.exists()) {
       loaded = true;      
       return loadStrings(file);
     }
   }
   catch (Exception e) {
   } // ignored

   try {
     File file = new File(filename);
     if (file.exists()) {
       loaded = true;        
       return loadStrings(file);
     }
   }
   catch (Exception e) {
   } // ignored
 }
 catch (SecurityException se) {
 }  // online, whups    
 fill(0);
 text(filename + " bad file",20,100);
 return null;
}



A good variation could be void loadWithoutException(String filename, String[] destiny)... if it runs.
I've posted a boolean variant on craigmod's question.

Re: That's it! I'm writing my own language!
Reply #6 - Sep 18th, 2005, 3:35pm
 
The boolean is better. It's portable. I thought it didn't work at first but it's a matter of relativity and not setting off java's security exceptions.

I've installed it on my crappy language and made an online demo demonstrating that it can reference local files with nothing more than "index.html"

http://www.robotacid.com/PBeta/urlCheck/

Thankee very muchee

Cheesy
Re: That's it! I'm writing my own language!
Reply #7 - Dec 2nd, 2005, 10:17pm
 
fyi.. the loading stuff should no longer be throwing exceptions anymore as of one of the later 009X releases (96?) so that part of the code will no longer be necessary. (details in revisions.txt)
Re: That's it! I'm writing my own language!
Reply #8 - Dec 2nd, 2005, 10:41pm
 
That's magical. I've now no reason to support this horrid, horrid project on my site any more.

Since studying A.I. I've found I could have saved myself so much trouble if I'd modelled my language on Lisp. I imagine it's very easy parsing a language using polish notation in a beginner language writing project. Not to mention the healthy amount of brackets one can use to split() with.
Re: That's it! I'm writing my own language!
Reply #9 - Dec 3rd, 2005, 6:46pm
 
yeah, lisp (or scheme) is a much easier language for which to write a first parser/compiler. you can probably even find toy implementations of it somewhere on the web that would be insightful.

the kind of parsing done for a language (using tools like lex and yacc, learning how bnf grammars work) is one of those second or third semester cs course things that's frustrating to learn but can be helpful.

i recommend looking into it more and then you can help us work out the issues with the preprocessor Wink
Re: That's it! I'm writing my own language!
Reply #10 - Dec 4th, 2005, 12:09am
 
Agh! The memories! LL,LR,LALR(iirc) parsers and all that stuff.

Though I do agree, whilst it's quite a complex subject, once you've learned it, you do get a much greater insight into why languages are the way they are, and the limitations on "free-form" style languages.
Page Index Toggle Pages: 1