Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BNF 1.62 KB | None | 0 0
  1. grammar fql;
  2.  
  3. options {
  4.     backtrack = false;
  5. }
  6.  
  7. tokens {
  8.     IMPORT = 'IMPORT';
  9.     DEF = 'DEF';
  10.     SELECT = 'SELECT';
  11.     AND = 'AND';
  12.     OR = 'OR';
  13.     NOT = 'NOT';
  14.     IF = 'IF';
  15.     THEN = 'THEN';
  16.     ELSE = 'ELSE';
  17.     CASE = 'CASE';
  18.     MATCH = 'MATCH';
  19.     SWITCH = 'SWITCH';
  20.     AS = 'AS';
  21.     FROM = 'FROM';
  22.     IN = 'IN';
  23.     EXIT = 'EXIT';
  24.     MODULE = 'MODULE';
  25.     PUBLIC = 'PUBLIC';
  26.     TRY = 'TRY';
  27.     CATCH = 'CATCH';
  28.     FILTER = 'FILTER';
  29.  
  30.     // Operators
  31.    
  32.     ASSIGN_OP           = ':=';
  33.     EQUAL_OP            = '=';
  34.     GREATER_OP          = '>';
  35.     GREATER_OR_EQUAL_OP = '>=';
  36.     LESS_OP             = '<';
  37.     LESS_OR_EQUAL_OP    = '<=';
  38.     PLUS_OP             = '+';
  39.     INCREMENT_OP        = '++';
  40.     MINUS_OP            = '-';
  41.     DECREMENT_OP        = '--';
  42.     MULTIPLY_OP         = '*';
  43.     DIVIDE_OP           = '/';
  44. }
  45.  
  46.  
  47. compilation_unit
  48.     :   module_def
  49.     |   function_def+ ;
  50.    
  51. module_def
  52.     :   MODULE ident '(' function_def+ ')' ;
  53.  
  54. function_def
  55.     :   PUBLIC DEF ident '=' function_decl ';'
  56.     |   DEF ident '=' function_decl ';' ;
  57. function_decl
  58.     : select_statement
  59.     | filter_statement ;
  60.  
  61. select_statement
  62.     :   SELECT field_list FROM source ;
  63.  
  64. filter_statement
  65.     :   FILTER ident '(' filter_list ')';
  66.  
  67. field_list
  68.     :   ident ( ',' ident )* ;
  69.  
  70. filter_list
  71.     :   'FILTERLIST' ;
  72.  
  73. source  : ident ;
  74.  
  75. // ---------------------------------------------------------------------------
  76. // L E X E R   G R A M M A R
  77. // ---------------------------------------------------------------------------
  78.  
  79.  
  80. WHITESPACE : ( ' ' | '\t' | '\r' | '\n' )+ { $channel = HIDDEN; };
  81.  
  82. ident   : LETTER ( LETTER | DIGIT )* ;
  83. fragment LETTER : 'A'..'Z' | 'a'..'z' ;
  84. fragment DIGIT : '0'..'9';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement