Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2024_compilation_Bazizi_Zaynoune
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
BAZIZI Zakaria
2024_compilation_Bazizi_Zaynoune
Commits
c636511c
Commit
c636511c
authored
1 year ago
by
ZaynouneFatimaZahrae
Browse files
Options
Downloads
Patches
Plain Diff
sa2ts
parent
45b4410a
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
+51
-37
51 additions, 37 deletions
src/ts/Sa2ts.java
with
51 additions
and
37 deletions
src/ts/Sa2ts.java
+
51
−
37
View file @
c636511c
package
ts
;
import
lParser.node.AType
;
import
lParser.node.ATypeType
;
import
sa.*
;
import
util.Error
;
...
...
@@ -11,7 +9,7 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
PARAM
}
private
Ts
tableGlobale
;
private
final
Ts
tableGlobale
;
private
Ts
tableLocaleCourante
;
private
Context
context
;
...
...
@@ -25,20 +23,29 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
context
=
Context
.
GLOBAL
;
}
public
Void
visit
(
SaDecVar
node
)
{
if
(
tableLocaleCourante
.
getVar
(
node
.
getNom
())
==
null
)
{
if
(
node
.
getTsItem
()
==
null
)
{
tableLocaleCourante
.
addVar
(
node
.
getNom
(),
node
.
getType
());
}
else
{
if
(
node
.
getTsItem
().
isParam
)
{
tableLocaleCourante
.
addParam
(
node
.
getNom
(),
node
.
getType
());
public
Void
visit
(
SaDecVar
node
)
throws
Exception
{
defaultIn
(
node
);
TsItemVar
ts
=
null
;
try
{
if
(
context
==
Context
.
PARAM
)
{
ts
=
tableLocaleCourante
.
addParam
(
node
.
getNom
(),
node
.
getType
());
}
else
if
(
context
==
Context
.
LOCAL
)
{
if
(
tableLocaleCourante
.
getVar
(
node
.
getNom
())
!=
null
)
throw
new
ErrorException
(
Error
.
TS
,
"Variable locale"
);
ts
=
tableLocaleCourante
.
addVar
(
node
.
getNom
(),
node
.
getType
());
}
else
{
tableLocaleCourante
.
addVar
(
node
.
getNom
(),
node
.
getType
());
if
(
tableGlobale
.
getVar
(
node
.
getNom
())
!=
null
)
throw
new
ErrorException
(
Error
.
TS
,
"Variable globale"
);
ts
=
tableLocaleCourante
.
addVar
(
node
.
getNom
(),
node
.
getType
());
}
}
catch
(
ErrorException
e
){
System
.
err
.
print
(
"Erreur dans la declaration de variable"
);
System
.
err
.
println
(
e
.
getMessage
());
System
.
exit
(
e
.
getCode
());
}
}
else
{
System
.
err
.
println
(
"La variable/ le paramètre"
+
node
.
getNom
()
+
"existe déjà !"
);
}
node
.
setTsItem
(
ts
);
defaultOut
(
node
);
System
.
out
.
println
(
tableGlobale
.
variables
);
return
null
;
}
...
...
@@ -100,32 +107,39 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
node
.
tsItem
=
tsItemVar
;
return
null
;
}
public
Void
visit
(
SaVarIndicee
node
){
TsItemVar
var
=
tableGlobale
.
getVar
(
node
.
getNom
());
if
(
var
==
null
)
System
.
err
.
println
(
"Introuvable"
);
else
node
.
tsItem
=
var
;
public
Void
visit
(
SaVarIndicee
node
)
throws
Exception
{
defaultIn
(
node
);
if
(
tableGlobale
.
getVar
(
node
.
getNom
())
!=
null
){
node
.
tsItem
=
tableGlobale
.
getVar
(
node
.
getNom
());
node
.
getIndice
().
accept
(
this
);
}
else
if
(
tableLocaleCourante
.
getVar
(
node
.
getNom
())
!=
null
){
node
.
tsItem
=
tableLocaleCourante
.
getVar
(
node
.
getNom
());
node
.
getIndice
().
accept
(
this
);
}
else
{
throw
new
ErrorException
(
Error
.
TS
,
""
);
}
defaultOut
(
node
);
return
null
;
}
public
Void
visit
(
SaAppel
node
){
String
nom
=
node
.
getNom
();
int
nbArgs
;
if
(
node
.
getArguments
()
==
null
)
nbArgs
=
0
;
else
nbArgs
=
node
.
getArguments
().
length
();
TsItemFct
tsItemFct
=
tableGlobale
.
getFct
(
nom
);
if
(
tableGlobale
.
getFct
(
nom
)
==
null
)
throw
new
RuntimeException
((
"Erreur"
));
if
(
nbArgs
!=
tsItemFct
.
nbArgs
)
throw
new
RuntimeException
(
"Erreur"
);
node
.
tsItem
=
tsItemFct
;
public
Void
visit
(
SaAppel
node
)
throws
Exception
{
defaultIn
(
node
);
if
(
node
.
getArguments
().
length
()
==
tableGlobale
.
getFct
(
node
.
getNom
()).
getNbArgs
()){
node
.
getArguments
().
accept
(
this
);
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
}
else
if
(
node
.
getArguments
()
==
null
&&
tableGlobale
.
getFct
(
node
.
getNom
()).
getNbArgs
()
==
0
)
{
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
}
else
{
throw
new
ErrorException
(
Error
.
TS
,
""
);
}
context
=
Context
.
LOCAL
;
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
context
=
Context
.
GLOBAL
;
defaultOut
(
node
);
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