-- The different sections of a TCS model have been enclosed between BEGIN and END -- comments below. Additional information is provided below each BEGIN comment. -- The main sections of interest are "Class templates", and -- "Operator table" (only for DSLs using operators). syntax AFortran { -- BEGIN Primitive templates -- Specifies representation of primitive types. -- Only needs modification when default lexer is not satisfactory. -- Generally modified along with the lexer. primitiveTemplate identifier for String default using NAME: value = "%token%"; primitiveTemplate stringSymbol for String using STRING: value = "%token%", serializer="'\'' + %value%.toCString() + '\''"; primitiveTemplate integerSymbol for Integer default using INT: value = "Integer.valueOf(%token%)"; primitiveTemplate floatSymbol for Double default using FLOAT: value = "Double.valueOf(%token%)"; -- END Primitive templates -- BEGIN Class templates -- Specifies representation of classes. -- This is the main section to work on. -- Generic Templates template Expression abstract; template ParameterDef abstract; template Element abstract; template Advice abstract; template Statement abstract; template Domain : "domain" name ";" ; template Pointcut context addToContext : "pointcut" name "(" paramdefs{separator = ","} ")" ":" pctexpr{separator = "&&"} ";" ; -- have to link the paramdefs of pointcut to paramdefs of advice template BeforeAdvice : "before" "(" paramdefs{separator = ","} ")" ":" pctname{refersTo = name} "(" paramdefs{separator = ","} ")" "{" advStmt "}" ; template AfterAdvice : "after" "(" paramdefs{separator = ","} ")" ":" pctname{refersTo = name} "(" paramdefs{separator = ","} ")" "{" advStmt "}" ; template AroundAdvice : "around" "(" paramdefs{separator = ","} ")" ":" pctname{refersTo = name} "(" paramdefs{separator = ","} ")" "{" advStmt "}" ; template Parameter : name ; template OpaqueStatement : stmt {as = stringSymbol} ";" ; template ProccedStatement : "proceed" "(" ")" ";" ; template LoopStatement abstract; template LoopExpr : "execution" "(" loopStmt ")" ; template LoopInitCondition abstract; template LoopExitCondition abstract; template LoopStrideCondition abstract; template IntegerLoopInitCondition : "init" ":" condition ; template IntegerLoopExitCondition : "exitcond" ":" condition ; template IntegerLoopStrideCondition : "stride" ":" condition ; template StringLoopInitCondition : "init" ":" condition ; template StringLoopExitCondition : "exitcond" ":" condition ; template StringLoopStrideCondition : "stride" ":" condition ; template ArgsExpr : "args" "(" name ")" ; -- Aspect Fortran Specific Templates template AFortran main : domain "aspect" name "{" pointcut advice "}" ; template FuncOrSubSignature abstract; template ExecExpr : "execution" "(" func_sub_Sig ")" ; template WithinCodeExpr : "withincode" "(" func_sub_Sig ")" ; -- need to handle in a better way template NotWithinCodeExpr : "!" "withincode" "(" func_sub_Sig ")" ; template CallExpr : "call" "(" func_sub_Sig ")" ; template FuncOrSubCallExpr : "CALL" name "(" params{separator = ","} ")" ; template FuncOrSubDefExpr abstract; template FuncOrSubDef abstract; template FuncDef : "FUNCTION" name "(" paramdefs{separator = ","} ")" ; template SubDef : "SUBROUTINE" name "(" paramdefs{separator = ","} ")" ; template FortranParamDef : type name ; template DoLoop : "do" "(" loopInitCondition "," loopExitCondition "," loopStrideCondition")" ; -- END Class templates -- BEGIN Special symbols -- Possible modifications: -- - Addition of new symbols. -- - Modification of spaces information. -- - Removal of unused symbols so that using these symbols results in lexical -- error rather than parsing error. symbols { lsquare = "["; rsquare = "]" : rightSpace; excl = "!"; coma = "," : leftNone, rightSpace; lparen = "("; rparen = ")" : leftNone, rightSpace; lcurly = "{" : leftSpace; rcurly = "}" : leftNone, rightSpace; semi = ";" : leftNone, rightSpace; colon = ":" : leftSpace, rightSpace; pipe = "|" : leftSpace, rightSpace; sharp = "#" : leftSpace; qmark = "?"; coloncolon = "::" : leftNone, rightNone; -- operator symbols point = "." : leftNone; rarrow = "->" : leftNone; minus = "-" : leftSpace, rightSpace; -- star = "*" : leftSpace, rightSpace; slash = "/" : leftSpace, rightSpace; plus = "+" : leftSpace, rightSpace; eq = "=" : leftSpace, rightSpace; gt = ">" : leftSpace, rightSpace; lt = "<" : leftSpace, rightSpace; ge = ">=" : leftSpace, rightSpace; le = "<=" : leftSpace, rightSpace; ne = "<>" : leftSpace, rightSpace; larrow = "<-" : leftSpace, rightSpace; } -- END Special symbols -- BEGIN Operator table -- Defines all operators with their priority, arity, and associativity. -- All defined operators must be used in operator templates. -- No operator in SampleDSL. The Calc DSLs may be used as examples. -- END Operator table -- BEGIN Lexer -- Specifies the lexical entities. -- Only needs modification when default lexer is not satisfactory. -- Generally modified along with Primitive templates. token COMMENT : endOfLine(start = "--"); lexer = " %options testLiterals = false; NL : ( '\\r' '\\n' | '\\n' '\\r' //Improbable | '\\r' | '\\n' ) {newline();} ; WS : ( ' ' | '\\t' ) ; %protected DIGIT : '0'..'9' ; %protected ALPHA : 'a'..'z' | 'A'..'Z' | '_' //For Unicode compatibility (from 0000 to 00ff) | '\\u00C0' .. '\\u00D6' | '\\u00D8' .. '\\u00F6' | '\\u00F8' .. '\\u00FF' ; %protected SNAME %v2 options { %v2 testLiterals = true; %v2 } : (ALPHA) (ALPHA | DIGIT)* ; NAME : ( %v3 SNAME %v2 s:SNAME {if(s.getType() != SNAME) $setType(s.getType());} | '\"'! ( ESC | '\\n' {newline();} | ~('\\\\'|'\\\"'|'\\n') )* '\"'! %v3 {setText(ei.unescapeString(getText(), 1));} ) | '*' ; INT : (DIGIT)+ %v2 (('.' DIGIT)=> '.' (DIGIT)+ {$setType(FLOAT);})? ; %v3 FLOAT : DIGIT+ '.' DIGIT* ; %protected ESC : '\\\\'! ( 'n' %v2{%setText(\"\\n\");} | 'r' %v2{%setText(\"\\r\");} | 't' %v2{%setText(\"\\t\");} | 'b' %v2{%setText(\"\\b\");} | 'f' %v2{%setText(\"\\f\");} | '\"' %v2{%setText(\"\\\"\");} | '\\'' %v2{%setText(\"\\'\");} | '\\\\' %v2{%setText(\"\\\\\");} | ( ('0'..'3') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : ('0'..'7') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : '0'..'7' )? )? | ('4'..'7') ( %v2 options { %v2 warnWhenFollowAmbig = false; %v2 } : ('0'..'7') )? ) { %v2 String s = %getText; %v2 int i; %v2 int ret = 0; %v2 String ans; %v2 for (i=0; i