Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. lexer grammar slfLexer;
  2.  
  3. // operators
  4. BECOMES: '=';
  5. PLUS: '+';
  6. MINUS: '-';
  7. TIMES: '*';
  8. DIVIDE: '/';
  9. MODULO: '%';
  10.  
  11. EQUALS: '==';
  12. LT: '<';
  13. LTE: '<=';
  14. GT: '>';
  15. GTE: '>=';
  16. UNEQUALS: '!=';
  17. AND: '&&';
  18. OR: '||';
  19. NOT: '!';
  20.  
  21. //keywords
  22. CONSTANT: 'constant';
  23. PRINT: 'print';
  24. READ: 'read';
  25. IF: 'if';
  26. THEN: 'then';
  27. ELSE: 'else';
  28. WHILE: 'while';
  29. INT: 'int';
  30. CHAR: 'char';
  31. BOOLEAN: 'boolean';
  32. STRING: 'string';
  33. RETURN: 'return';
  34.  
  35. //interpunction
  36. COLON: ':';
  37. SEMICOLON: ';';
  38. OPAREN: '(';
  39. CPAREN: ')';
  40. OCURLY: '{';
  41. CCURLY: '}';
  42. COMMA: ',';
  43.  
  44. // values
  45. LITERALBOOLEAN: 'true' | 'false';
  46. LITERALSTRING: '"' ('\\"' | '\\\\' | ~('\n'|'\r') )*? '"'; // "string" escapes \" and \\
  47. LITERALCHARACTER: '\'' ( '\\\'' | ~('\n'|'\r') )*? '\''; // 'c' escapes '\''
  48. LITERALNUMBER: DIGIT+;
  49.  
  50. IDENTIFIER: LETTER (LETTER | DIGIT)*;
  51.  
  52. COMMENT: '//' ~[\r\n]* -> skip;
  53.  
  54. WS: [ \t\r\n]+ -> skip;
  55.  
  56. fragment DIGIT: ('0'..'9');
  57. fragment LETTER:('a'..'z' | 'A'..'Z');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement