From: Terence Parr <> Date: Thu, 14 Sep 1995 01:02:42 +0000 (-0500) Subject: auto commit for import X-Git-Url: https://pd.if.org/git/?p=pccts;a=commitdiff_plain;h=fc721223c8cd72f1b93e0a41cf9e871be62d6c74 auto commit for import --- diff --git a/testcpp/11/test.g b/testcpp/11/test.g new file mode 100755 index 0000000..b3a2349 --- /dev/null +++ b/testcpp/11/test.g @@ -0,0 +1,78 @@ +/* This is test.g which tests multiple scanners/parsers; DLG-based scanner; + * also, we test multiple lexical classes. + */ +<< +#include "Lexer.h" +typedef ANTLRCommonToken ANTLRToken; +#include "PBlackBox.h" + +int main() +{ + ParserBlackBox p(stdin); + p.parser()->input(); + return 0; +} +>> + +#token "[\ \t\n]+" <> + +#lexclass START + +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 )* "@" + ; + +cmd : "print" + ( NUMBER <getText());>> + | STRING <getText());>> + ) + ; + +include + : "#data" 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)); + scan.mode(Lexer::DATA); + ANTLRTokenBuffer pipe(&scan); + Include parser(&pipe); + parser.init(); + parser.data(); + } + }>> + ; + +#lexclass DATA + +#token "[\ \t\n]+" <> + +data: "0x[0-9]+" ":" "0x[0-9]+" + <getText());>> + ; + +} + +#lexclass START + +#token STRING "\" [a-zA-Z0-9_.,\ \t]+ \"" +#token NUMBER "[0-9]+"