Grammar

    This is the EBNF Xion grammar. This grammar has been implemented thanks to ANTLR 2.7.0. Characters are between ' and key words between ". A ? represents an option, a * a repetition, a + a repetition with at least one occurrence, a | separates possibilities, a ~ is the anti-rule and .. give the ASCII interval between two characters. Whitespaces, carriage returns, line feed, file feed, tabulations are ignored, as the comment rule.

program::=    (initializer)?    (statement)*

initializer::=    "super"    '('    ( exprList )?    ')'

compoundStatement::=    '{'    ( statement )*    '}'

statement::=
         compoundStatement
    |    expression ';'
    |    declaration    ';'
    |    "if"    '('    expression    ')'    statement    ( "else"    statement )?
    |    "for"    '('    forInit    ';'    forCond    ','    forIter    ';'    ')'    statement
    |    "while"    '('    expression    ')'    statement
    |    "do"    statement    "while"    '('    expression    ')'    ';'
    |    "return"    (expression)?    ';'
    |    "write"    (expression)?    ';'
    |    "writeRaw"    (expression)?    ';'
    |    ';'

forInit::=    ( declaration    |    expressionList )?

forCond::=    ( expression )?

forIter::=    ( expressionList )?

declaration::=     type   variableDefinitions

variableDefinitions::=    variableDeclarator    ( ','    variableDeclarator )*

variableDeclarator::=    IDENT varInitializer

varInitializer::=    ( '='    expression )?

type::=
         identifier
    |    builtInType
    |    collectionType.


builtInType::=
         "Void"
    |    "Boolean"
    |    "Integer"
    |    "Real"
    |    "String"
    |    "Date"
    |    "Time"
    |    "OclAny"
    |    "OclType"
    |    "Double"
    |    "Float"
    |    "Long"
    |    "Int"
    |    "Short"
    |    "Byte"

collectionType::=    collectionKind    '('    type    ')'

collectionKind::=
         "Collection"
    |    "Set"
    |    "Bag"
    |    "Sequence"

identifier::=    IDENT    ( "::"    IDENT )*

expression::=    assignmentExpression

expressionList::=    expression    ( ','    expression )*

assignmentExpression::=
        conditionalExpression
        (
            ( '=' | "+=" | "-=" | "*=" | "%=" | ">>=" | "<<=" | "&=" | "^=" | "|=" )
            assignmentExpression
        )?

conditionalExpression::=    logicalOrExpression    ( '?'    assignmentExpression    ':'    conditionalExpression )?

logicalOrExpression::=    logicalAndExpression    ( "||"    logicalAndExpression )*

logicalAndExpression::=    inclusiveOrExpression    ( "&&"    inclusiveOrExpression )*

inclusiveOrExpression::=    exclusiveOrExpression    ( '|'    exclusiveOrExpression )*

exclusiveOrExpression::=    andExpression    ( '^'    andExpression )*

andExpression::=    equalityExpression    ( '&'    equalityExpression )*

equalityExpression::=    relationalExpression    ( ( '=' | "!=" )    relationalExpression )*

relationalExpression::=    shiftExpression    (
             ( ( '<' | '>' | "<=" | ">=" )    shiftExpression )*
        |    "instanceof"    type
        )

shiftExpression::=    additiveExpression    ( ( "<<" | ">>" )    additiveExpression )*

additiveExpression::=    multiplicativeExpression    ( ( '+' | '-' )    multiplicativeExpression )*

multiplicativeExpression::=    unaryExpression    ( ( '*' | '/' | '%' ) unaryExpression )*

unaryExpression:
         "++"    unaryExpression
    |    "--"    unaryExpression
    |    '-'    unaryExpression
    |    '+'    unaryExpression
    |    unaryExpressionNotPlusMinus

unaryExpressionNotPlusMinus::=
         '~'    unaryExpression
    |    '!'    unaryExpression
    |    '('    type    ')'    unaryExpression
    |    postfixExpression

postfixExpression::=    primaryExpression    ( ( '.' | "->" )    featureCall )*    ( ( "++" | "--" ) )?

featureCall::=
         ( identifier    ( '('    ( expressionList )?    ')'    |    ( '['    IDENT    ']' )?    '['    expressionList    ']' )?)
    |    ( ( '=' | "==" | '!' | '~' | "!=" | "<>" | '/' | '+' | '-' | '*' | '%' | ">>" | '>' | ">=" | "<<" | "<=" | '<' | '^' | '|' | '||' | "&&" | '&') ( '('    expressionList    ')' )? )

primaryExpression::=
         newExpression
    |    constant
    |    "true"
    |    "false"
    |    "this"
    |    "self"
    |    "null"
    |    '('    assignmentExpression    ')'
    |    builtInType
    |    collectionType
    |    featureCall

newExpression::=    "new"    type    '('    ( expressionList )?    ')'

constant::=
         NUM_INT
    |    STRING_LITERAL
    |    NUM_FLOAT
    |    '#' IDENT
    |    litteralCollection

litteralCollection::=    collectionKind    '{'    ( expressionListOrRange )?    '}'

expressionListOrRange::=    expression    ( ( ',' expression )+    |    ".."    expression )?

DIGIT::=    '0' .. '9'

ALPHA::=    'a' .. 'z' | 'A' .. 'Z' | '_' | '$' | '\u00C0' .. '\u00D6' | \u00D8' .. '\u00F6' | '\u00F8' .. '\u00FF'

IDENT::=    ALPHA ( ALPHA | DIGIT )*

NUM_INT::=    (DIGIT)+

NUM_FLOAT::=    (DIGIT)+    ( '.'    ( DIGIT )+    (EXPONENT)?    |    EXPONENT )

EXPONENT::=    ( 'e' | 'E' )    ( '+' | '-' )?    ( '0' .. '9' )+

ESC::=    '\'    ( 'n' | 'r' | 't' | 'b' | 'f' | '"' | ''' | '\' | ( '0' .. '3' ) ( ( '0' .. '7' ) ( ( '0' .. '7' ) )? )? | ( '4' .. '7' ) ( ('0'..'7') )?

STRING_LITERAL::=    '''    ( ESC    | ~( '\' | ''' ) )*    '''    |    '"'    ( ESC    | ~( '\' | '" ') )*    '"'

 

Sommaire