All pastes #2077336 Raw Edit

Anonymous

public text v1 · immutable
#2077336 ·published 2011-06-09 17:18 UTC
rendered paste body
grammar XL;

options {
  language = Java;
}

@header {
  package com.eco360.server.parser;
}

@lexer::header {
  package com.eco360.server.parser;
}

program
  : 'program' IDENT '='
    ( constant | variable )*
    'begin'
    statement*
    'end' IDENT '.'
  ;
 
constant
  : 'constant' IDENT ':' type ':=' expression ';'
  ;
  
variable
  : 'var' IDENT (',' IDENT)* ':' type (':=' expression )? ';'
  ;
  
type
  : 'Integer'
  ;
  
statement
  :  assignmentStatement
  |  ifStatement
  ; 
  
ifStatement
  : 'if' expression 'then' statement+ 
    ('elsif' expression 'then' statement+)*
    ('else' statement+)?
    'end' 'if' ';'
  ;
  
assignmentStatement
  :   IDENT ':=' expression ';'
  ;
 
 // lol time
 
term
  :   IDENT
  |  '(' expression ')'
  |  INTEGER
  ; 
  
negation
  :  'not'* term
  ;

unary
  : ('+' | '-' )* negation
  ;
  
mult 
  : unary (('*' | '/' | 'mod') unary)*
  ;
  
add
  : mult (('+' | '-') mult)*
  ;
  
relation
  : add (('=' | '/=' | '<' | '<=' | '>=' | '>') add)*
  ;
  
expression
  : relation (('and' | 'or') relation)*
  ;
  
INTEGER: '0'..'9'+;
IDENT: ('a'..'z' | 'A'..'Z' )('a'..'z' | 'A'..'Z' | '0'..'9')*;
WS: (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;};