Click here to Skip to main content
15,900,511 members
Home / Discussions / Java
   

Java

 
GeneralRe: java servlet - error HTTP 500 - java.lang.nullpointer exception [modified] Pin
golisarmi11-Nov-09 2:43
golisarmi11-Nov-09 2:43 
GeneralRe: java servlet - error HTTP 500 - java.lang.nullpointer exception Pin
sparlay_pk16-Nov-09 7:49
sparlay_pk16-Nov-09 7:49 
QuestionSaving Forms to an XML file or .txt file Pin
Clement Tientcheu10-Nov-09 18:20
Clement Tientcheu10-Nov-09 18:20 
AnswerRe: Saving Forms to an XML file or .txt file Pin
sparlay_pk16-Nov-09 7:56
sparlay_pk16-Nov-09 7:56 
Questiondeploying java database application Pin
Muhammad Adeel Zahid9-Nov-09 8:08
Muhammad Adeel Zahid9-Nov-09 8:08 
QuestionHow to Validate XML against XSD v1.1 Pin
Skippums9-Nov-09 7:08
Skippums9-Nov-09 7:08 
QuestionTable locked and session was invalidated Pin
tarek.mostafa8-Nov-09 23:11
tarek.mostafa8-Nov-09 23:11 
QuestionNeed help with building a compiler that takes regular expressions in Java Pin
Jesus877-Nov-09 20:44
Jesus877-Nov-09 20:44 
Errors im getting:
cannot find symbol constructor method Token. but i do have a constructor in Token class

cannot find symbol variable tokenCode. i clearly use it alll over and i think i initialized it properly so whats wrong?

cannot find symbol variable scantest.i have that in same folder where all classes are in why wont it read it?





scanner class in which i need help fixing the above errors
import java.io.BufferedReader; 
    import java.io.FileReader;
    import java.io.*;
    
    public class scanner implements CompilerConstants {
     private char c;
      private BufferedReader source; 
      public int token;
        
      private String attr = "";
      //private int val = '0'; 
      private
        
        public scanner(BufferedReader buffer) {
         source = buffer;
         
         getChar();
        } //constructor of scanner
        
        
        public void getChar()
        {
         c = (char)(source.read());
         //do a read in
        }
        
        
        //lookup for finding identifiers
        public boolean lookup(String word)
        {
         boolean check = false;
         for(int i=0; i < RESERVEDWORD.length;i++)
          if(word==(RESERVEDWORD[i]))
          {
           check = true;
          }
         return check;
        }
        
        
        //public boolean T(int tcc, String attt) //to return token
        //{
        // tokenCode = tcc;
        // attribute = attt;
        // return T;
       // }
        
        
         public Token nextToken() throws IOException
        {
        
        attr = "";
        
        //need to save to do lookup see if its identifier or not
        while(c!=EOFCHAR);  //if not end of file then do  
        { 
         while (Character.isWhitespace(c))//remove white space, check whether is letter or digit
         {
       getChar();
         }
         if (Character.isLetter(c))
         {
       while(Character.isLetterOrDigit(c))
       { 
        attr = attr + c;
        getChar();
       }
       
       return new Token(lookup(attr), attr); //
         }
        else if (Character.isDigit(c)) {
       while(Character.isDigit(c))
       {
        attr = attr + c;
        getChar();
       }
       return new Token(NUMBER, attr);
        } 
        else {
     switch (c) {
        
      case '<' : getChar();
       if(c=='>')
       {
        getChar();
        return new Token(NE, null);
       } 
       else if (c=='=')
       {
        getChar();
        return new Token(LE, null);
       }
       return new Token(LT, null);
       
        
      case '>' : getChar();
       if(c=='<')
       {
        getChar();
        return new Token(NE, null);
       } 
       else if (c=='=')
       {
        getChar();
        return new Token(GE, null);
       }
       return new Token(GT, null);
     
      
      case '=' : getChar();
      return new Token(EQ, null);
      
      case '|' : getChar();
      return new Token(OR, null);
      
      case '+' : getChar();
      return new Token(PLUS, null);
      
      case '-' : getChar();
      return new Token(MINUS, null);
      
      case '*' : getChar();
      return new Token(TIMES, null);
      
      case '/' : getChar();
      return new Token(DIVIDE, null);
      
      case '[' : getChar();
      return new Token(LEFTSQ, null);
      
      case ']' : getChar();
      return new Token(RIGHTSQ, null);
      
      case '(' : getChar();
      return new Token(LEFTPAREN, null);
      
      case ')' : getChar();
      return new Token(RIGHTPAREN, null);
      
      case ',' : getChar();
      return new Token(COMMA, null);
      
      case EOFCHAR : getChar();
      return new Token(EOF, null);
    
     }
     } // switch
     
      //return EOF.Token;
      return Token(tokenCode, attr);  //tokenAttribute
       
        } // if
       // return Token;
    } // getToken
    
    
    public static void main(String[] args)
    {
     BufferedReader source = new BufferedReader(new FileReader(scantest.echo));
    }
    }





