aboutsummaryrefslogtreecommitdiff
path: root/backendC/CleanCompilerSources/comparser_2.c
blob: 3a257aeb8932bfa55aca3995b125edf10b5df72d (plain) (blame)
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
/*
		Ronny Wichers Schreur
		University of Nijmegen
*/

# pragma segment comparser
# ifdef THINK_C
# pragma options (!macsbug_names)
# endif

# undef	PRINT_RULES_AFTER_PARSING
# undef	STOP_AFTER_PARSING

# undef H

# include	"types.t"
# include	"syntaxtr.t"

# include	"comsupport.h"
# include	"scanner.h"
# include	"sizes.h"
# include	"checker.h"
# include	"statesgen.h"
# include	"comparser.h"
# include	"buildtree.h"
# include	"comprehensions.h"
# include	"settings.h"
# include	"checksupport.h"

# ifdef PRINT_RULES_AFTER_PARSING
# include "dbprint.h"
# endif

static void	*gSymbIdEnv;

static IdentP	gBasicTypeIdents [Nr_Of_Basic_Types], gIfIdent;

static SymbolP
NewPredefinedTypeSymbol (SymbKind symbolKind, KeywordKind keyWordKind, IdentP *identPtr)
{
	char		*symbolName;
	SymbolP		symbol;
	IdentP		ident;

	symbolName	= ReservedWords [keyWordKind];
	symbol		= NewSymbol (symbolKind);

	ident				= PutStringInHashTable (symbolName, TypeSymbolIdTable);
	ident->ident_symbol	= symbol;
	ident->ident_environ= (char*)gSymbIdEnv;
	*identPtr			= ident;

	return (symbol);
} /* NewPredefinedSymbol */

static SymbolP
NewPredefinedSymbol (SymbKind symbolKind, KeywordKind keyWordKind, IdentP *identPtr)
{
	char		*symbolName;
	SymbolP		symbol;
	IdentP		ident;

	symbolName	= ReservedWords [keyWordKind];
	symbol		= NewSymbol (symbolKind);

	ident				= PutStringInHashTable (symbolName, SymbolIdTable);
	ident->ident_symbol	= symbol;
	ident->ident_environ= (char*)gSymbIdEnv;
	*identPtr			= ident;

	return (symbol);
} /* NewPredefinedSymbol */

void
InitParser (void)
{
	int		i;

	ScanInitialise ();
#ifndef CLEAN2
	MakeErrorStructures ();

	gCurrentContext			= NULL;
	gNodeIdEnv				= (char *) 1;
	/* RWS, hack to avoid name space confusion bug */
	gAttributeEnv			= (char *) (1 << 16);

	gAttrVarAdmin = NULL;
#endif
	for (i = 0; i < MaxNodeArity; i++)
	{	SelectSymbols	 [i] = NULL;
		TupleTypeSymbols [i] = NULL;
	}

	BasicTypeSymbols [int_type]		= NewPredefinedTypeSymbol (int_type, intsym, & gBasicTypeIdents [int_type]);
	BasicTypeSymbols [bool_type]	= NewPredefinedTypeSymbol (bool_type, boolsym, & gBasicTypeIdents [bool_type]);
	BasicTypeSymbols [char_type]	= NewPredefinedTypeSymbol (char_type, charsym, & gBasicTypeIdents [char_type]);
	BasicTypeSymbols [string_type]	= NewPredefinedTypeSymbol (string_type, stringsym, & gBasicTypeIdents [string_type]);
	BasicTypeSymbols [real_type]	= NewPredefinedTypeSymbol (real_type, realsym, & gBasicTypeIdents [real_type]);
	BasicTypeSymbols [file_type]	= NewPredefinedTypeSymbol (file_type, filesym, & gBasicTypeIdents [file_type]);
	BasicTypeSymbols [world_type]	= NewPredefinedTypeSymbol (world_type, worldsym, & gBasicTypeIdents [world_type]);

	ArraySymbols [LazyArrayInstance]	= NewPredefinedTypeSymbol (array_type, arraysym, &gArrayIdents [LazyArrayInstance]);
	ArraySymbols [StrictArrayInstance]	= NewPredefinedTypeSymbol (strict_array_type, strictarraysym, &gArrayIdents [StrictArrayInstance]);
	ArraySymbols [UnboxedArrayInstance] = NewPredefinedTypeSymbol (unboxed_array_type, unboxedarraysym, &gArrayIdents [UnboxedArrayInstance]);
	
	BasicTypeSymbols [procid_type]	= NewPredefinedTypeSymbol (procid_type, procidsym, & gBasicTypeIdents [procid_type]);

	IfSymbol		= NewPredefinedSymbol (if_symb, ifsym, &gIfIdent);
	BasicTypeSymbols [redid_type]	= NewPredefinedTypeSymbol (procid_type, procidsym, & gBasicTypeIdents [redid_type]);
	ApplyTypeSymbol	= NewSymbol (fun_type);

	TrueSymbol		= NewSymbol (bool_denot);
	TrueSymbol->symb_bool = True;
	FalseSymbol		= NewSymbol (bool_denot);
	FalseSymbol->symb_bool = False;

	TupleSymbol		= NewSymbol (tuple_symb);
	ListSymbol		= NewSymbol (list_type);
	ConsSymbol		= NewSymbol (cons_symb);
	NilSymbol		= NewSymbol (nil_symb);
	ApplySymbol		= NewSymbol (apply_symb);
	FailSymbol		= NewSymbol (fail_symb);
	AllSymbol		= NewSymbol (all_symb);
	EmptyTypeSymbol	= NewSymbol (empty_type);

	InitialiseEnumFunctionIds ();

	clear_p_at_node_tree();
} /* InitParser */