I am not a good programmer in java but can anyone of you provide some examples regarding lexical analysis in java and syntactical analysis in java
I am not a good programmer in java but can anyone of you provide some examples regarding lexical analysis in java and syntactical analysis in java
Code:Color getColor(String name) { String data; StringTokenizer st; int red, green, blue; data = getParameter(name); if (data == null) return null; st = new StringTokenizer(data, ","); try { red = Integer.parseInt(st.nextToken()); green = Integer.parseInt(st.nextToken()); blue = Integer.parseInt(st.nextToken()); } catch (Exception e) { return null; // (ERROR STATE) could not parse it } return new Color(red, green, blue); // (END STATE) done. }
Code:while (true) { Expression res; int c = StreamTokenizer.TT_EOL; String varName = null; System.out.println("Enter an expression..."); try { while (true) { c = st.nextToken(); if (c == StreamTokenizer.TT_EOF) { System.exit(1); } else if (c == StreamTokenizer.TT_EOL) { continue; } else if (c == StreamTokenizer.TT_WORD) { if (st.sval.compareTo("dump") == 0) { dumpVariables(variables); continue; } else if (st.sval.compareTo("clear") == 0) { variables = new Hashtable(); continue; } else if (st.sval.compareTo("quit") == 0) { System.exit(0); } else if (st.sval.compareTo("exit") == 0) { System.exit(0); } else if (st.sval.compareTo("help") == 0) { help(); continue; } varName = st.sval; c = st.nextToken(); } break; } if (c != '=') { throw new SyntaxError("missing initial '=' sign."); }
Bookmarks