Computer Science Canada Java Token Parser |
Author: | pyrnight [ Sun Mar 02, 2008 10:09 am ] | ||
Post subject: | Java Token Parser | ||
Well its like 3 weeks or so, maybe 4, into class, and I've written this for computer science class. I'm in grade 11. Enjoy ![]() PS: Its probably not perfect but its all I need for my PIC compiler project this semester ![]()
|
Author: | HeavenAgain [ Sun Mar 02, 2008 10:15 am ] |
Post subject: | RE:Java Token Parser |
so what does this do? oh and, you do know there is a StringTokenizer class right? and by the looks of it regular expression would definitely help you out |
Author: | pyrnight [ Sun Mar 02, 2008 10:28 am ] |
Post subject: | RE:Java Token Parser |
I know there is a StringTokenizer class, this was for a cs class though, that would kind of defeat the purpose of learning to code, using a premade class woudln't it? What this does it seperate it into tokens on each new line // The "TokenParse" class. import java.io.* ; public class TokenParse { public static final String filename = "YOURJAVAFILE.java" ; public static boolean isAlpha ( char check ) { // Ascii values... I should have cheated an used >= 'A'... // but I realized that after I coded this if ( ( ( int ) check >= 65 && ( int ) check <= 90 ) || ( ( int ) check >= 97 && ( int ) check <= 122 ) ) |
Author: | OneOffDriveByPoster [ Sun Mar 02, 2008 10:39 am ] |
Post subject: | Re: RE:Java Token Parser |
pyrnight @ Sun Mar 02, 2008 10:28 am wrote: java.io.* Probably not one token. The parser may be more helpful if you could print the token types detected. |
Author: | pyrnight [ Sun Mar 02, 2008 4:29 pm ] |
Post subject: | RE:Java Token Parser |
We're just making a compiler for a simple pic, so thigns like java.io.* or token types don't matter to much right now. and java.io.* is one token I think. Prove me wrong. |
Author: | OneOffDriveByPoster [ Sun Mar 02, 2008 6:29 pm ] | ||
Post subject: | Re: RE:Java Token Parser | ||
pyrnight @ Sun Mar 02, 2008 4:29 pm wrote: We're just making a compiler for a simple pic, so thigns like java.io.* or token types don't matter to much right now. and java.io.* is one token I think. Prove me wrong.
JLS 3.0 subsection 18.1:
You are making a Java compiler? |
Author: | pyrnight [ Mon Mar 03, 2008 9:54 pm ] |
Post subject: | RE:Java Token Parser |
No. As I said before, we're making a compiler for a pic, that program was just to test the tokenization. And ok, you got me on the import thing, but its not relevant to what I need to do, so I'm not going to fix it, but thanks for the heads up. |