Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar grammaire;
- options {
- language = C;
- output = AST;
- }
- tokens {
- PLUS = '+' ;
- MOINS = '-' ;
- FOIS = '*' ;
- DIVI = '/' ;
- PUISS = '^' ;
- GPAREN = '(' ;
- DPAREN = ')';
- OPEN_BLCK = '{';
- CLOS_BLCK = '}';
- SUP = '>' ;
- INF = '<' ;
- SUPEQ = '>=' ;
- INFEQ = '<=' ;
- AFFECT = '=' ;
- EGAL = '==' ;
- NEGAL = '/=' ;
- DEF = '::';
- // div - mod - null - ... ?
- ARGSEPAR = ',' ;
- TO = '->';
- SYNOTYPE = 'type';
- PRINT = 'print';
- ERROR = 'error';
- LET = 'let';
- IN = 'in';
- IF = 'if';
- THEN = 'then';
- ELSE = 'else';
- OTHERWISE = 'otherwise';
- TELQUE = '|';
- MAIN = 'main';
- ENDINSTRUCT = ';' ;
- }
- INT : '0'..'9'+ ;
- STRING : '"' ( ~('"') )* '"';
- BOOL : ('True'|'False');
- TYPE : ('A'..'Z')('a'..'z'|'A'..'Z')* ; //'Int' | 'Char' | 'String' | 'Bool' |
- IDENTIFIER : (('a'..'z') ('_'?('a'..'z'|'A'..'Z'|'0'..'9'))*)|'_' ;
- COMMENTAIRE : '--' .* '\n' {$channel=HIDDEN;} ;
- WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;} ;
- code_source
- : main (definition_fct|synonyme)*
- ;
- // Point d'entrée du programme. Doit être analysé en dernier
- main
- : 'main' '=' (expression|ifthen) ';'
- ;
- definition_fct
- : IDENTIFIER (('::' TYPE ('->' TYPE)+ ';') | (((INT+)|(IDENTIFIER+))? ('|' (condition|'otherwise') )? '=' (expression|ifthen) ';'))
- ;
- letin
- : 'let' '{' (IDENTIFIER '=' expression ';')+ '}' 'in' expression
- ;
- ifthen
- : 'if' condition 'then' (expression|ifthen) ('else' (expression|ifthen))?
- ;
- expression
- : 'print' expression
- | 'error' STRING
- | STRING
- | letin
- | niveau_signe
- ;
- niveau_signe
- : ('-')? niveau_somme
- ;
- niveau_somme
- : niveau_fois (('+'|'-') niveau_fois)?
- ;
- // % ou mod ?
- niveau_fois
- : valeur_atomique (('*'|'/'|'%') valeur_atomique)?
- ;
- valeur_atomique
- : INT
- | '(' niveau_signe ')'
- | appel_fct
- ;
- appel_fct
- : IDENTIFIER ('('(niveau_signe(','niveau_signe)*)')')?
- | INT 'mod' INT
- | 'div' '(' niveau_signe ',' niveau_signe ')'
- ;
- synonyme
- : 'type' TYPE '=' TYPE ';'
- ;
- condition
- : expression ('>'|'<'|'>='|'<='|'=='|'/=') expression
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement