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
0041abe2
Commit
0041abe2
authored
2 years ago
by
lucien.noel
Browse files
Options
Downloads
Patches
Plain Diff
amélioration du code
parent
e122f40d
No related branches found
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
+24
-63
24 additions, 63 deletions
Visitors/SemanticAnalyzer.java
with
24 additions
and
63 deletions
Visitors/SemanticAnalyzer.java
+
24
−
63
View file @
0041abe2
...
@@ -60,7 +60,8 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -60,7 +60,8 @@ public class SemanticAnalyzer implements ASTVisitor {
cond
instanceof
Egal
||
cond
instanceof
Diff
||
cond
instanceof
Egal
||
cond
instanceof
Diff
||
cond
instanceof
Inferieur
||
cond
instanceof
InfEgal
||
cond
instanceof
Inferieur
||
cond
instanceof
InfEgal
||
cond
instanceof
Superieur
||
cond
instanceof
SupEgal
))
{
cond
instanceof
Superieur
||
cond
instanceof
SupEgal
))
{
// throw new RuntimeException("classe invalide :"+node.getCondition().getClass().toString());
// throw new RuntimeException("classe invalide
// :"+node.getCondition().getClass().toString());
throw
new
RuntimeException
(
"la condition passée n'est pas un booleen !"
);
throw
new
RuntimeException
(
"la condition passée n'est pas un booleen !"
);
}
}
...
@@ -95,12 +96,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -95,12 +96,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -136,12 +132,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -136,12 +132,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -168,12 +159,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -168,12 +159,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -187,12 +173,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -187,12 +173,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -224,6 +205,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -224,6 +205,7 @@ public class SemanticAnalyzer implements ASTVisitor {
public
Object
visit
(
Ou
node
)
{
public
Object
visit
(
Ou
node
)
{
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
return
null
;
return
null
;
}
}
...
@@ -283,12 +265,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -283,12 +265,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -302,12 +279,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -302,12 +279,7 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getGauche
().
accept
(
this
);
node
.
getGauche
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
node
.
getDroite
().
accept
(
this
);
Expression
gauche
=
(
node
.
getGauche
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getGauche
()).
getExpression
()
boolean
isComparaisonOk
=
isRelationOk
(
node
.
getGauche
(),
node
.
getDroite
());
:
node
.
getGauche
();
Expression
droite
=
(
node
.
getDroite
()
instanceof
Parentheses
)
?
((
Parentheses
)
node
.
getDroite
()).
getExpression
()
:
node
.
getDroite
();
boolean
isComparaisonOk
=
isRelationOk
(
gauche
,
droite
);
if
(!
isComparaisonOk
)
{
if
(!
isComparaisonOk
)
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
...
@@ -342,32 +314,7 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -342,32 +314,7 @@ public class SemanticAnalyzer implements ASTVisitor {
*/
*/
private
boolean
isRelationOk
(
Expression
gauche
,
Expression
droite
)
{
private
boolean
isRelationOk
(
Expression
gauche
,
Expression
droite
)
{
boolean
ok
=
false
;
boolean
ok
=
false
;
if
((
isExpressionNumber
(
gauche
)
&&
isExpressionNumber
(
droite
))
||
(
isExpressionBooleen
(
gauche
)
&&
isExpressionBooleen
(
droite
)))
{
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
ok
=
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
ok
=
true
;
ok
=
true
;
}
}
return
ok
;
return
ok
;
...
@@ -375,12 +322,26 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -375,12 +322,26 @@ public class SemanticAnalyzer implements ASTVisitor {
/**
/**
* Indique si l'expression passée est un nombre
* Indique si l'expression passée est un nombre
*
* @param expr
* @param expr
* @return true si l'expression passée est un nombre
* @return true si l'expression passée est un nombre
*/
*/
private
boolean
isExpressionNumber
(
Expression
expr
)
{
private
boolean
isExpressionNumber
(
Expression
expr
)
{
expr
=
(
expr
instanceof
Parentheses
)?((
Parentheses
)
expr
).
getExpression
():
expr
;
return
expr
instanceof
Nombre
||
(
expr
instanceof
Idf
return
expr
instanceof
Nombre
||
(
expr
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
expr
).
getNom
())).
getType
()
instanceof
Entier
);
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
expr
).
getNom
())).
getType
()
instanceof
Entier
);
}
}
/**
* Indique si l'expression passée est un booleen
*
* @param expr
* @return true si l'expression passée est un booleen
*/
private
boolean
isExpressionBooleen
(
Expression
expr
)
{
expr
=
(
expr
instanceof
Parentheses
)?((
Parentheses
)
expr
).
getExpression
():
expr
;
return
expr
instanceof
Vrai
||
expr
instanceof
Faux
||
expr
instanceof
Relation
||
(
expr
instanceof
Idf
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
expr
).
getNom
())).
getType
()
instanceof
Booleen
);
}
}
}
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