summaryrefslogtreecommitdiff
path: root/cmake/elfinfo/src/main/antlr4
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-07-04 21:53:55 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-07-04 21:53:55 +0200
commitc7fb7dfd794700bf6977a907a8612e9b644e4fe4 (patch)
tree57bd9a7f0499c795cf7aa9ba2f1c08ef406df847 /cmake/elfinfo/src/main/antlr4
parentead2f1961fc653861a151a033c3cd0657c50af16 (diff)
downloadintel-quark-d2000-playground-c7fb7dfd794700bf6977a907a8612e9b644e4fe4.tar.gz
intel-quark-d2000-playground-c7fb7dfd794700bf6977a907a8612e9b644e4fe4.tar.bz2
intel-quark-d2000-playground-c7fb7dfd794700bf6977a907a8612e9b644e4fe4.tar.xz
intel-quark-d2000-playground-c7fb7dfd794700bf6977a907a8612e9b644e4fe4.zip
o Improved parser.
Diffstat (limited to 'cmake/elfinfo/src/main/antlr4')
-rw-r--r--cmake/elfinfo/src/main/antlr4/Test1Lexer.g422
-rw-r--r--cmake/elfinfo/src/main/antlr4/Test1Parser.g423
2 files changed, 45 insertions, 0 deletions
diff --git a/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4 b/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4
new file mode 100644
index 0000000..142229d
--- /dev/null
+++ b/cmake/elfinfo/src/main/antlr4/Test1Lexer.g4
@@ -0,0 +1,22 @@
+lexer grammar Test1Lexer;
+
+channels {
+ WHITESPACE_CHANNEL
+}
+
+NAME : [a-z]+;
+
+// Characters
+C_PLUS : '+';
+C_MINUS : '-';
+C_QUOTE : '"' -> skip, pushMode(STRING);
+
+//SPACE : [ ];
+
+WS
+ : [ \t\r\n]+ -> channel(WHITESPACE_CHANNEL)
+ ;
+
+mode STRING;
+STRING_ANY : ~'"';
+STRING_END_QUOTE : '"' -> skip, popMode;
diff --git a/cmake/elfinfo/src/main/antlr4/Test1Parser.g4 b/cmake/elfinfo/src/main/antlr4/Test1Parser.g4
new file mode 100644
index 0000000..affdfe5
--- /dev/null
+++ b/cmake/elfinfo/src/main/antlr4/Test1Parser.g4
@@ -0,0 +1,23 @@
+parser grammar Test1Parser;
+
+options {
+ tokenVocab = Test1Lexer;
+}
+
+name
+ : NAME
+ | STRING_ANY*
+ ;
+
+file
+ : stmt*
+ ;
+
+stmt
+ : expr
+ ;
+
+expr
+ : name C_PLUS name
+ | name C_MINUS name
+ ;