CERT-SEI

CCL Grammar

BNF Specification of CCL v1.0

BNF Notation

     
  • A* zero or more A
  •  
  • A+ one or more A
  •  
  • [A]zero or one A
  •  
  • A | B   either A or B (alternation)
  •  
  • A B  A followed by B (concatenation)
  •  
  • ()    grouping
  •  
  • N : P  production, non-terminal N defined in terms of A
  •  
  • {comments are in braces and italicized}

Keywords and Symbols

     
  • Keywords are shown boldface
  •  
  • Literal symbols are also shown in boldface, e.g., ; { } ( ) .
  •  
  • String, integer, float, etc., literals are STRING_LIT, INT_LIT, …
  •  
  • ID is the designated literal for Identifiers

Start : cclSpec
cclSpec:
            topLevelUnit*
topLevelUnit:
            simpleUnit | constructiveUnit                      

simpleUnit:
            annotation      | declaration  

constructiveUnit:
            assemblyDecl | componentDecl | environmentDecl

declaration:
            variableDeclaration ;
            | constantDeclaration ;
            | typeDeclaration ;
            | procDeclaration

variableDeclaration: typeSpecifier initDeclarator (, initDeclarator)*

constantDeclaration:
            const typeSpecifier initDeclarator (, initDeclarator)*

typeDeclaration:
            typedef typeDeclSpecifier initDeclarator (, initDeclarator)*

procDeclaration:
            [extern] proc typeSpecifier ID (formalParam*) { procPart* }

procPart:
            declaration | action

typeSpecifier:
            int        
            | bool
            | float
            | string      
            | void            
            | scopedId

typeDeclSpecifier:
            typeSpecifier | enumSpecifier

enumSpecifier:
            enum { enumerator+ }

enumerator:
            ID | ID = constantExpression

initDeclarator:
            declarator       | declarator = initializer

declarator:
            ID
            | ID ( [conditionalExpression (, conditionalExpression)*] ) [elaborate]
            | ID ( [ constantExpression ] )+                                 

initializer:
            assignmentExpression
            | { initializer (, initializer)* }                      

elaborate:

{ resourceStm ; (resourceStm ;)* }

resourceStm:
            variableDeclaration
            | scopedId = scopedId

annotation: annnotate scopedId { STRING_LIT , constantDeclaration }

scopedId: [:] ID (: ID)* (. ID)*

assemblyDecl:
            assembly ID ( [formalParam (, formalParam)*] ) ( ID )              
            { assumeClause assemblyPart* exposeClause }

assumeClause:
            assume { (variableDeclaration ;)* }

exposeClause:

expose { [exposePin (, exposePin)* ] }

exposePin:
            scopedId [as ID]

assemblyPart:
         annotation
            | interaction
            | declaration

interaction:

scopedId ~> ( scopedId | { scopedId (, scopedId)* } )

componentDecl:     
            component ID ( [formalParam (, formalParam)*] ) { comPart* }

formalParam: [ const ] typeSpecifier [ & ] ID

comPart:
            annotation
            | declaration
            | sinkPinSpec
            | sourcePinSpec
            | reaction
            | verbatim

sinkPinSpec:
            sink (asynch | synch) ID ( [pinParam (, pinParam)* ] ) ;          

sourcePinSpec:
            source (asynch | synch) ID ([pinParam (, pinParam)* ]) ;

pinParam:
            (consume | produce) formalParam

reaction:
            [threaded] react ID (pinXRef ) { reactStm* }

pinXref:
            { ID (, ID)* }

reactStm:
            declaration
            | stateSpec
            | transitionSpec

stateSpec:
             state ID  { action* }

action:
            verbatimLit
            | assignmentExpression ;
            | returnStatement ;
            | iteration
            | ifThenElse
            | alert ( conditionalExpression , conditionalExpression ) ;
            | { action action* }

iteration:       
            whileIteration
            | forIteration
            | doWhileIteration

whileIteration:
        while ( conditionalExpression ) action

forIteration:
       for (
         [ assignmentExpression ] ;
         [ assignmentExpression ] ;
         [ assignmentExpression ] ) action

doWhileIteration:
        do action while ( conditionalExpression ) ;

returnStatement:
        return [ assignmentExpression ]

ifThenElse:
            if ( conditionalExpression ) action [ else action ]

transitionSpec:
            transitionHead -> ID { [event] [guard] [action] }

transitionHead:
            start | ID

event:
            | trigger eventTrigger ;
            | trigger timeTrigger ;

eventTrigger:
            unaryExpression {Note: must be ^unaryExpression or $unaryExpression}

timeTrigger:

after ( additiveExpression )

guard:
            guard conditionalExpression ;

environmentDecl:
            environment ID ([formalParam (, formalParam)*]) { environPart* }

environPart:
            annotation
            | declaration
            | serviceSpec

serviceSpec:
            [ singleton ] service ID ([formalParam (, formalParam)*]) { comPart* }

assignmentExpression:
            conditionalExpression
            | unaryExpression = assignmentExpression

conditionalExpression:
            equalityExpression
            | conditionalExpression || equalityExpression
            | conditionalExpression && equalityExpression

constantExpression: conditionalExpression

equalityExpression:
            relationalExpression
            | equalityExpression == relationalExpression
            | equalityExpression != relationalExpression

relationalExpression:
            additiveExpression
            | relationalExpression < additiveExpression
            | relationalExpression <= additiveExpression
            | relationalExpression > additiveExpression
            | relationalExpression >= additiveExpression

additiveExpression:
            multiplicativeExpression
            | additiveExpression + multiplicativeExpression
            | additiveExpression - multiplicativeExpression

multiplicativeExpression:
            castExpression
            | multiplicativeExpression * castExpression
            | multiplicativeExpression / castExpression
            | multiplicativeExpression % castExpression

castExpression:
            unaryExpression
            | ( typeIdentifier ) castExpression

typeIdentifier:
            int | float | boolean

unaryExpression:
            postfixExpression
            | ^ unaryExpression
            | $ unaryExpression
            | ++ unaryExpression
            | -- unaryExpression
            | + unaryExpression
            | - unaryExpression
            | !  unaryExpression

postfixExpression:
            primaryExpression
            | postfixExpression [ additiveExpression ]
            | postfixExpression ([conditionalExpresssion (, conditioalExpression)*])
            | postfixExpression ++
            | postfixExpression --

primaryExpression:
            scopedId
            | literalValue
            | ( assignmentExpression )

literalValue:
            INT_LIT
            | FLOAT_LIT      
            | STRING_LIT
            | true
            | false

ID: letter (letter | digit | _)*
INT_LIT: digit (digit)*
FLOAT_LIT: digit* . digit+
STRING_LIT: quoted text following C rules

SEI Blog