Java Compiler Complier

  • lifeissomething1234
  • Born
  • Born
  • lifeissomething1234
  • Posts: 1

Post 3+ Months Ago

I have a question, here is my codes for java Complier Compiler to compile and test everything seems working perfectly, but the real issue is that, after I run this on unix shell, when I type 8/2 it should print like this: <RATIONAL> (`8/2') value = 4.0.

Does anyone have a clue? Please


TOKEN :

{
< MYID: ("abdr827") >
}


TOKEN:

{
< MYID2: ("abdr"|"827")+ >
}


TOKEN:

{
< MYID3: (("abdr" ((("8")+ ("2") ("7")) | (("8") ("2")+ ("7")) | (("8") ("2") ("7"))+))) >
}



TOKEN : /* Integers literals */
{
< INTEGER_LITERAL:("+" | "-")? (["0"-"9"] (<DIGIT>)*) >
}

TOKEN:

{
<RATIONAL: (["0"-"9"]) + | (["0"-"9"])+ "." (["0"-"9"])+ | (["0"-"9"])+ "." | "." (["0"-"9"])+ | (["0"-"9"])+ "/" (["0"-"9"])+ >
}




TOKEN : /* Identifiers. */
{
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
}

TOKEN :
{
< HORROR: (~[ " ", "\t", "\n", "\r", "\f"])+ >
}


TOKEN : /* Definitions for use in other lexical definitions
(signified by the `#'). */
{
< #LETTER: [ "a"-"z", "A"-"Z" ] >
|
< #DIGIT: [ "0"-"9"] >
}



/*
* A simple grammar to match tokens and print them.
*/

void TokenList() :
{Token t; int val;}
{
( { val = 0;}
( t = <INTEGER_LITERAL> | t=<MYID> |t=<MYID2> | t=<MYID3> | t = <IDENTIFIER> | t = <RATIONAL> | t=<HORROR> )
// Code executed after any match to tokens above
{ System.out.print(tokenImage[t.kind]+" (`"+t.image+"') ");
switch(t.kind) {
case INTEGER_LITERAL:
//my code start here

/*
if ((t.image).substring(0) == "+"){
val = cw1.parseLiteral(((t.image).substring(1)),10);
System.out.println(" value = "+val);
} else {
val = cw1.parseLiteral(t.image,10);
System.out.println(" value = "+val);
}
*/




/* do whatever you want */


String input = t.image;
String search = "+";
String sub = "";
String result = " value = " +val;
int i;
do { // replace all matching substrings

i = input.indexOf(search);
if(i != -1) {
result = input.substring(0, i);
result = result + sub;
result = result + input.substring(i + search.length());
input = result;
}
} while(i != -1);
System.out.println("value = " +input);
break;


default:
System.out.println(" "); // new line
}


}
)* <EOF>
}
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.