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
d7505509
Commit
d7505509
authored
2 years ago
by
lucien.noel
Browse files
Options
Downloads
Patches
Plain Diff
le code
parent
c060d8db
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/test_base_with_sementic_issue.input
+15
-19
15 additions, 19 deletions
Tests/test_base_with_sementic_issue.input
Visitors/SemanticAnalyzer.java
+29
-24
29 additions, 24 deletions
Visitors/SemanticAnalyzer.java
with
44 additions
and
43 deletions
Tests/test_base_with_sementic_issue.input
+
15
−
19
View file @
d7505509
programme Program
programme Program
entier x, y;
booleen v;
entier x, y;
booleen f;
booleen z;
entier x;
entier y;
debutprg
debutprg
ecrire 6 + 2;
v = vrai;
ecrire 6 - 2;
f = faux;
ecrire 6 / 2;
x = 2;
ecrire 6 * 2;
y = 3;
x = 20;
ecrire "::: et";
y = 4;
ecrire faux et faux;
ecrire x + y;
ecrire vrai et faux;
ecrire x - y;
ecrire vrai et vrai;
ecrire x / y;
ecrire vrai et v;
ecrire x * y;
ecrire vrai et f;
x = x + 4;
ecrire non faux et vrai;
y = y - 2;
ecrire x + y;
ecrire x - y;
ecrire x / y;
ecrire x * y;
finprg
finprg
This diff is collapsed.
Click to expand it.
Visitors/SemanticAnalyzer.java
+
29
−
24
View file @
d7505509
...
@@ -34,7 +34,8 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -34,7 +34,8 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getDestination
().
accept
(
this
);
node
.
getDestination
().
accept
(
this
);
node
.
getSource
().
accept
(
this
);
node
.
getSource
().
accept
(
this
);
if
(!(
node
.
getDestination
()
instanceof
Idf
))
{
if
(!(
node
.
getDestination
()
instanceof
Idf
))
{
throw
new
RuntimeException
(
"Impossible d'effectuer une affectation sur quelque chose d'autre qu'un identifiant !"
);
throw
new
RuntimeException
(
"Impossible d'effectuer une affectation sur quelque chose d'autre qu'un identifiant !"
);
}
}
String
idfNom
=
((
Idf
)
node
.
getDestination
()).
getNom
();
String
idfNom
=
((
Idf
)
node
.
getDestination
()).
getNom
();
if
(
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
node
.
getDestination
()).
getNom
())).
cst
)
{
if
(
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
node
.
getDestination
()).
getNom
())).
cst
)
{
...
@@ -256,7 +257,8 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -256,7 +257,8 @@ public class SemanticAnalyzer implements ASTVisitor {
node
.
getFrom
().
accept
(
this
);
node
.
getFrom
().
accept
(
this
);
node
.
getTo
().
accept
(
this
);
node
.
getTo
().
accept
(
this
);
node
.
getInstruction
().
accept
(
this
);
node
.
getInstruction
().
accept
(
this
);
if
(!(
isExpressionNumber
(
node
.
getFrom
())
&&
isExpressionNumber
(
node
.
getTo
())
&&
isExpressionNumber
(
node
.
getIteratorName
()))){
if
(!(
isExpressionNumber
(
node
.
getFrom
())
&&
isExpressionNumber
(
node
.
getTo
())
&&
isExpressionNumber
(
node
.
getIteratorName
())))
{
throw
new
RuntimeException
(
"Erreur dans la condition de la boucle 'pour' !"
);
throw
new
RuntimeException
(
"Erreur dans la condition de la boucle 'pour' !"
);
}
}
return
null
;
return
null
;
...
@@ -356,7 +358,8 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -356,7 +358,8 @@ 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
((
isExpressionNumber
(
gauche
)
&&
isExpressionNumber
(
droite
))
||
(
isExpressionBooleen
(
gauche
)
&&
isExpressionBooleen
(
droite
)))
{
ok
=
true
;
ok
=
true
;
}
}
return
ok
;
return
ok
;
...
@@ -382,7 +385,9 @@ public class SemanticAnalyzer implements ASTVisitor {
...
@@ -382,7 +385,9 @@ public class SemanticAnalyzer implements ASTVisitor {
*/
*/
private
boolean
isExpressionBooleen
(
Expression
expr
)
{
private
boolean
isExpressionBooleen
(
Expression
expr
)
{
expr
=
(
expr
instanceof
Parentheses
)
?
((
Parentheses
)
expr
).
getExpression
()
:
expr
;
expr
=
(
expr
instanceof
Parentheses
)
?
((
Parentheses
)
expr
).
getExpression
()
:
expr
;
return
expr
instanceof
Vrai
||
expr
instanceof
Faux
||
expr
instanceof
Relation
||
expr
instanceof
Non
||
expr
instanceof
Et
||
expr
instanceof
Ou
||
(
expr
instanceof
Idf
return
expr
instanceof
Vrai
||
expr
instanceof
Faux
||
expr
instanceof
Relation
||
expr
instanceof
Non
&&
TDS
.
getInstance
().
identifier
(
new
Entree
(((
Idf
)
expr
).
getNom
())).
getType
()
instanceof
Booleen
);
||
expr
instanceof
Et
||
expr
instanceof
Ou
||
(
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