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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BAUQUIN Niels
2024_compilation_bauquin
Commits
086b4789
Commit
086b4789
authored
1 year ago
by
BAUQUIN Niels
Browse files
Options
Downloads
Patches
Plain Diff
geg
parent
bf675260
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Compiler.java
+2
-1
2 additions, 1 deletion
src/Compiler.java
src/ts/Sa2ts.java
+131
-2
131 additions, 2 deletions
src/ts/Sa2ts.java
src/ts/Ts.java
+3
-11
3 additions, 11 deletions
src/ts/Ts.java
src/ts/TsItemVar.java
+1
-0
1 addition, 0 deletions
src/ts/TsItemVar.java
with
137 additions
and
14 deletions
src/Compiler.java
+
2
−
1
View file @
086b4789
...
@@ -32,9 +32,10 @@ public class Compiler
...
@@ -32,9 +32,10 @@ public class Compiler
System
.
out
.
println
(
"[BUILD SC] "
);
System
.
out
.
println
(
"[BUILD SC] "
);
buildSc
();
buildSc
();
System
.
out
.
println
(
"[BUILD SA] "
);
System
.
out
.
println
(
"[BUILD SA] "
);
buildSa
();
/*
buildSa
();
System
.
out
.
println
(
"[BUILD TS] "
);
System
.
out
.
println
(
"[BUILD TS] "
);
buildTs
();
buildTs
();
/*
System.out.println("[TYPE CHECKING]");
System.out.println("[TYPE CHECKING]");
typeCheck();
typeCheck();
System.out.println("[BUILD C3A] ");
System.out.println("[BUILD C3A] ");
...
...
This diff is collapsed.
Click to expand it.
src/ts/Sa2ts.java
+
131
−
2
View file @
086b4789
package
ts
;
package
ts
;
import
sa.*
;
import
sa.*
;
import
util.Error
;
import
util.Error
;
import
util.Type
;
public
class
Sa2ts
extends
SaDepthFirstVisitor
<
Void
>
{
public
class
Sa2ts
extends
SaDepthFirstVisitor
<
Void
>
{
enum
Context
{
enum
Context
{
...
@@ -22,14 +23,142 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
...
@@ -22,14 +23,142 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
context
=
Context
.
GLOBAL
;
context
=
Context
.
GLOBAL
;
}
}
@Override
public
Void
visit
(
SaDecTab
node
)
throws
Exception
{
String
nomTableau
=
node
.
getNom
();
Type
typeTableau
=
node
.
getType
();
int
tailleTableau
=
node
.
getTaille
();
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nomTableau
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"Le tableau "
+
nomTableau
+
" est déjà défini."
);
}
tableGlobale
.
addTab
(
nomTableau
,
typeTableau
,
tailleTableau
);
}
return
null
;
}
@Override
public
Void
visit
(
SaDecFonc
node
)
throws
Exception
{
String
nomFonction
=
node
.
getNom
();
SaLDecVar
parameters
=
node
.
getParametres
();
SaLDecVar
variable
=
node
.
getVariable
();
SaInst
corps
=
node
.
getCorps
();
if
(
tableGlobale
.
getFct
(
nomFonction
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
nomFonction
+
" est déjà définie."
);
}
Ts
table
=
new
Ts
();
tableLocaleCourante
=
table
;
int
param
=
0
;
if
(
parameters
!=
null
)
{
context
=
Context
.
PARAM
;
parameters
.
accept
(
this
);
param
=
parameters
.
length
();
}
if
(
variable
!=
null
)
{
context
=
Context
.
LOCAL
;
variable
.
accept
(
this
);
}
node
.
tsItem
=
tableGlobale
.
addFct
(
nomFonction
,
node
.
getTypeRetour
(),
param
,
table
,
node
);
if
(
corps
!=
null
)
{
context
=
Context
.
LOCAL
;
corps
.
accept
(
this
);
}
context
=
Context
.
GLOBAL
;
return
null
;
}
@Override
public
Void
visit
(
SaDecVar
node
)
throws
Exception
{
String
nomVar
=
node
.
getNom
();
Type
typeVar
=
node
.
getType
();
if
(
context
==
Context
.
LOCAL
)
{
if
(
tableLocaleCourante
.
getVar
(
nomVar
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" est déjà définie."
);
}
node
.
setTsItem
(
tableLocaleCourante
.
addVar
(
nomVar
,
typeVar
));
}
else
if
(
context
==
Context
.
PARAM
)
{
if
(
tableLocaleCourante
.
getVar
(
nomVar
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" est déjà définie."
);
}
node
.
setTsItem
(
tableLocaleCourante
.
addParam
(
nomVar
,
typeVar
));
}
else
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nomVar
)
!=
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" est déjà définie."
);
}
node
.
setTsItem
(
tableGlobale
.
addVar
(
nomVar
,
typeVar
));
}
return
null
;
}
@Override
public
Void
visit
(
SaVarSimple
node
)
throws
Exception
{
String
nomVar
=
node
.
getNom
();
TsItemVarSimple
varSimple
=
node
.
getTsItem
();
if
(
context
==
Context
.
LOCAL
)
{
if
(
tableLocaleCourante
.
getVar
(
nomVar
)
==
null
&&
tableGlobale
.
getVar
(
nomVar
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" n'est pas définie."
);
}
if
(
tableLocaleCourante
.
getVar
(
nomVar
)
!=
null
)
{
node
.
tsItem
=
(
TsItemVarSimple
)
tableLocaleCourante
.
getVar
(
nomVar
);
}
else
{
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
nomVar
);
}
}
else
if
(
context
==
Context
.
PARAM
)
{
if
(
tableLocaleCourante
.
getVar
(
nomVar
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" n'est pas définie."
);
}
}
else
if
(
context
==
Context
.
GLOBAL
)
{
if
(
tableGlobale
.
getVar
(
nomVar
)
==
null
||
varSimple
.
getTaille
()
>
1
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La variable "
+
nomVar
+
" n'est pas définie."
);
}
node
.
tsItem
=
(
TsItemVarSimple
)
tableGlobale
.
getVar
(
nomVar
);
}
return
null
;
}
@Override
public
Void
visit
(
SaAppel
node
)
throws
Exception
{
String
nomFonction
=
node
.
getNom
();
SaLExp
arguments
=
node
.
getArguments
();
int
args
=
0
;
if
(
arguments
!=
null
)
{
arguments
.
accept
(
this
);
args
=
arguments
.
length
();
}
if
(
tableGlobale
.
getFct
(
nomFonction
)
==
null
)
{
throw
new
ErrorException
(
Error
.
TS
,
"La fonction "
+
nomFonction
+
" n'est pas définie."
);
}
if
(
this
.
tableGlobale
.
getFct
(
nomFonction
).
getNbArgs
()
!=
args
)
{
throw
new
ErrorException
(
Error
.
TS
,
"Le nombre d'arguments est incorrect."
+
this
.
tableGlobale
.
getFct
(
nomFonction
).
getNbArgs
()
+
" requis."
);
}
node
.
tsItem
=
tableGlobale
.
getFct
(
node
.
getNom
());
return
null
;
}
@Override
public
Void
visit
(
SaVarIndicee
node
)
throws
Exception
{
String
nomVar
=
node
.
getNom
();
SaExp
indice
=
node
.
getIndice
();
if
(
tableGlobale
.
getVar
(
nomVar
)
==
null
&&
tableGlobale
.
getVar
(
nomVar
).
getTaille
()
==
1
)
throw
new
ErrorException
(
Error
.
TS
,
"indice "
+
nomVar
+
" incorrect."
);
node
.
tsItem
=
tableGlobale
.
getVar
(
node
.
getNom
());
indice
.
accept
(
this
);
return
null
;
}
public
void
defaultIn
(
SaNode
node
)
public
void
defaultIn
(
SaNode
node
)
{
{
//
System.out.println("<" + node.getClass().getSimpleName() + ">");
System
.
out
.
println
(
"<"
+
node
.
getClass
().
getSimpleName
()
+
">"
);
}
}
public
void
defaultOut
(
SaNode
node
)
public
void
defaultOut
(
SaNode
node
)
{
{
//
System.out.println("</" + node.getClass().getSimpleName() + ">");
System
.
out
.
println
(
"</"
+
node
.
getClass
().
getSimpleName
()
+
">"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ts/Ts.java
+
3
−
11
View file @
086b4789
...
@@ -23,11 +23,7 @@ public class Ts
...
@@ -23,11 +23,7 @@ public class Ts
public
TsItemVar
addVar
(
String
identif
,
Type
type
)
public
TsItemVar
addVar
(
String
identif
,
Type
type
)
{
{
for
(
String
id
:
variables
.
keySet
())
{
if
(
id
==
identif
&&
variables
.
get
(
id
).
isParam
)
{
return
null
;
}
}
TsItemVar
item
=
new
TsItemVarSimple
(
identif
,
type
);
TsItemVar
item
=
new
TsItemVarSimple
(
identif
,
type
);
item
.
portee
=
this
;
item
.
portee
=
this
;
item
.
adresse
=
this
.
adrVarCourante
;
item
.
adresse
=
this
.
adrVarCourante
;
...
@@ -39,11 +35,7 @@ public class Ts
...
@@ -39,11 +35,7 @@ public class Ts
public
TsItemVar
addParam
(
String
identif
,
Type
type
)
public
TsItemVar
addParam
(
String
identif
,
Type
type
)
{
{
for
(
String
id
:
variables
.
keySet
())
{
if
(
id
==
identif
&&
variables
.
get
(
id
).
isParam
)
{
return
null
;
}
}
TsItemVar
item
=
new
TsItemVarSimple
(
identif
,
type
);
TsItemVar
item
=
new
TsItemVarSimple
(
identif
,
type
);
item
.
portee
=
this
;
item
.
portee
=
this
;
item
.
adresse
=
this
.
adrArgCourante
;
item
.
adresse
=
this
.
adrArgCourante
;
...
@@ -55,7 +47,7 @@ public class Ts
...
@@ -55,7 +47,7 @@ public class Ts
public
TsItemVar
addTab
(
String
identif
,
Type
type
,
int
taille
)
public
TsItemVar
addTab
(
String
identif
,
Type
type
,
int
taille
)
{
{
//Verifier qu'on est en global
TsItemVar
item
=
new
TsItemVarTab
(
identif
,
type
,
taille
);
TsItemVar
item
=
new
TsItemVarTab
(
identif
,
type
,
taille
);
item
.
portee
=
this
;
item
.
portee
=
this
;
item
.
adresse
=
this
.
adrVarCourante
;
item
.
adresse
=
this
.
adrVarCourante
;
...
...
This diff is collapsed.
Click to expand it.
src/ts/TsItemVar.java
+
1
−
0
View file @
086b4789
...
@@ -9,6 +9,7 @@ public abstract class TsItemVar {
...
@@ -9,6 +9,7 @@ public abstract class TsItemVar {
public
boolean
isParam
;
public
boolean
isParam
;
public
Type
type
;
public
Type
type
;
public
int
getAdresse
(){
return
this
.
adresse
;}
public
int
getAdresse
(){
return
this
.
adresse
;}
public
String
getIdentif
(){
return
this
.
identif
;}
public
String
getIdentif
(){
return
this
.
identif
;}
public
Ts
getPortee
()
{
return
this
.
portee
;}
public
Ts
getPortee
()
{
return
this
.
portee
;}
...
...
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