summaryrefslogtreecommitdiff
path: root/src/parser/smt/smt_lexer.g
blob: 695b7b787aebb7d1f805e8a2bf0678259a7b7fb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* *******************                                                        */
/*  smt_lexer.g
 ** Original author: dejan
 ** Major contributors: cconway, mdeters
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.
 **
 ** Lexer for SMT-LIB input language.
 **/

options {
  language = "Cpp";            // C++ output for antlr
  namespaceStd  = "std";       // Cosmetic option to get rid of long defines in generated code
  namespaceAntlr = "antlr";    // Cosmetic option to get rid of long defines in generated code
  namespace = "CVC4::parser";  // Wrap everything in the smtparser namespace
}

/**
 * AntlrSmtLexer class is a stream tokenizer (lexer) for the SMT-LIB benchmark
 * language.
 */
class AntlrSmtLexer extends Lexer;

options {
  exportVocab = SmtVocabulary;  // Name of the shared token vocabulary
  testLiterals = false;         // Do not check for literals by default
  defaultErrorHandler = false;  // Skip the default error handling, just break with exceptions
  k = 2;
}

tokens {
  // Base SMT-LIB tokens
  DISTINCT      = "distinct";
  ITE           = "ite";
  IF_THEN_ELSE  = "if_then_else";
  TRUE          = "true";
  FALSE         = "false";
  NOT           = "not";
  IMPLIES       = "implies";
  AND           = "and";
  OR            = "or";
  XOR           = "xor";
  IFF           = "iff";
  EXISTS        = "exists";
  FORALL        = "forall";
  LET           = "let";
  FLET          = "flet";
  THEORY        = "theory";
  LOGIC         = "logic";
  SAT           = "sat";
  UNSAT         = "unsat";
  UNKNOWN       = "unknown";
  BENCHMARK     = "benchmark";
  // The SMT attribute tokens
  LOGIC_ATTR       = ":logic";
  ASSUMPTION_ATTR  = ":assumption";
  FORMULA_ATTR     = ":formula";
  STATUS_ATTR      = ":status";
  EXTRASORTS_ATTR  = ":extrasorts";
  EXTRAFUNS_ATTR   = ":extrafuns";
  EXTRAPREDS_ATTR  = ":extrapreds";
  C_NOTES       = ":notes";
  // arithmetic symbols
  EQUAL         = "=";
  LESS_THAN     = "<";
  GREATER_THAN  = ">";
  AMPERSAND     = "&";
  AT            = "@";
  POUND         = "#";
  PLUS          = "+";
  MINUS         = "-";
  STAR          = "*";
  DIV           = "/";
  PERCENT       = "%";
  PIPE          = "|";
  TILDE         = "~";
}

/**
 * Matches any letter ('a'-'z' and 'A'-'Z').
 */
protected
ALPHA options { paraphrase = "a letter"; }
  :  'a'..'z'
  |  'A'..'Z'
  ;

/**
 * Matches the digits (0-9)
 */
protected
DIGIT options { paraphrase = "a digit"; }
  :   '0'..'9'
  ;

/**
 * Matches an identifier from the input. An identifier is a sequence of letters,
 * digits and "_", "'", "." symbols, starting with a letter.
 */
IDENTIFIER options { paraphrase = "an identifier"; testLiterals = true; }
  :  ALPHA (ALPHA | DIGIT | '_' | '\'' | '.')*
  ;

/**
 * Matches an identifier starting with a colon. An identifier is a sequence of letters,
 * digits and "_", "'", "." symbols, starting with a colon.
 */
C_IDENTIFIER options { paraphrase = "an identifier starting with a colon"; testLiterals = true; }
  :  ':' ALPHA (ALPHA | DIGIT | '_' | '\'' | '.')*
  ;

/**
 * Matches the value of user-defined annotations or attributes. The only constraint imposed on a user-defined value is that it start with
 * an open brace and end with closed brace.
 */
USER_VALUE
  :   '{'
      ( '\n' { newline(); }
      | ~('{' | '}' | '\n')
        )*
    '}'
  ;

/**
 * Matches the question mark symbol ('?').
 */
QUESTION_MARK options { paraphrase = "a question mark '?'"; }
  :  '?'
  ;

/**
 * Matches the dollar sign ('$').
 */
DOLLAR_SIGN options { paraphrase = "a dollar sign '$'"; }
  :  '$'
  ;

/**
 * Matches the left bracket ('(').
 */
LPAREN options { paraphrase = "a left parenthesis '('"; }
  :   '(';

/**
 * Matches the right bracket ('(').
 */
RPAREN options { paraphrase = "a right parenthesis ')'"; }
  :   ')';

/**
 * Matches and skips whitespace in the input.
 */
WHITESPACE options { paraphrase = "whitespace"; }
  :  (' ' | '\t' | '\f')              { $setType(antlr::Token::SKIP); }
  ;

/**
 * Matches and skips the newline symbols in the input.
 */
NEWLINE options { paraphrase = "a newline"; }
  :   ('\r' '\n' | '\r' | '\n')       { $setType(antlr::Token::SKIP); newline(); }
  ;

/**
 * Matches a numeral from the input (non-empty sequence of digits).
 */
NUMERAL options { paraphrase = "a numeral"; }
  :  (DIGIT)+
  ;

/**
 * Matches an allowed escaped character.
 */
protected ESCAPE
  : '\\' ('"' | '\\' | 'n' | 't' | 'r')
  ;

/**
 * Matches a double quoted string literal. Escaping is supported, and escape
 * character '\' has to be escaped.
 */
STRING_LITERAL options { paraphrase = "a string literal"; }
  :  '"' (ESCAPE | ~('"'|'\\'))* '"'
  ;

/**
 * Matches the comments and ignores them
 */
COMMENT options { paraphrase = "comment"; }
  : ';' (~('\n' | '\r'))*                    { $setType(antlr::Token::SKIP); }
  ;

/* Arithmetic symbol tokens */
EQUAL :   "=";
LESS_THAN : "<";
GREATER_THAN : ">";
AMPERSAND :  "&";
AT :  "@";
POUND :  "#";
PLUS :  "+";
MINUS :  "-";
STAR :  "*";
DIV :  "/";
PERCENT :  "%";
PIPE :  "|";
TILDE : "~";
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback