summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-17 17:34:40 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-17 17:34:40 +0200
commit44c43a703e2d996ac80318a67c7ba3a828dca19b (patch)
tree8571efbf3c676abbcce9bfd9d1b817ec98dac950 /instr-to-kodkod/parser
parentc5caca06e411066828cec2a6008c126d64ffabb6 (diff)
Starting to work on a parser for the properties.
Diffstat (limited to 'instr-to-kodkod/parser')
-rw-r--r--instr-to-kodkod/parser/PropertyLexer.g413
-rw-r--r--instr-to-kodkod/parser/PropertyParser.g430
2 files changed, 43 insertions, 0 deletions
diff --git a/instr-to-kodkod/parser/PropertyLexer.g4 b/instr-to-kodkod/parser/PropertyLexer.g4
new file mode 100644
index 0000000..27f1bca
--- /dev/null
+++ b/instr-to-kodkod/parser/PropertyLexer.g4
@@ -0,0 +1,13 @@
+lexer grammar PropertyLexer;
+
+TAG_EXISTING_KW: '(tag_existing';
+AND_OPERATOR_KW: '(and';
+OR_OPERATOR_KW: '(or';
+NOT_OPERATOR_KW: '(not';
+EXISTS_OPERATOR_KW: '(exists';
+FORALL_OPERATOR_KW: '(forall';
+ID: [a-zA-Z0-9_]+;
+L_PAREN : '(';
+R_PAREN : ')';
+
+WS: [ \t\r\n]+ -> skip;
diff --git a/instr-to-kodkod/parser/PropertyParser.g4 b/instr-to-kodkod/parser/PropertyParser.g4
new file mode 100644
index 0000000..740b308
--- /dev/null
+++ b/instr-to-kodkod/parser/PropertyParser.g4
@@ -0,0 +1,30 @@
+parser grammar PropertyParser;
+options { tokenVocab = PropertyLexer; }
+
+prog: tag_existing;
+
+tag_existing
+ : TAG_EXISTING_KW L_PAREN (tag_item)+ R_PAREN formula R_PAREN
+;
+
+tag_item
+ : L_PAREN ID ID R_PAREN
+;
+
+formula
+ : and_operator
+ | or_operator
+ | not_operator
+ | exists_operator
+ | forall_operator
+ | predicate
+;
+
+and_operator: AND_OPERATOR_KW formula (formula)+ R_PAREN;
+or_operator: OR_OPERATOR_KW formula (formula)+ R_PAREN;
+not_operator: NOT_OPERATOR_KW formula R_PAREN;
+exists_operator: EXISTS_OPERATOR_KW ID ID formula R_PAREN;
+forall_operator: FORALL_OPERATOR_KW ID ID formula R_PAREN;
+
+
+predicate: L_PAREN ID (ID)* R_PAREN;