Token class

public class Token implements CompilerConstants {
      private int tokenCode;
      private String attribute;

       public Token(int tc, String att) //constructor
       {
           tokenCode = tc;
           attribute = att;

       }

       public int getToken()//return tokencode
       {
           return tokenCode;
       }
       //return token attribute

       public String tokenAttribute()
       {
           return attribute;
       }

       public String toString(){

       String tokenString = tokenCode + "  ";

       switch (tokenCode) {  //// relational expressions for metasymbols
           case AND: return (tokenString + "/n AND");
           case IDENTIFIER: return (tokenString + "/n IDENTIFIER" + attribute);
           case OR: return (tokenString + "/n OR");
           case NOT: return (tokenString + "/n NOT");
           case ARRAY: return (tokenString + "/n ARRAY");
           case BEGIN: return (tokenString + "/n BEGIN ");
           case  BOOLEAN: return (tokenString + "/n BOOLEAN ");
           case  DO: return (tokenString + "/n DO ");
           case  ELSE: return (tokenString + "/n ELSE");
           case  END: return (tokenString + "/n END");
           case  FOR: return (tokenString + "/n FOR");
           case  FROM: return (tokenString + "/n FROM");
           case  IF: return (tokenString + "/n IF");
           case  INTEGER: return (tokenString + "/n INTEGER");
           case  PROCEDURE: return (tokenString + "/n PROCEDURE");
           case  PROGRAM: return (tokenString + "/n PROGAM");
           case  READ: return (tokenString + "/n READ");
           case  START: return (tokenString + "/n START");
           case  THEN: return (tokenString + "/n THEN");
           case  TO: return (tokenString + "/n TO");
           case  TRUE: return (tokenString + "/n TRUE");
           case  WHILE: return (tokenString + "/n WHILE");
           case  WRITE: return (tokenString + "/n WRITE");
           case  WRITELN: return (tokenString + "/n WRITELN");
           case  NUMBER: return (tokenString + "/n NUMBER" + attribute);
           case  STRING: return (tokenString + "/n STRING" + attribute);
           case  LT: return (tokenString + "/n LT");
           case  LE: return (tokenString + "/n LE");
           case  GT: return (tokenString + "/n GT");
           case  GE: return (tokenString + "/n GE");
           case  EQ: return (tokenString + "/n EQ");
           case  NE: return (tokenString + "/n NE");
           case  PLUS: return (tokenString + "/n PLUS");
           case  MINUS: return (tokenString + "/n MINUS");
           case  TIMES: return (tokenString + "/n TIMES");
           case  DIVIDE: return (tokenString + "/n DIVIDE");
           case  LEFTSQ: return (tokenString + "/n LEFTSQ");
           case  RIGHTSQ: return (tokenString + "/n RIGHTSQ");
           case  LEFTPAREN: return (tokenString + "/n LEFTPAREN");
           case  COLONEQUAL: return (tokenString + "/n COLONEQUAL");
           case  COMMA: return (tokenString + "/n COMMA");
           case  EOF: return (tokenString + "/n  EOF");


       }
     return tokenString;
      }
   }





CompilerConstants class

public interface CompilerConstants {
       public static final int AND = 1;
       public static final int ARRAY = 2;
       public static final int BEGIN = 3;
       public static final int BOOLEAN = 4;
       public static final int DO = 5;
       public static final int ELSE = 6;
       public static final int END = 7;
       public static final int FALSE = 8;
       public static final int FOR = 9;
       public static final int FROM = 10;
       public static final int IF = 11;
       public static final int INTEGER = 12;
       public static final int NOT = 13;
       public static final int OR = 14;
       public static final int PROCEDURE = 15;
       public static final int PROGRAM = 16;
       public static final int READ = 17;
       public static final int START = 18;
       public static final int THEN = 19;
       public static final int TO = 20;
       public static final int TRUE = 21;
       public static final int WHILE = 22;
       public static final int WRITE = 23;
       public static final int WRITELN = 24;
       public static final int IDENTIFIER = 30;
       public static final int NUMBER = 31;
       public static final int STRING = 32;
       public static final int LT = 33;
       public static final int LE = 34;
       public static final int GT = 35;
       public static final int GE = 36;
       public static final int EQ = 37;
       public static final int NE = 38;
       public static final int PLUS = 39;
       public static final int MINUS = 40;
       public static final int TIMES = 41;
       public static final int DIVIDE = 42;
       public static final int LEFTSQ = 43;
       public static final int RIGHTSQ = 44;
       public static final int LEFTPAREN = 45;
       public static final int RIGHTPAREN = 46;
       public static final int COLONEQUAL = 47;
       public static final int COMMA = 48;
       public static final int EOF = 99;
       
       public static final char EOFCHAR = (char)(-1);
       
       public static final String[] RESERVEDWORD = {"","and","array","begin","boolean",
                     "do","else","end","false","for","from","if","integer","not","or",
                     "procedure","program","read","start","then","to","true","while",
                     "write","writeln"};
                     
       public static final boolean DEBUG = true;
       
    } // interface CompilerConstants

AnswerRe: Need help with building a compiler that takes regular expressions in Java Pin
Nagy Vilmos8-Nov-09 22:16
professionalNagy Vilmos8-Nov-09 22:16 
GeneralRe: Need help with building a compiler that takes regular expressions in Java [modified] Pin
Jesus8710-Nov-09 9:29
Jesus8710-Nov-09 9:29 
QuestionPokerHand class can someone help me solve this code? Pin
sweetbab7-Nov-09 19:55
sweetbab7-Nov-09 19:55 
AnswerRe: PokerHand class can someone help me solve this code? [modified] Pin
Richard MacCutchan7-Nov-09 21:52
mveRichard MacCutchan7-Nov-09 21:52 
Questionsending sms thro Java application Pin
pearlpristine6-Nov-09 1:33
pearlpristine6-Nov-09 1:33 
AnswerRe: sending sms thro Java application Pin
42774806-Nov-09 6:35
42774806-Nov-09 6:35 
QuestionAirline Reservation Pin
Shah Ravi5-Nov-09 20:20
Shah Ravi5-Nov-09 20:20 
AnswerRe: Airline Reservation Pin
portmansdress5-Nov-09 20:43
portmansdress5-Nov-09 20:43 
GeneralRe: Airline Reservation Pin
Richard MacCutchan5-Nov-09 23:11
mveRichard MacCutchan5-Nov-09 23:11 
AnswerRe: Airline Reservation Pin
Richard MacCutchan5-Nov-09 23:10
mveRichard MacCutchan5-Nov-09 23:10 
AnswerRe: Airline Reservation Pin
42774805-Nov-09 23:52
42774805-Nov-09 23:52 
Questiontools.jar Pin
Stephen Lintott3-Nov-09 19:19
Stephen Lintott3-Nov-09 19:19 
AnswerRe: tools.jar Pin
Nagy Vilmos3-Nov-09 22:26
professionalNagy Vilmos3-Nov-09 22:26 
GeneralRe: tools.jar Pin
Stephen Lintott3-Nov-09 22:56
Stephen Lintott3-Nov-09 22:56 
QuestionTroubles in launching a java application at MS windows system startup (user login) [modified] Pin
Fire-Dragon-DoL2-Nov-09 15:12
Fire-Dragon-DoL2-Nov-09 15:12 
AnswerRe: Troubles in launching a java application at MS windows system startup (user login) Pin
Nagy Vilmos2-Nov-09 22:08
professionalNagy Vilmos2-Nov-09 22:08 
AnswerRe: Troubles in launching a java application at MS windows system startup (user login) Pin
42774802-Nov-09 22:44
42774802-Nov-09 22:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.