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 (78 lines) | stat: -rw-r--r-- 1,384 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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<Lexer, Include, ANTLRToken> p(stdin);
	p.parser()->input();
	return 0;
}
>>

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

#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		<<printf("%s\n", $1->getText());>>
		|	STRING		<<printf("%s\n", $1->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]+"	<<skip();>>

data:	"0x[0-9]+" ":" "0x[0-9]+"
		<<printf("data %s\n", $1->getText());>>
	;

}

#lexclass START

#token STRING	"\" [a-zA-Z0-9_.,\ \t]+ \""
#token NUMBER	"[0-9]+"