File: test.g

package info (click to toggle)
pccts 1.33MR33-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,212 kB
  • ctags: 5,280
  • sloc: ansic: 46,051; cpp: 3,234; makefile: 957
file content (39 lines) | stat: -rw-r--r-- 1,038 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
/* This is test.g which tests a simple DLG-based scanner using string input */

<<
typedef ANTLRCommonToken ANTLRToken;

#include "DLGLexer.h"
#include "PBlackBox.h"

int main(int argc, char **argv)
{
	if ( argc==1 ) {fprintf(stderr, "how about an argument?\n"); exit(1);}
	DLGStringInput in(argv[1]);		/* create an input stream for DLG */
	DLGLexer scan(&in);				/* create scanner reading from stdin */
	ANTLRTokenBuffer pipe(&scan);	/* make pipe between lexer & parser */
	ANTLRTokenPtr aToken = new ANTLRToken;
	scan.setToken(mytoken(aToken));
	Expr parser(&pipe);		/* create parser of type Expr hooked to scanner */
	parser.init();			/* init the parser; prime lookahead etc... */
	parser.e();				/* start parsing at rule 'e' of that parser */

	return 0;
}
>>

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

#tokclass My { IDENTIFIER NUMBER }

class Expr {				/* Define a grammar class */

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

}

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