File: parser.y

package info (click to toggle)
doc%2B%2B 3.2-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 1,844 kB
  • ctags: 1,925
  • sloc: cpp: 16,762; lex: 2,938; makefile: 278; java: 273; yacc: 139; perl: 20; sh: 17
file content (207 lines) | stat: -rw-r--r-- 4,877 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*************************************************************************

    DOC++, a C++ (and C) documentation system for LaTeX and HTML

	    Copyright (C) 1996  Roland Wunderling,
				Malte Zoeckler


    DOC++ is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation. This program
    is distributed WITHOUT ANY WARRANTY; without even the implied
    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the GNU General Public License for more details.

    If you intend to use DOC++ commercially on a regular basis you
    must contact the authors for an appropriate donation.

 *************************************************************************/


%{
/*
 *	includes
 */
#include <stdio.h>
#include <iostream.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>

#include "doc.h"
int yyerror(const char *s);

void
dumpType( Entry* current )
{
    cerr << " --- type became `" << (const char*)current->type << "'\n" ;
}

/*
 *	imports
 */
extern int	yyLastLine ;
extern int	yyLineNr ;
extern char	yyFileName[] ;
extern McString	yyText ;

extern int	yylex();
extern void	restart() ;
extern void	done() ;
extern void	parseMessage( const char* str, const char* str2 ) ;
extern void	strip( McString& dest,const char* source ) ;

/*
 *	defines
 */
#define isalpha(ch)	(( ch=='_' || ch=='~' || ch=='[' || ch==']' || \
			   ('a'<=ch && ch<='z') || ('A'<=ch && ch<='Z') ))
#define isalphanum(ch)	(( isalpha(ch) || ('0'<=ch && ch<='9') ))


/*
 *	statics
 */
static int	protection ;	/* current protection status */

/*
static C_String*	name ;
static C_String*	memo ;
static C_String*	doc ;
static C_String*	program ;
*/

extern Entry*	current ;

%}
%token	CHAR

%token	SEPARATOR
%token	STRUCT
%token	UNION
%token	ENUM

%token	';'
%token	CODE
%token	NAME
%token	CONST
%token	CLASS
%token	MACRO
%token	ROUND
%token	CURLY

%%
Start:		
	    |	Start GetEntry
	    |	Start error	{ fprintf( stderr,
					   "ERROR before line %d of file %s: `%s'\n",
					   yyLineNr, yyFileName,
					   (const char*)yyText ) ;
				  done() ;
				}
	    ;

GetEntry:	FillType GetIt	{ done() ; }
	    ;

FillType:	
	    |	FillType CONST	{ current->name += yyText ; }
	    |	FillType CODE	{ current->name += yyText ; }
	    |	FillType NAME	{ current->type += current->name ;
				  current->name = yyText ;
	    			}
	    ;

GetIt:		Function	{ current->section = FUNCTION_SEC ;
				  parseMessage( "found function:  ", current->name ) ;
	    			}
	    |	Variable	{ current->section = VARIABLE_SEC ;
				  parseMessage( "found variable:  ", current->name ) ;
	    			}
	    |	Struct		{ current->section = CLASS_SEC ;
				  parseMessage( "found class:     ", current->name ) ;
	    			}
	    |	Class		{ current->section = CLASS_SEC ;
				  parseMessage( "found class:     ", current->name ) ;
	    			}
	    |	Enum		{ current->section = UNION_SEC ;
				  parseMessage( "found union:     ", current->name ) ;
	    			}
	    |	Union		{ current->section = UNION_SEC ;
				  parseMessage( "found union:     ", current->name ) ;
	    			}
	    |	Macro		{ current->section = MACRO_SEC ;
				  done() ;
				  parseMessage( "found macro:     ", current->name ) ;
	    			}
	    ;

Function:	ROUND		{ current->program = yyText ; }
		OptStuff
		FuncEnd
	    ;

OptStuff:
	    |	CODE
	    |	CONST
	    ;

FuncEnd:	';'
	    |	SEPARATOR
	    |	CURLY
	    ;

Struct:		STRUCT NAME	{ current->type += current->name ;
				  current->type += " class" ;
				  current->name  = yyText ; }
		OptBases
		CURLY		{ current->program = yyText ; }
	    ;

Class:		CLASS NAME	{ current->type += current->name ;
				  current->type += " class" ;
				  current->name  = yyText ; }
		OptBases
		CURLY		{ current->program = yyText ; }
	    ;

OptBases:
	    |	OptBases CODE		{ current->args += yyText ; }
	    |	OptBases SEPARATOR	{ current->args += yyText ; }
	    |	OptBases NAME		{ current->args += yyText ; }
	    ;

Macro:		MACRO NAME	{ current->type = "\\#define" ;
				  current->name = yyText ; }
		OptArgs
	    ;

OptArgs:
	    |	ROUND		{ current->program = yyText ; }
	    ;

Variable:	';'
	    |	SEPARATOR
	    ;

Enum:		ENUM NAME	{ current->type += current->name ;
				  current->type += " enum" ;
				  current->name  = yyText ; }
		OptBases
		CURLY		{ current->program = yyText ; }
	    ;

Union:		UNION NAME	{ current->type += current->name ;
				  current->type += " enum" ;
				  current->name  = yyText ; }
		OptBases
		CURLY		{ current->program = yyText ; }
	    ;

%%
#ifndef	NDEBUG
int	yydebug() { return 1 ;}
#endif	//NDEBUG

int	yyerror(const char *) { return 1 ;}