Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs444
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
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xun Yang
cs444
Commits
68c2b22e
Commit
68c2b22e
authored
5 years ago
by
pycsham
Browse files
Options
Downloads
Patches
Plain Diff
added checks for definite assignemnt. some minor fixes required
parent
1cb3e0cf
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
LineNodes.py
+7
-2
7 additions, 2 deletions
LineNodes.py
Test.py
+4
-2
4 additions, 2 deletions
Test.py
joosc.py
+4
-1
4 additions, 1 deletion
joosc.py
with
15 additions
and
5 deletions
LineNodes.py
+
7
−
2
View file @
68c2b22e
...
...
@@ -31,7 +31,7 @@ def makeNodeFromAllStatement(parseTree, typeName):
return
WhileNode
(
child
,
typeName
)
elif
child
.
name
==
'
variableDcl
'
:
return
VarDclNode
(
child
,
typeName
)
return
VarDclNode
(
child
,
typeName
,
True
)
# Creates AST node from statementExpr
...
...
@@ -94,7 +94,7 @@ class BlockNode(ASTNode):
# 1. variableDcl type ID
# 2. variableDcl type ID ASSIGN variableInit
class
VarDclNode
(
ASTNode
):
def
__init__
(
self
,
parseTree
,
typeName
):
def
__init__
(
self
,
parseTree
,
typeName
,
checkAssign
=
False
):
self
.
parseTree
=
parseTree
self
.
dclType
=
None
self
.
name
=
None
# variable name
...
...
@@ -110,6 +110,11 @@ class VarDclNode(ASTNode):
# Handling rule: variableInit expr
self
.
variableInit
=
makeNodeFromExpr
(
parseTree
.
children
[
3
].
children
[
0
],
typeName
)
# Checking for definite assignment
if
checkAssign
:
if
not
self
.
variableInit
:
raise
Exception
(
"
ERROR: local variable declaration not assigned
"
)
self
.
myType
=
self
.
dclType
.
myType
self
.
children
.
append
(
self
.
dclType
)
self
.
children
.
append
(
self
.
variableInit
)
...
...
This diff is collapsed.
Click to expand it.
Test.py
+
4
−
2
View file @
68c2b22e
...
...
@@ -137,8 +137,10 @@ def run(testFiles):
# if n == "Tests/A3/J1_accessstaticfield/Main.java":
# print(n)
# print(t)
ASTs
=
astBuild
(
parseTrees
)
try
:
ASTs
=
astBuild
(
parseTrees
)
except
Exception
as
e
:
return
"
AST buidling:
"
+
e
.
args
[
0
]
# for (n, t) in ASTs:
# print(n)
...
...
This diff is collapsed.
Click to expand it.
joosc.py
+
4
−
1
View file @
68c2b22e
...
...
@@ -45,7 +45,10 @@ def main():
parseTrees
.
append
((
f
,
tree
))
# Building ASTs from all parse trees
ASTs
=
astBuild
(
parseTrees
)
try
:
ASTs
=
astBuild
(
parseTrees
)
except
Exception
as
e
:
# for definite assignemnt
return
42
try
:
buildEnvAndLink
(
ASTs
)
...
...
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