]> pd.if.org Git - pccts/commitdiff
auto commit for import
authorTerence Parr <>
Thu, 14 Sep 1995 00:24:12 +0000 (19:24 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 26 Feb 2017 02:16:51 +0000 (20:16 -0600)
testcpp/5/test.g [new file with mode: 0755]

diff --git a/testcpp/5/test.g b/testcpp/5/test.g
new file mode 100755 (executable)
index 0000000..ca4b8f7
--- /dev/null
@@ -0,0 +1,70 @@
+/* This is test.g which tests multiple scanners/parsers; DLG-based scanner */
+<<
+#include "Lexer.h"
+typedef ANTLRCommonToken ANTLRToken;
+
+int main()
+{
+       ANTLRTokenPtr aToken = new ANTLRToken;
+       DLGFileInput in(stdin);
+       Lexer scan(&in);
+       scan.setToken(mytoken(aToken));
+       ANTLRTokenBuffer pipe(&scan);
+       Include parser(&pipe);
+       parser.init();
+
+       parser.input();
+       return 0;
+}
+>>
+
+#token "[\ \t\n]+"     <<skip();>>
+#token Eof "@"
+
+class Include {
+
+<<
+/* this is automatically defined to be a member function of Include::
+ * since it is within the "class {...}" boundaries.
+ */
+private:
+char *stripquotes(ANTLRChar *s)
+{
+       s[strlen(s)-1] = '\0';
+       return &s[1];
+}
+>>
+
+input
+       :       ( cmd | include )* Eof
+       ;
+
+cmd    :       "print"
+               (       NUMBER          <<printf("%s\n", $1->getText());>>
+               |       STRING          <<printf("%s\n", $1->getText());>>
+               )
+       ;
+
+include
+       :       "#include" STRING
+               <<{
+               FILE *f;
+               f = fopen(stripquotes($2->getText()), "r");
+               if ( f==NULL ) {fprintf(stderr, "can't open %s\n", $2->getText()+1);}
+               else {
+                       ANTLRTokenPtr aToken = new ANTLRToken;
+                       DLGFileInput in(f);
+                       Lexer scan(&in);
+                       scan.setToken(mytoken(aToken));
+                       ANTLRTokenBuffer pipe(&scan);
+                       Include parser(&pipe);
+                       parser.init();
+                       parser.input();
+               }
+               }>>
+       ;
+
+}
+
+#token STRING  "\" [a-zA-Z0-9_.,\ \t]+ \""
+#token NUMBER  "[0-9]+"