MatchPattern.g4 2.59 KB
Newer Older
Alexander Weigl's avatar
Alexander Weigl committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
grammar MatchPattern;

/* Examples for testing

f(x)
f(x,y,g(y))
X
?Y
_
...
f(... ?X ...)
f(..., ?X)
f(..., ...?X...)
f(..., ... g(x) ...)
f(_, x, _, y, ... y ...)
*/
17

Alexander Weigl's avatar
Alexander Weigl committed
18
19
20
sequentPattern : antec=semiSeqPattern? ARROW succ=semiSeqPattern? #sequentArrow
               | anywhere=semiSeqPattern #sequentAnywhere
               ;
21

22
semiSeqPattern : termPattern (',' termPattern)*;
23

Alexander Weigl's avatar
Alexander Weigl committed
24
termPattern :
25
26
27
28
      termPattern MUL termPattern                               #mult
    | <assoc=right> termPattern op=(DIV|MOD) termPattern        #divMod
    | termPattern op=(PLUS|MINUS) termPattern                   #plusMinus
    | termPattern op=(LE|GE|LEQ|GEQ) termPattern                #comparison
29
    | termPattern op=(NEQ|EQ) termPattern                 #equality
30
31
32
33
    | termPattern AND termPattern                               #and
    | termPattern OR termPattern                                #or
    | termPattern IMP termPattern                               #impl
    | termPattern XOR termPattern                               #xor
34
   // | termPattern EQUIV termPattern                             #equivalence
35
36
37
    //|   termPattern EQUIV termPattern already covered by EQ/NEQ
    | MINUS termPattern                                         #exprNegate
    | NOT termPattern                                           #exprNot
Alexander Weigl's avatar
Alexander Weigl committed
38
39
40
    | '(' termPattern ')' bindClause?                                      #exprParen
    | func=ID ( '(' termPattern (',' termPattern)* ')')? bindClause?        #function
    |  DONTCARE   bindClause?                                              #dontCare
41
42
43
44
45
46
    //| STARDONTCARE  #starDontCare
    | SID                                                       #schemaVar
    | STARDONTCARE termPattern STARDONTCARE                     #anywhere
    | DIGITS                                                    #number
    // not working because of ambigue | left=termPattern op=(PLUS|MINUS|MUL|LE|GE|LEQ|GEQ|NEQ|EQ| AND|OR|IMP) right=termPattern #binaryOperation
    ;
47

Alexander Weigl's avatar
Alexander Weigl committed
48
49
50
/*
f(x), f(x,y,g(y)), X, ?Y, _, ..., f(... ?X ...), f(..., ?X), f(..., ...?X...), f(..., ... g(x) ...), f(_, x, _, y, ... y ...)
*/
51

Alexander Weigl's avatar
Alexander Weigl committed
52
bindClause : ('\\as' | ':') SID;
Alexander Weigl's avatar
Alexander Weigl committed
53
54
55
56

ARROW : '⇒' | '==>';
DONTCARE: '?' | '_' | '█';
STARDONTCARE: '...' | '…';
57
58
59
60
61
62
63
64
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
DIV : '/' ;
EQ : '=' ;
NEQ : '!=' ;
GEQ : '>=' ;
LEQ : '<=' ;
65
EQUIV : '<->';
66
67
68
69
GE : '>' ;
LE : '<' ;
AND : '&' ;
OR: '|' ;
70
IMP: '->';
71
72
MOD:'%';
XOR:'^';
Alexander Weigl's avatar
Alexander Weigl committed
73
74
FORALL: '\forall' | '∀';
EXISTS: '\exists';
75
76
77
78
79

DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
SID: '?' [_a-zA-Z0-9\\]+ ;
ID : [a-zA-Z\\_] ([_a-zA-Z0-9\\])*;
80

Alexander Weigl's avatar
Alexander Weigl committed
81
COMMENT: '//' ~[\n\r]* -> channel(HIDDEN);
82
WS: [\n\f\r\t ] -> channel(HIDDEN);