PQL queries are expressed in terms of program design models (entities and abstractions).
PQL queries references the following:
procedure.procName
or variable.varName
Modifies (procedure, variable)
assign (variable, expr)
Evaluation of a query yields a list of program elements that match a query. Program elements are specific instances of design entities (e.g. procedure named main
, statement number 35
, or variable named x
).
Basic queries contain:
procedure p; variable v;
where p
is a procedure entity and v
is a variable entityThere is an implicit and
operator between clauses. Query results must make sure that they satisfy all clauses.
A query written in PQL is syntactically valid if it follows all the defined language rules.
Meta symbols:
a* - repetition 0 or more times of a
a+ - repetition 1 or more times of a
[ a ] - repetition 0 or one occurrence of 'a'
a | b - a or b
Lexical tokens:
LETTER: A-Z | a-z - capital or small letter
DIGIT: 0-9
NZDIGIT: 1-9 - non-zero digit
IDENT : LETTER ( LETTER | DIGIT )*
NAME : LETTER ( LETTER | DIGIT )*
INTEGER : 0 | NZDIGIT ( DIGIT )* - no leading zero
synonym : IDENT
stmtRef : synonym | '_' | INTEGER
entRef : synonym | '_' | '"' IDENT '"'
Grammar rules:
select-cl : declaration* 'Select' synonym [ suchthat-cl ] [ pattern-cl ]
declaration : design-entity synonym (',' synonym)* ';'
design-entity : 'stmt' | 'read' | 'print' | 'call' | 'while' |
'if' | 'assign' | 'variable' | 'constant' | 'procedure'
suchthat-cl : 'such' 'that' relRef
relRef : Follows | FollowsT | Parent | ParentT | UsesS | UsesP | ModifiesS | ModifiesP
Follows : 'Follows' '(' stmtRef ',' stmtRef ')'
FollowsT : 'Follows*' '(' stmtRef ',' stmtRef ')'
Parent : 'Parent' '(' stmtRef ',' stmtRef ')'
ParentT : 'Parent*' '(' stmtRef ',' stmtRef ')'
UsesS : 'Uses' '(' stmtRef ',' entRef ')'
UsesP : 'Uses' '(' entRef ',' entRef ')'
ModifiesS : 'Modifies' '(' stmtRef ',' entRef ')'
ModifiesP : 'Modifies' '(' entRef ',' entRef ')'
pattern-cl : 'pattern' syn-assign '(' entRef ',' expression-spec ')'
expression-spec : '"' expr'"' | '_' '"' expr '"' '_' | '_'
expr: expr '+' term | expr '-' term | term
term: term '*' factor | term '/' factor | term '%' factor | factor
factor: var_name | const_value | '(' expr ')'
syn-assign : IDENT
var_name: NAME
const_value : INTEGER
Notes:
x
, +
and y
in any of the following character streams:
x+y
x + y
x +y
assign pattern; variable Select, assign; Select Select pattern pattern(assign, _)
A syntactically valid query is semantically invalid if it violates rules that cannot be captured by the language rules.
The following are rules that are not captured by the grammar:
A synonym name can only be declared once.
All the synonyms used in clauses must be declared exactly once.
syn-assign
must be declared as a synonym of an assignment (design entity assign
).
The first argument for Modifies
and Uses
cannot be _
, as it is unclear whether _
refers to a statement or procedure.
Synonyms of design entities can appear as relationship arguments, and should match the design entity defined for the relationship.
Parent(arg1, arg2)
, if arg1
is a synonym, then arg1
must be a statement synonym, or a subtype of a statement synonym (read, print, assign, if, while, call).Modifies(arg1, arg2)
, if arg2
is a synonym, then arg2
must be a variable synonym.Design Abstraction | First argument | Second argument |
---|---|---|
Follows / Follows* | Synonym of statement or a statement subtype | Synonym of statement or a statement subtype |
Parent / Parent* | Synonym of statement or a statement subtype | Synonym of statement or a statement subtype |
Uses / Modifies | Synonym of statement or a statement subtype or procedure | Synonym of variable |
Similarly, synonyms of design entities can appear as arguments in pattern clauses, and should match the design entity defined for pattern clauses.
pattern a (arg1, _)
, if arg1
is a synonym, then arg1
must be a variable synonym.