SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. grammar sample;
  2.  
  3. assignment  :  IDENT ':=' NUM ';' ;
  4.  
  5. IDENT       :  ('a'..'z')+ ;
  6.  
  7. NUM         :  ('0'..'9')+ ;
  8.  
  9. WS          :  (' '|'n'|'t'|'r')+ {$channel=HIDDEN;} ;
  10.      
  11. x := 99;
  12.      
  13. x := @!$()()%99***;
  14.      
  15. grammar Sample;
  16.  
  17. @members {
  18.   public static void main(String[] args) throws Exception {
  19.     ANTLRStringStream in = new ANTLRStringStream("x := @!$()()%99***;");
  20.     SampleLexer lexer = new SampleLexer(in);
  21.     CommonTokenStream tokens = new CommonTokenStream(lexer);
  22.     SampleParser parser = new SampleParser(tokens);
  23.     parser.assignment();
  24.   }
  25. }
  26.  
  27. assignment  :  IDENT ':=' NUM ';' ;
  28.  
  29. IDENT       :  ('a'..'z')+ ;
  30.  
  31. NUM         :  ('0'..'9')+ ;
  32.  
  33. WS          :  (' '|'n'|'t'|'r')+ {$channel=HIDDEN;} ;
  34.      
  35. // generate parser/lexer
  36. java -cp antlr-3.2.jar org.antlr.Tool Sample.g
  37.  
  38. // compile
  39. javac -cp antlr-3.2.jar *.java
  40.  
  41. // run Windows
  42. java -cp .;antlr-3.2.jar SampleParser
  43. // or run *nix/MacOS
  44. java -cp .:antlr-3.2.jar SampleParser
  45.      
  46. line 1:5 no viable alternative at character '@'
  47. line 1:6 no viable alternative at character '!'
  48. line 1:7 no viable alternative at character '$'
  49. line 1:8 no viable alternative at character '('
  50. line 1:9 no viable alternative at character ')'
  51. line 1:10 no viable alternative at character '('
  52. line 1:11 no viable alternative at character ')'
  53. line 1:12 no viable alternative at character '%'
  54. line 1:15 no viable alternative at character '*'
  55. line 1:16 no viable alternative at character '*'
  56. line 1:17 no viable alternative at character '*'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top