Appendix A. Summary of PQL grammar rules

advertisement
CS3215 (2010): Project Handbook
Appendix A. Summary of PQL grammar rules
Lexical tokens are written in capital letters (e.g., LETTER, INTEGER, STRING). Keywords
are between apostrophes (e.g., ‘procedure’). Non-terminals are in small letters.
Meta symbols:
a* - repetition 0 or more times of a
a+ - repetition 1 or more times of a
a | b - a or b
brackets ( and ) are used for grouping
Lexical rules:
LETTER : A-Z | a-z -- capital or small letter
DIGIT : 0-9
IDENT : LETTER ( LETTER | DIGIT | ‘#’ )*
INTEGER : DIGIT+
Auxiliary grammar rules:
tuple : elem | ‘<’ elem ( ‘,’ elem )* ‘>’
elem : synonym | attrRef
synonym : IDENT
attrName : ‘procName’ | ‘varName’ | ‘value’ | ‘stmt#’
entRef : synonym | ‘_’ | ‘”’ IDENT ‘”’ | INTEGER
stmtRef : synonym | ‘_’ | INTEGER
lineRef : synonym | ‘_’ | INTEGER
design-entity : ‘procedure’ | ‘stmtLst’ | ‘stmt’ | ‘assign’ | ‘call’ | ‘while’ | ‘if’ | ‘variable’ |
‘constant’ | ‘prog_line’
Grammar rules for select clause:
select-cl : declaration* ‘Select’ result-cl ( with-cl | suchthat-cl | pattern-cl )*
declaration : design-entity synonym (‘,’ synonym)* ‘;’
result-cl : tuple | ‘BOOLEAN’
with-cl : ‘with’ attrCond
suchthat-cl : ‘such that’ relCond
pattern-cl : ‘pattern’ patternCond
attrCond : attrCompare (‘and’ attrCompare )*
attrCompare : attrRef ‘=’ ref
attrRef : synonym ‘.’ attrName
ref : ‘”’ IDENT ‘”’ | INTEGER | attrRef
relCond : relRef ( ‘and’ relRef )*
relRef : ModifiesP | ModifiesS | UsesP | UsesS | Calls | CallsT |
Parent | ParentT | Follows | FollowsT | Next | NextT | Affects | AffectsT
ModifiesP : ‘Modifies’ ‘(’ entRef ‘,’ entRef ‘)’
ModifiesS : ‘Modifies’ ‘(’ stmtRef ‘,’ entRef ‘)’
UsesP : ‘Uses’ ‘(’ entRef ‘,’ entRef ‘)’
UsesS : ‘Uses’ ‘(’ stmtRef ‘,’ entRef ‘)’
Calls : ‘Calls’ ‘(’ entRef ‘,’ entRef ‘)’
CallsT : ‘Calls*’ ‘(’ entRef ‘,’ entRef ‘)’
Parent : ‘Parent’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
ParentT : ‘Parent*’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
Follows : ‘Follows’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
Copyright © Stan Jarzabek 2010
FollowsT : ‘Follows*’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
Next : ‘Next’ ‘(’ lineRef ‘,’ lineRef ‘)’
NextT : ‘Next*’ ‘(’ lineRef ‘,’ lineRef ‘)’
Affects : ‘Affects’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
AffectsT : ‘Affects*’ ‘(’ stmtRef ‘,’ stmtRef ‘)’
patternCond : pattern ( ‘and’ pattern )*
pattern : assign | while | if
assign : synonym ‘(’ entRef ‘,’ sub-expression-spec | ‘_’ ‘)’
sub-expression-spec : sub-expression
| ‘_’ sub-expression
| sub-expression ‘_’
| ‘_’ sub-expression ‘_’
sub-expression : ‘“’ sub_expr ‘”’
// ‘synonym’ above must be of type ‘assign’
// sub-expr must be a well-formed expression in SIMPLE, except that brackets are not used
// see query examples in section Error! Reference source not found. in the Project
Handbook
if : synonym ‘(’ entRef ‘,’ ‘_’ ‘,’ ‘_’ ‘)’
// ‘synonym’ above must be of type ‘if’
while : synonym ‘(’ entRef ‘,’ ‘_’ ‘)’
// ‘synonym’ above must be of type ‘while’
Summary of other PQL rules:
1. PQL query can contain any number of such that, with and pattern clauses. All the
clauses may appear more than one time in a query, in any order, e.g.:
Select … with … such that … with … with … pattern … such that …
2. There is a default and between any two consecutive clauses. Therefore, we can swap or
merge clauses without changing the meaning of the query.
3. A query result must satisfy all the query conditions in all the clauses. The existential
quantifier is always implicit in PQL queries. That means, a query returns any result for
which THERE EXISTS a combination of synonym instances satisfying the conditions
specified in all the query conditions.
4. If the query result clause is a tuple, then tuple elements that satisfy all the query conditions
at the same time are reported as query result.
5. Query with result BOOLEAN returns true iff there is at least one combination of
synonyms satisfying all the query conditions.
6. All the synonyms used in a query must be declared.
7. Spaces can be freely used and are meaningless (also multiple spaces).
8. Arguments in relationships should be synonyms, ‘_’ and, depending on the relationship,
integer (statement line numbers or program line numbers) or string (variable or procedure
names). Relationship arguments should conform to program design abstractions models
for SIMPLE, as defined in Section Error! Reference source not found..
9. Underscore ‘_’ is a placeholder for an unconstrained synonym. Symbol ‘_’ can be only
used when the context uniquely implies the type of the design enity denoted by ‘_’.
10. Under with we can compare an attribute value and constant (integer or string, depending
on the type of attribute) or two attribute values (provided they are of the same type).
11. Please check conventions described in Section Error! Reference source not found., as
they apply in addition to the above PQL core rules.
12. You can make your own assumptions about any other details that have not been specified
in the Handbook – such as case-sensitivity of identifiers/keywords.
--- The End ---
Copyright © Stan Jarzabek 2010
2
Download