fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7.  
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. StreamTokenizer in = getTokenizer();
  11.  
  12. do {
  13. in.nextToken();
  14.  
  15. switch (in.ttype) {
  16. case StreamTokenizer.TT_WORD:
  17. System.out.println("WORD: " + in.sval);
  18. break;
  19. case StreamTokenizer.TT_NUMBER:
  20. System.out.println("NUMBER: " + in.nval);
  21. break;
  22. case '"':
  23. System.out.println("QUOTE: " + in.sval);
  24. break;
  25. case '(':
  26. case ')':
  27. case '\'':
  28. case '.':
  29. case '`':
  30. case ',':
  31. case '@':
  32. System.out.println((char)in.ttype);
  33. break;
  34. case StreamTokenizer.TT_EOF:
  35. break;
  36. default:
  37. System.out.print("UNKNOWN: ");
  38. System.out.println((char)in.ttype);
  39. break;
  40. }
  41.  
  42. } while (in.ttype != StreamTokenizer.TT_EOF);
  43.  
  44. }
  45.  
  46. static StreamTokenizer getTokenizer() throws java.lang.Exception
  47. {
  48.  
  49. in.resetSyntax();
  50. in.wordChars(0, 0xFFFF);
  51. in.quoteChar('"');
  52. in.parseNumbers();
  53. in.lowerCaseMode(true);
  54. in.whitespaceChars(' ', ' ');
  55. in.whitespaceChars('\t', '\t');
  56. in.whitespaceChars('\r', '\r');
  57. in.whitespaceChars('\n', '\n');
  58. in.commentChar(';');
  59. in.ordinaryChar('\'');
  60. in.ordinaryChar('(');
  61. in.ordinaryChar(')');
  62. in.ordinaryChar('`');
  63. in.ordinaryChar(',');
  64. in.ordinaryChar('.');
  65. in.ordinaryChar('@');
  66.  
  67. return in;
  68. }
  69. }
Success #stdin #stdout 0.08s 380160KB
stdin
(defun abc (x y) (cons (car x) (cdr y)))
(+ 123 45 (* 3 4))
(define kkk "test lang あいうえお 諸行無常 弱肉強食 ソn desu") ; test language
(define fff '(abc efg))
(a . b)
(defmacro foo (x) `(cons ,x ,x))
(defmacro foo (x) `(progn ,@x))
stdout
(
WORD: defun
WORD: abc
(
WORD: x
WORD: y
)
(
WORD: cons
(
WORD: car
WORD: x
)
(
WORD: cdr
WORD: y
)
)
)
(
WORD: +
NUMBER: 123.0
NUMBER: 45.0
(
WORD: *
NUMBER: 3.0
NUMBER: 4.0
)
)
(
WORD: define
WORD: kkk
QUOTE: test lang あいうえお 諸行無常 弱肉強食 ソn desu
)
(
WORD: define
WORD: fff
'
(
WORD: abc
WORD: efg
)
)
(
WORD: a
.
WORD: b
)
(
WORD: defmacro
WORD: foo
(
WORD: x
)
`
(
WORD: cons
,
WORD: x
,
WORD: x
)
)
(
WORD: defmacro
WORD: foo
(
WORD: x
)
`
(
WORD: progn
,
@
WORD: x
)
)