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
eae4a5e3
Commit
eae4a5e3
authored
5 years ago
by
pycsham
Browse files
Options
Downloads
Patches
Plain Diff
fixed paramNode bug. still working on bug for disambig called twice
parent
c014e22b
No related branches found
Branches containing commit
No related tags found
1 merge request
!5
Name disambig
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
AstBuilding.py
+5
-4
5 additions, 4 deletions
AstBuilding.py
Environment.py
+2
-1
2 additions, 1 deletion
Environment.py
ExprPrimaryNodes.py
+2
-2
2 additions, 2 deletions
ExprPrimaryNodes.py
NameNode.py
+11
-4
11 additions, 4 deletions
NameNode.py
Test.py
+16
-15
16 additions, 15 deletions
Test.py
with
36 additions
and
26 deletions
AstBuilding.py
+
5
−
4
View file @
eae4a5e3
...
...
@@ -51,10 +51,11 @@ def disamiguateAndTypeChecking(ASTs):
# disambiguate namesapce: figuring out the meaning of the shortest prefix of names
for
t
in
ASTs
:
try
:
t
[
1
].
recurseAction
(
"
disambigName
"
)
except
Exception
as
e
:
raise
e
# try:
# t[1].recurseAction("disambigName")
# except Exception as e:
# raise e
t
[
1
].
recurseAction
(
"
disambigName
"
)
# type checking
...
...
This diff is collapsed.
Click to expand it.
Environment.py
+
2
−
1
View file @
eae4a5e3
...
...
@@ -6,7 +6,8 @@ class Env:
'
InterNode
'
:
'
type
'
,
'
ClassNode
'
:
'
type
'
,
'
MethodNode
'
:
'
method
'
,
'
VarDclNode
'
:
'
expr
'
'
VarDclNode
'
:
'
expr
'
,
'
ParamNode
'
:
'
expr
'
})
...
...
This diff is collapsed.
Click to expand it.
ExprPrimaryNodes.py
+
2
−
2
View file @
eae4a5e3
...
...
@@ -29,7 +29,7 @@ def makeNodeFromExpr(parseTree, typeName):
if
c
.
name
==
'
primaryAndArray
'
:
return
makeNodeFromAllPrimary
(
c
,
typeName
)
elif
c
.
name
==
'
ID
'
or
c
.
name
==
'
COMPID
'
:
return
NameNode
(
c
,
typeName
,
Fals
e
)
return
NameNode
(
c
,
typeName
,
typeNam
e
)
elif
c
.
name
==
'
assignment
'
:
return
AssignNode
(
c
,
typeName
)
elif
len
(
c
.
children
)
==
1
:
...
...
@@ -73,7 +73,7 @@ def makeNodeFromAllPrimary(parseTree, typeName):
# helper methods
###########################################################
def
helperDisambigName
(
node
):
if
node
and
node
.
__class
.
__name__
==
"
NameNode
"
:
if
node
and
node
.
__class
__
.
__name__
==
"
NameNode
"
:
try
:
node
.
disambigName
()
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
NameNode.py
+
11
−
4
View file @
eae4a5e3
...
...
@@ -27,6 +27,7 @@ class NameNode(ASTNode):
self
.
methodInvoke
=
methodInvoke
# Bool: true if the last ID in the name is a method invokation
self
.
env
=
None
self
.
typeName
=
typeName
# the name of the class or interface that this node belongs under
self
.
children
=
[]
self
.
name
=
getParseTreeNodes
([
"
ID
"
,
"
COMPID
"
],
parseTree
)[
0
].
lex
...
...
@@ -59,16 +60,18 @@ class NameNode(ASTNode):
return
True
return
False
# Checks and updates prefix if the next ID in self.IDs is a local variable
# Checks and updates prefix if the next ID in self.IDs is a local variable
or a parameter
def
checkLocalVar
(
self
):
if
not
self
.
IDs
:
return
True
print
(
"
checking local variable
"
)
print
(
self
.
IDs
)
ID
=
self
.
IDs
[
0
]
localVarNode
=
self
.
env
.
findNode
(
ID
,
"
expr
"
)
if
localVarNode
:
self
.
addToPrefix
(
localVarNode
)
return
True
return
False
# Checks and updates prefix if the next ID in self.IDs is in the contains set
...
...
@@ -76,6 +79,8 @@ class NameNode(ASTNode):
def
checkContains
(
self
,
update
=
False
):
if
not
self
.
IDs
:
return
True
print
(
"
checking contains set
"
)
print
(
self
.
IDs
)
ID
=
self
.
IDs
[
0
]
if
self
.
env
.
findNode
(
ID
,
"
fieldDcl
"
)
or
self
.
env
.
findNode
(
ID
,
"
method
"
):
...
...
@@ -88,14 +93,14 @@ class NameNode(ASTNode):
def
checkStatic
(
self
):
if
not
self
.
IDs
:
return
True
currPrefix
=
""
for
index
,
ID
in
enumerate
(
self
.
IDs
):
if
currPrefix
:
currPrefix
+=
"
.
"
currPrefix
+=
ID
typeNode
=
self
.
env
.
getNode
(
currPrefix
)
typeNode
=
self
.
env
.
getNode
(
currPrefix
,
"
type
"
)
if
typeNode
:
# checking if the next ID is a static field in the class/interface
...
...
@@ -131,6 +136,8 @@ class NameNode(ASTNode):
# Checking if a1 is a local variable
if
self
.
checkLocalVar
():
print
(
"
local variable check is true
"
)
print
(
self
.
IDs
)
return
# TODO: Checking if a1 is in the contains set
...
...
This diff is collapsed.
Click to expand it.
Test.py
+
16
−
15
View file @
eae4a5e3
...
...
@@ -5,7 +5,7 @@ import traceback
from
Scanning
import
scan
from
Parsing
import
parse
from
AstBuilding
import
astBuild
,
buildEnvAndLink
from
AstBuilding
import
astBuild
,
buildEnvAndLink
,
disamiguateAndTypeChecking
import
Weeding
...
...
@@ -82,7 +82,7 @@ def run(testFiles):
parseTrees
=
[]
for
f
in
testFiles
:
#
print(f)
print
(
f
)
if
f
.
split
(
"
/
"
)[
-
1
]
==
"
.DS_Store
"
:
continue
content
=
open
(
f
,
"
r
"
).
read
()
...
...
@@ -146,10 +146,10 @@ def run(testFiles):
ASTs
=
astBuild
(
parseTrees
)
# for (n, t) in ASTs:
#
print(n)
#
print("--------------------")
#
t.printTree()
#
print("\n \n\n \n")
#
print(n)
#
print("--------------------")
#
t.printTree()
#
print("\n \n\n \n")
try
:
buildEnvAndLink
(
ASTs
)
...
...
@@ -160,16 +160,17 @@ def run(testFiles):
return
"
buildEnvAndLink:
"
+
e
.
args
[
0
]
# print("<<<<------- after buildEnvAndLink -------->>>>>>")
#
for (n, t) in ASTs:
#
print(n)
#
print("--------------------")
#
t.printTree()
#
print("\n \n\n \n")
for
(
n
,
t
)
in
ASTs
:
print
(
n
)
print
(
"
--------------------
"
)
t
.
printTree
()
print
(
"
\n
\n\n
\n
"
)
try
:
disamiguateAndTypeChecking
(
ASTs
)
except
Exception
as
e
:
return
"
Disambiguate and Type checking:
"
+
e
.
args
[
0
]
# try:
# disamiguateAndTypeChecking(ASTs)
# except Exception as e:
# return "Disambiguate and Type checking: " + e.args[0]
disamiguateAndTypeChecking
(
ASTs
)
# print("Succeeded")
# print("**********************************************************")
return
""
...
...
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