File: test.g

package info (click to toggle)
pccts 1.33MR33-6
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 3,220 kB
  • ctags: 5,279
  • sloc: ansic: 46,053; cpp: 3,234; makefile: 959
file content (45 lines) | stat: -rw-r--r-- 975 bytes parent folder | download | duplicates (19)
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
/* This is test.g which tests a simple DLG-based scanner
 * with user-defined tokens
 */

/* Here, we use #tokdefs to define token types, but still let DLG do the
 * lexing. ANTLR will not create a tokens.h file.
 */
#tokdefs "mytokens.h"

<<
#include "DLGLexer.h"		/* include definition of DLGLexer.
							 * This cannot be generated automatically because
							 * ANTLR has no idea what you will call this file
							 * with the DLG command-line options.
							 */

typedef ANTLRCommonToken ANTLRToken;

int main()
{
	ANTLRTokenPtr aToken = new ANTLRToken;
	DLGFileInput in(stdin);
	DLGLexer scan(&in);
	ANTLRTokenBuffer pipe(&scan);
	scan.setToken(mytoken(aToken));
	Expr parser(&pipe);
	parser.init();

	parser.e();
	return 0;
}
>>

#token "[\ \t\n]+"	<<skip();>>

class Expr {				/* Define a grammar class */

e	:	IDENTIFIER NUMBER "@"
		<<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
	;

}

#token IDENTIFIER	"[a-z]+"
#token NUMBER		"[0-9]+"