Bonjour
je veux savoir si je peux ajouter une declaration des directives juste aprés le nom de l'unité
par exemple
sachant qu'elle est optionnelleCode:
1
2
3Unit MainForm PLATFORM= expression LIBRARY;
merci de me repondre
Version imprimable
Bonjour
je veux savoir si je peux ajouter une declaration des directives juste aprés le nom de l'unité
par exemple
sachant qu'elle est optionnelleCode:
1
2
3Unit MainForm PLATFORM= expression LIBRARY;
merci de me repondre
As tu essayé ?!
Citation:
Envoyé par aide delphi
merci pour votre reponse
enfin, je developpe pas avec delphi mais j'utilise la grammaire delphi pour developper un parseur (parser) delphi, donc je dois comprendre toute la syntaxe delphi
j'ai trouvé 2 cas différent dans la declaration de l'unité
donc ma question se pose sur la partie (=Expression) ? es-ce qu'on peut l'ajouter ou non?Code:
1
2
3
4
5
6
7 1er cas : Unit unit 1 Library Platform; 2eme cas: Unit unit1 Library Platform = expression;
sachant qu'elle est en opitionnelle dans ma grammaire !!! :roll:
Merci
en tout cas ca ne compile pas sur mon delphi 7 (';' attendu mais '=' trouvé)
De plus, l'aide de D7 dit :Citation:
Les directives platform et library ne spécifient pas la plate-forme ni la bibliothèque. Si votre but consiste à écrire du code indépendant de la plate-forme, vous n'avez pas à savoir à quelle plate-forme un symbole est spécifique ; il suffit que le symbole soit marqué comme spécifique à une certaine plate-forme pour vous informer d'éventuels problèmes de portabilité.
encore merci pour votre reponse
mais ça peut marcher avec les nouvelles version de delphi, ou peut etre avec le delphi.net , non??!!
Ben, pour ma grammaire, elle doit etre généralisé (marche avec toutes les version de delphi)
Merci
celle de D7 est la suivante :
Code:
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 But -> (Programme | Paquet | Bibliothèque | Unité) Programme -> [PROGRAM Ident ['(' ListeIdent ')'] ';'] BlocProgramme '.' Unité -> UNIT Ident [DirectivePortabilité] ';' SectionInterface SectionImplémentation SectionInit '.' Paquet -> PACKAGE Ident ';' [ClauseRequires] [ClauseContains] END '.' Bibliothèque -> LIBRARY Ident ';' BlocProgramme '.' BlocProgramme -> [ClauseUses] Bloc ClauseUses -> USES ListeIdent ';' DirectivePortabilité -> platform -> deprecated -> library SectionInterface -> INTERFACE [ClauseUses] [DéclInterface]... DéclInterface -> SectionConst -> SectionType -> SectionVar -> EnTêteExportation EnTêteExportation -> EnTêteProcédure ';' [Directive] -> EnTêteFonction ';' [Directive] SectionImplémentation -> IMPLEMENTATION [ClauseUses] [SectionDécl]... [InstructionExports]... Bloc -> [SectionDécl] [InstructionExports]... InstructionComposée [InstructionExports]... InstructionExports-> EXPORTS ElémentExports [, ElémentExports]... ElémentExports-> Ident [NOM|INDICE "'" ExprConst "'"] [INDICE|NOM "'" ExprConst "'"] SectionDécl -> SectionDéclLabel -> SectionConst -> SectionType -> SectionVar -> SectionDéclProc SectionDéclLabel -> LABEL IdentLabel SectionConst -> CONST (DéclConstant ';')... DéclConstant -> Ident '=' ExprConst [DirectivePortabilité] -> Ident ':' IdentType '=' ConstanteTypée [DirectivePortabilité] SectionType -> TYPE (DéclType ';'). DéclType -> Ident '=' [TYPE] Type [DirectivePortabilité] -> Ident '=' [TYPE] TypeRestreint [DirectivePortabilité] ConstanteTypée -> (ExprConst | ConstanteTableau | ConstanteEnregistrement) ConstanteTableau -> '(' ConstanteTypée ',' ')' ConstanteEnregistrement -> '(' ConstChampEnreg ';'... ')' ConstChampEnreg -> Ident ':' ConstanteTypée Type -> IdentType -> TypeSimple -> TypeStruc -> TypePointeur -> TypeChaîne -> TypeProcédure -> TypeVariant -> TypeRefClass TypeRestreint -> TypeObjet -> TypeClasse -> TypeInterface TypeRefClass -> CLASS OF IdentType TypeSimple -> (TypeScalaire | TypeRéel) TypeRéel -> REAL48 -> REAL -> SINGLE -> DOUBLE -> EXTENDED -> CURRENCY -> COMP TypeScalaire -> (TypeIntervalle | TypeEnum | IdentScalaire) IdentScalaire -> SHORTINT -> SMALLINT -> INTEGER -> BYTE -> LONGINT -> INT64 -> WORD -> BOOLEAN -> CHAR -> WIDECHAR -> LONGWORD -> PCHAR TypeVariant -> VARIANT -> OLEVARIANT TypeIntervalle -> ExprConst '..' ExprConst TypeEnum -> '(' ElémentTypeEnum ','... ')' ElémentTypeEnum -> Ident [ '=' ExprConst ] TypeChaîne -> STRING -> ANSISTRING -> WIDESTRING -> STRING '[' ExprConst ']' TypeStruc -> [PACKED] (TypeTableau | TypeEnsemble | TypeFichier | TypeEnreg [PACKED]) TypeTableau -> ARRAY ['[' TypeScalaire ','... ']'] OF Type [DirectivePortabilité] TypeEnreg -> RECORD [ListeChamp] END [DirectivePortabilité] ListeChamp -> DéclChamp ';'... [SectionVariable] [';'] DéclChamp -> ListeIdent ':' Type [DirectivePortabilité] SectionVariant -> CASE [Ident ':'] IdentType OF VariantEnreg ';'... VariantEnreg -> ExprConst ','... ':' '(' [ListeChamp] ')' TypeEnsemble -> SET OF TypeScalaire [DirectivePortabilité] TypeFichier -> FILE OF IdentType [DirectivePortabilité] TypePointeur -> '^' IdentType [DirectivePortabilité] TypeProcédure -> (EnTêteProcédure | EnTêteFonction) [OF OBJECT] SectionVar -> VAR (DéclVar ';')... DéclVar Sur Windows -> ListeIdent ':' Type [(ABSOLUTE (Ident | ExprConst)) | '=' ExprConst] [DirectivePortabilité] Sur Linux -> ListeIdent ':' Type [ABSOLUTE (Ident) | '=' ExprConst] [DirectivePortabilité] Expression -> ExpressionSimple [OpRel ExpressionSimple]... ExpressionSimple -> ['+' | '-'] Terme [OpAdd Terme]... Terme -> Facteur [OpMul Facteur]... Facteur -> Désignateur ['(' ListeExpr ')'] -> '@' Désignateur -> Nombre -> Chaîne -> NIL -> '(' Expression ')' -> NOT Facteur -> ConstructeurEnsemble -> IdentType '(' Expression ')' OpRel -> '>' -> '<' -> '<=' -> '>=' -> '<>' -> IN -> IS -> AS OpAdd -> '+' -> '-' -> OR -> XOR OpMul -> '*' -> '/' -> DIV -> MOD -> AND -> SHL -> SHR Désignateur -> IdentQualif ['.' Ident | '[' ListeExpr ']' | '^']... ConstructeurEnsemble -> '[' [ElémentEnsemble ','...] ']' ElémentEnsemble -> Expression ['..' Expression] ListeExpr -> Expression ','... Instruction -> [IdentLabel ':'] [InstructionSimple | InstructionStructurée] ListeInstructions -> Instruction ';' InstructionSimple -> Désignateur ['(' [ListeExpr] ')'] -> Désignateur ':=' Expression -> INHERITED -> GOTO IdentLabel InstructionStructurée -> InstructionComposée -> InstructionCondition -> InstructionBoucle -> InstructionWith -> InstructionTryExcept -> InstructionTryFinally -> InstructionRaise -> InstructionAssembleur InstructionComposée -> BEGIN ListeInstructions END InstructionCondition -> InstructionIf -> InstructionCase InstructionIf -> IF Expression THEN Instruction [ELSE Instruction] InstructionCase -> CASE Expression OF SélecteurCase ';'... [ELSE ListeInstructions] [';'] END SélecteurCase -> LabelCase ','... ':' Instruction LabelCase -> ExprConst ['..' ExprConst] InstructionBoucle -> InstructionRepeat -> InstructionWhile -> InstructionFor InstructionRepeat -> REPEAT Instruction UNTIL Expression InstructionWhile -> WHILE Expression DO Instruction InstructionFor -> FOR IdentQualif ':=' Expression (TO | DOWNTO) Expression DO Instruction InstructionWith -> WITH ListeIdent DO Instruction InstructionTryExcept -> TRY Instruction... EXCEPT BlocException END BlocException -> [ON [Ident ':'] IDType DO Instruction]... [ELSE Instruction...] InstructionTryFinally -> TRY Instruction FINALLY Instruction END InstructionRaise -> RAISE [objet] [AT adresse] InstructionAssembleur -> ASM -> <langageassemblage> -> END SecDéclProcédure -> DéclProcédure -> DéclFonction DéclProcédure -> EnTêteProcédure ';' [Directive] [DirectivePortabilité] Bloc ';' DéclFonction -> EnTêteFonction ';' [Directive] [DirectivePortabilité] Bloc ';' EnTêteFonction-> FUNCTION Ident [ParamètresFormels] ':' (TypeSimple | STRING) EnTêteProcédure -> PROCEDURE Ident [ParamètresFormels] ParamètresFormels -> '(' ParamètreFormel ';'... ')' ParamètreFormel -> [VAR | CONST | OUT] Paramètre Paramètre -> ListeIdent [':' ([ARRAY OF] TypeSimple | STRING | FILE)] -> Ident ':' TypeSimple '=' ExprConst Directive -> CDECL -> REGISTER -> DYNAMIC -> VIRTUAL -> EXPORT -> EXTERNAL -> NEAR -> FAR -> FORWARD -> MESSAGE ConstExpr -> OVERRIDE -> OVERLOAD -> PASCAL -> REINTRODUCE -> SAFECALL -> STDCALL -> VARARGS -> LOCAL -> ABSTRACT TypeObjet -> OBJECT [HéritageObjet] [ListeChampObjet] [ListeMéthode] END HéritageObjet -> '(' IdentQualif ')' ListeMéthode -> (EnTêteMéthode [';' VIRTUAL]) ';'... EnTêteMéthode -> EnTêteProcédure -> EnTêteFonction -> EnTêteConstructeur -> EnTêteDestructeur EnTêteConstructeur -> CONSTRUCTOR Ident [ParamètresFormels] EnTêteDestructeur -> DESTRUCTOR Ident [ParamètresFormels] ListeChampObjet -> (ListeIdent ':' Type) ';' SectionInit -> INITIALIZATION ListeInstructions [FINALIZATION ListeInstructions] END -> BEGIN ListeInstructions END -> END TypeClasse -> CLASS [HéritageClasse] [VisibilitéClasse] [ListeChampClasse] [ListeMéthodeClasse] [ListePropriétéClasse] END HéritageClasse -> '(' ListeIdent ')' VisibilitéClasse -> [PUBLIC | PROTECTED | PRIVATE | PUBLISHED] ListeChampClasse -> (VisibilitéClasse ListeChampObjet) ';'... ListeMéthodeClasse -> (VisibilitéClasse ListeMéthode) ';'... ListePropriétéClasse -> (VisibilitéClasse ListePropriété ';')... ListePropriété -> PROPERTY Ident [InterfacePropriété] [SpécificateursPropriété] [DirectivePortabilité] InterfacePropriété -> [ListesParamètrePropriété] ':' Ident ListesParamètrePropriété -> '[' (ListeIdent ':' IdentType) ';'... ']' SpécificateursPropriété -> [INDEX ExprConst] [READ Ident] [WRITE Ident] [STORED (Ident | Constante)] [(DEFAULT ExprConst) | NODEFAULT] [IMPLEMENTS IdentType] TypeInterface -> INTERFACE [HéritageInterface] [ListeMéthodeClasse] [ListePropriétéClasse] ... END HéritageInterface -> '(' ListeIdent ')' ClauseRequires -> REQUIRES ListeIdent... ';' ClauseContains -> CONTAINS ListeIdent... ';' ListeIdent -> Ident ','... IdentQualif -> [IdentUnité '.'] Ident IdentType -> [IdentUnité '.'] <identificateur de type> Ident -> <identificateur> ExprConst -> <expression constante> IdentUnité -> <identificateur d'unité> IdentLabel -> <identificateur de label> Nombre -> <nombre> Chaîne -> <chaîne>
Merci pour votre aide ;)
bonjour
j'ai une question concernant la declaration d'une fonction ou procedure
je veux savoir l'utilité des directives, et localDeclaration dans la declaration des fonction et procedureCode:
1
2
3
4
5
6
7 function functionName(parameterList): returnType; directives; localDeclarations; begin statements end;
merci de me repondre
Les directives sont très variées, elles peuvent contrôler le comportement des méthodes d'objets (virtual, overload, override, etc...), seulement informatives (deprecated, platform) ou encore spécifier la convention d'appel (cdecl, register, etc...).
localDeclaration c'est encore pire :D
C'est là que sont déclarées toutes les variables locales mais pas seulement. On peut faire bien plus, comme déclarer des constantes locales, des types locaux voire carrément des procédures/fonctions locales.
Sincèrement : bonne chance ! ;)
Le langage Delphi est très difficile à exprimer avec un grammaire formelle, à cause d'un certain nombre d'ambiguïtés syntaxiques qui sont en fait levées par une analyse sémantique !
Exemple, la déclaration d'une constante typée :
Pour savoir comment parser ces trois valeurs de constantes, il faut savoir que Integer est un entier simple, que TSmallArray est un tableau, et que TPoint est un record.Code:
1
2
3
4
5
6
7 type TSmallArray = array[0..2] of Integer; const IntConst: Integer = (5 + 3); TabConst: TSmallArray = (1, 2, 3); RecordConst: TPoint = (X: 1; Y: 2);
Il y en a d'autres du style :mouarf:
C'est pour cela que la grande majorité des parsers Delphi sont écrits à la main.
Personnellement, pour mon projet Sepi, j'utilise une grammaire presque LL(1), avec des "extensions" à moi :
- Possibilité de déterminer quel choix prendre sur base d'informations sémantiques en cas de conflits syntaxiques ;
- Possibilité de "tenter" un choix, et de revenir en arrière s'il s'avère être erroné.
Tu pourras trouver ma grammaire là :
http://sepi.svn.sourceforge.net/view...ra?view=markup
Cette grammaire ne passe pas encore sur tout, mais mine de rien elle peut parser la quasi totalité de la RTL et de la VCL standard de Delphi :)
Merci pour votre reponse
enfin j'ai trouvé une personne qui comprend que la grammaire du delphi est vraiment compliqué
en fait vous travaillez avec quel language ?, moi avec javaCC j'ai trouvé une grammaire delphi sous gold parser si vous l'avez besoin
http://www.devincook.com/goldparser/grammars/index.htm
cordialement