Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Technique de compilation - TP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lucien.noel
Technique de compilation - TP
Commits
becd94b9
Commit
becd94b9
authored
2 years ago
by
lucien.noel
Browse files
Options
Downloads
Patches
Plain Diff
analyse de == corrigée
parent
211e33f5
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
Visitors/SemanticAnalyzer.java
+27
-14
27 additions, 14 deletions
Visitors/SemanticAnalyzer.java
with
27 additions
and
14 deletions
Visitors/SemanticAnalyzer.java
+
27
−
14
View file @
becd94b9
...
...
@@ -124,20 +124,33 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
//test si la valeur à gauche et à droite du == sont du même type
// if(node.getGauche() instanceof Vrai || node.getGauche() instanceof Faux || (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Booleen)){
// if(!(node.getDroite() instanceof Vrai || node.getDroite() instanceof Faux || (node.getDroite() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getDroite()).getNom())).getType() instanceof Booleen))){
// throw new RuntimeException("classe invalide : "+((Parentheses)node.getDroite()).getExpression().getClass());
// // throw new RuntimeException("Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !");
// }
// }else if(node.getGauche() instanceof Nombre || (node.getGauche() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getGauche()).getNom())).getType() instanceof Entier)){
// if(!(node.getDroite() instanceof Nombre || (node.getDroite() instanceof Idf && TDS.getInstance().identifier(new Entree(((Idf)node.getDroite()).getNom())).getType() instanceof Entier))){
// throw new RuntimeException("Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !");
// }
// }else{
// throw new RuntimeException("Normalement cette exception ne devrait jamais apparaitre mais on ne sait jamais");
// }
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)?
((
Parentheses
)
node
.
getGauche
()).
getExpression
():
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)?
((
Parentheses
)
node
.
getDroite
()).
getExpression
():
node
.
getDroite
();
boolean
isComparaisonOk
=
false
;
if
((
gauche
instanceof
Nombre
&&
droite
instanceof
Nombre
)
||
(
gauche
instanceof
Nombre
&&
(
droite
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
droite
).
getNom
())).
getType
()
instanceof
Entier
))
||
((
gauche
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
gauche
).
getNom
())).
getType
()
instanceof
Entier
)
&&
droite
instanceof
Nombre
)
||
((
gauche
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
gauche
).
getNom
())).
getType
()
instanceof
Entier
)
&&
(
droite
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
droite
).
getNom
())).
getType
()
instanceof
Entier
)))
{
//dans le cas ou on compare 2 nombres
isComparaisonOk
=
true
;
}
else
if
(
(
gauche
instanceof
Vrai
||
gauche
instanceof
Faux
||
(
gauche
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
gauche
).
getNom
())).
getType
()
instanceof
Booleen
)
||
gauche
instanceof
Relation
)
&&
(
droite
instanceof
Vrai
||
droite
instanceof
Faux
||
(
droite
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
droite
).
getNom
())).
getType
()
instanceof
Booleen
)
||
droite
instanceof
Relation
)
)
{
//dans le cas où on compare 2 booleans
isComparaisonOk
=
true
;
}
if
(!
isComparaisonOk
){
throw
new
RuntimeException
(
"Impossible d'effectuer une comparaison entre 2 valeur qui ne sont pas du même type !"
);
}
return
null
;
}
...
...
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