Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2024_compilation_bauquin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BAUQUIN Niels
2024_compilation_bauquin
Commits
68ab49e9
Commit
68ab49e9
authored
1 year ago
by
BAUQUIN Niels
Browse files
Options
Downloads
Patches
Plain Diff
dfg
parent
086b4789
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ts/Sa2ts.java
+45
-43
45 additions, 43 deletions
src/ts/Sa2ts.java
with
45 additions
and
43 deletions
src/ts/Sa2ts.java
+
45
−
43
View file @
68ab49e9
...
@@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
...
@@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
@Override
public
Void
visit
(
SaDecTab
node
)
throws
Exception
{
public
Void
visit
(
SaDecTab
node
)
throws
Exception
{
String
nomTableau
=
node
.
getNom
();
String
idTab
=
node
.
getNom
();
Type
typeTableau
=
node
.
getType
();
Type
typeTab
=
node
.
getType
();
int
tailleTableau
=
node
.
getTaille
();
int
tailleTab
=
node
.
getTaille
();
System
.
out
.
println
(
node
);
if
(
context
==
Context
.
GLOBAL
)
{
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nomTableau
)
!=
null
)
{
if
(
tableGlobale
.
getVar
(
idTab
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"Le tableau "
+
nomTableau
+
" est déjà défini."
);
throw
new
ErrorException
(
Error
.
TS
,
"Le tableau "
+
idTab
+
" est déjà défini."
);
}
}
tableGlobale
.
addTab
(
nomTableau
,
typeTab
leau
,
tailleTab
leau
);
node
.
tsItem
=
tableGlobale
.
addTab
(
idTab
,
typeTab
,
tailleTab
);
}
}
return
null
;
return
null
;
}
}
@Override
@Override
public
Void
visit
(
SaDecFonc
node
)
throws
Exception
{
public
Void
visit
(
SaDecFonc
node
)
throws
Exception
{
String
nomFonction
=
node
.
getNom
();
String
idFct
=
node
.
getNom
();
SaLDecVar
parameters
=
node
.
getParametres
();
SaLDecVar
parameters
=
node
.
getParametres
();
SaLDecVar
variable
=
node
.
getVariable
();
SaLDecVar
variable
=
node
.
getVariable
();
SaInst
corps
=
node
.
getCorps
();
SaInst
corps
=
node
.
getCorps
();
if
(
tableGlobale
.
getFct
(
nomFonction
)
!=
null
)
{
if
(
tableGlobale
.
getFct
(
idFct
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
nomFonction
+
" est déjà définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
idFct
+
" est déjà définie."
);
}
}
Ts
table
=
new
Ts
();
Ts
table
=
new
Ts
();
tableLocaleCourante
=
table
;
tableLocaleCourante
=
table
;
int
param
=
0
;
int
nbArgs
=
0
;
if
(
parameters
!=
null
)
{
if
(
parameters
!=
null
)
{
context
=
Context
.
PARAM
;
context
=
Context
.
PARAM
;
parameters
.
accept
(
this
);
parameters
.
accept
(
this
);
param
=
parameters
.
length
();
nbArgs
=
parameters
.
length
();
}
}
if
(
variable
!=
null
)
{
if
(
variable
!=
null
)
{
context
=
Context
.
LOCAL
;
context
=
Context
.
LOCAL
;
variable
.
accept
(
this
);
variable
.
accept
(
this
);
}
}
node
.
tsItem
=
tableGlobale
.
addFct
(
nomFonction
,
node
.
getTypeRetour
(),
param
,
table
,
node
);
node
.
tsItem
=
tableGlobale
.
addFct
(
idFct
,
node
.
getTypeRetour
(),
nbArgs
,
table
,
node
);
if
(
corps
!=
null
)
{
if
(
corps
!=
null
)
{
context
=
Context
.
LOCAL
;
context
=
Context
.
LOCAL
;
corps
.
accept
(
this
);
corps
.
accept
(
this
);
...
@@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
...
@@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
@Override
public
Void
visit
(
SaDecVar
node
)
throws
Exception
{
public
Void
visit
(
SaDecVar
node
)
throws
Exception
{
String
nom
Var
=
node
.
getNom
();
String
id
Var
=
node
.
getNom
();
Type
typeVar
=
node
.
getType
();
Type
typeVar
=
node
.
getType
();
if
(
context
==
Context
.
LOCAL
)
{
if
(
context
==
Context
.
LOCAL
)
{
if
(
tableLocaleCourante
.
getVar
(
nom
Var
)
!=
null
)
{
if
(
tableLocaleCourante
.
getVar
(
id
Var
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" est déjà définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" est déjà définie
dans la fonction
."
);
}
}
node
.
setTsItem
(
tableLocaleCourante
.
addVar
(
nom
Var
,
typeVar
));
node
.
setTsItem
(
tableLocaleCourante
.
addVar
(
id
Var
,
typeVar
));
}
else
if
(
context
==
Context
.
PARAM
)
{
}
else
if
(
context
==
Context
.
PARAM
)
{
if
(
tableLocaleCourante
.
getVar
(
nom
Var
)
!=
null
)
{
if
(
tableLocaleCourante
.
getVar
(
id
Var
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" est déjà définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" est déjà définie
dans les parametres
."
);
}
}
node
.
setTsItem
(
tableLocaleCourante
.
addParam
(
nom
Var
,
typeVar
));
node
.
setTsItem
(
tableLocaleCourante
.
addParam
(
id
Var
,
typeVar
));
}
else
if
(
context
==
Context
.
GLOBAL
)
{
}
else
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nom
Var
)
!=
null
)
{
if
(
tableGlobale
.
getVar
(
id
Var
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" est déjà définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" est déjà définie
dans la table globale
."
);
}
}
node
.
setTsItem
(
tableGlobale
.
addVar
(
nom
Var
,
typeVar
));
node
.
setTsItem
(
tableGlobale
.
addVar
(
id
Var
,
typeVar
));
}
}
return
null
;
return
null
;
}
}
@Override
@Override
public
Void
visit
(
SaVarSimple
node
)
throws
Exception
{
public
Void
visit
(
SaVarSimple
node
)
throws
Exception
{
String
nom
Var
=
node
.
getNom
();
String
id
Var
=
node
.
getNom
();
TsItemVarSimple
varSimple
=
node
.
getTsItem
();
TsItemVarSimple
varSimple
=
node
.
getTsItem
();
if
(
context
==
Context
.
LOCAL
)
{
if
(
context
==
Context
.
LOCAL
)
{
if
(
tableLocaleCourante
.
getVar
(
nom
Var
)
==
null
&&
tableGlobale
.
getVar
(
nom
Var
)
==
null
)
{
if
(
tableLocaleCourante
.
getVar
(
id
Var
)
==
null
&&
tableGlobale
.
getVar
(
id
Var
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" n'est pas définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" n'est pas définie."
);
}
}
if
(
tableLocaleCourante
.
getVar
(
nom
Var
)
!=
null
)
{
if
(
tableLocaleCourante
.
getVar
(
id
Var
)
!=
null
)
{
node
.
tsItem
=
(
TsItemVarSimple
)
tableLocaleCourante
.
getVar
(
nom
Var
);
node
.
tsItem
=
(
TsItemVarSimple
)
tableLocaleCourante
.
getVar
(
id
Var
);
}
else
{
}
else
{
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
nom
Var
);
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
id
Var
);
}
}
}
else
if
(
context
==
Context
.
PARAM
)
{
}
else
if
(
context
==
Context
.
PARAM
)
{
if
(
tableLocaleCourante
.
getVar
(
nom
Var
)
==
null
)
{
if
(
tableLocaleCourante
.
getVar
(
id
Var
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" n'est pas définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" n'est pas définie."
);
}
}
}
else
if
(
context
==
Context
.
GLOBAL
)
{
}
else
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nom
Var
)
==
null
||
varSimple
.
getTaille
()
>
1
)
{
if
(
tableGlobale
.
getVar
(
id
Var
)
==
null
||
varSimple
.
getTaille
()
>
1
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nom
Var
+
" n'est pas définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
id
Var
+
" n'est pas définie."
);
}
}
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
nom
Var
);
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
id
Var
);
}
}
return
null
;
return
null
;
}
}
@Override
@Override
public
Void
visit
(
SaAppel
node
)
throws
Exception
{
public
Void
visit
(
SaAppel
node
)
throws
Exception
{
String
nomFonction
=
node
.
getNom
();
String
idFct
=
node
.
getNom
();
SaLExp
arguments
=
node
.
getArguments
();
SaLExp
arguments
=
node
.
getArguments
();
int
a
rgs
=
0
;
int
nbA
rgs
=
0
;
if
(
arguments
!=
null
)
{
if
(
arguments
!=
null
)
{
arguments
.
accept
(
this
);
arguments
.
accept
(
this
);
a
rgs
=
arguments
.
length
();
nbA
rgs
=
arguments
.
length
();
}
}
if
(
tableGlobale
.
getFct
(
nomFonction
)
==
null
)
{
if
(
tableGlobale
.
getFct
(
idFct
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
nomFonction
+
" n'est pas définie."
);
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
idFct
+
" n'est pas définie."
);
}
}
if
(
this
.
tableGlobale
.
getFct
(
nomFonction
).
getNbArgs
()
!=
a
rgs
)
{
if
(
this
.
tableGlobale
.
getFct
(
idFct
).
getNbArgs
()
!=
nbA
rgs
)
{
throw
new
ErrorException
(
Error
.
TS
,
"Le nombre d'arguments est incorrect."
throw
new
ErrorException
(
Error
.
TS
,
"Le nombre d'arguments est incorrect."
+
this
.
tableGlobale
.
getFct
(
nomFonction
).
getNbArgs
()
+
" requis."
);
+
this
.
tableGlobale
.
getFct
(
idFct
).
getNbArgs
()
+
" requis."
);
}
}
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
...
@@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
...
@@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override
@Override
public
Void
visit
(
SaVarIndicee
node
)
throws
Exception
{
public
Void
visit
(
SaVarIndicee
node
)
throws
Exception
{
String
nom
Var
=
node
.
getNom
();
String
id
Var
=
node
.
getNom
();
SaExp
indice
=
node
.
getIndice
();
SaExp
indice
=
node
.
getIndice
();
if
(
tableGlobale
.
getVar
(
nom
Var
)
==
null
&&
tableGlobale
.
getVar
(
nom
Var
).
getTaille
()
==
1
)
if
(
tableGlobale
.
getVar
(
id
Var
)
==
null
&&
tableGlobale
.
getVar
(
id
Var
).
getTaille
()
==
1
)
throw
new
ErrorException
(
Error
.
TS
,
"indice "
+
nom
Var
+
" incorrect."
);
throw
new
ErrorException
(
Error
.
TS
,
"indice "
+
id
Var
+
" incorrect."
);
node
.
tsItem
=
tableGlobale
.
getVar
(
node
.
getNom
());
node
.
tsItem
=
tableGlobale
.
getVar
(
node
.
getNom
());
indice
.
accept
(
this
);
indice
.
accept
(
this
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment