Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMILES PARSER
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
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Singh, Amisha
SMILES PARSER
Commits
8e68577d
Commit
8e68577d
authored
2 years ago
by
Singh, Amisha
Browse files
Options
Downloads
Patches
Plain Diff
Update parser.py
parent
0780a28f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
parser.py
+27
-5
27 additions, 5 deletions
parser.py
with
27 additions
and
5 deletions
parser.py
+
27
−
5
View file @
8e68577d
...
...
@@ -124,20 +124,28 @@ def check_validity(string, start, table,follow,productions,first):
idx
=
0
print
(
"
Stack
\t\t
Input
\t\t
Moves
"
)
while
(
len
(
stack
)
>
0
):
top
=
stack
[
-
1
]
if
top
!=
'
&
'
:
print
(
f
"
Top =>
{
top
}
"
)
curr_string
=
input_string
[
idx
]
# print("current",curr_string)
# print(idx,len(input_string))
if
curr_string
==
'
&
'
and
idx
+
1
==
len
(
input_string
):
accepted
=
True
break
if
input_string
[
idx
-
1
]
+
curr_string
in
[
'
Cl
'
,
'
Br
'
,
'
At
'
,
'
Ts
'
,
'
se
'
,
'
as
'
]:
#print("here")
curr_string
=
input_string
[
idx
-
1
]
+
curr_string
#print("done")
idx
=
idx
+
1
#print(input_string[idx])
if
top
==
'
Z
'
:
idx
=
idx
curr_string
=
input_string
[
idx
]
#print("NOW",input_string[idx])
if
curr_string
+
input_string
[
idx
+
1
]
in
[
'
Cl
'
,
'
Br
'
,
'
At
'
,
'
Ts
'
,
'
se
'
,
'
as
'
]:
#print("me")
curr_string
=
curr_string
+
input_string
[
idx
+
1
]
idx
=
idx
if
input_string
[
idx
+
1
]
==
'
-
'
:
...
...
@@ -146,6 +154,7 @@ def check_validity(string, start, table,follow,productions,first):
print
(
f
"
Current input =>
{
curr_string
}
"
)
if
len
(
stack
)
==
1
and
idx
<
len
(
input_string
)
-
1
:
stack
.
append
(
'
body
'
)
print
(
"
1
"
)
top
=
stack
[
-
1
]
if
curr_string
==
'
&
'
:
accepted
=
True
...
...
@@ -155,15 +164,30 @@ def check_validity(string, start, table,follow,productions,first):
idx
+=
1
if
len
(
stack
)
==
1
and
idx
<
len
(
input_string
)
-
1
:
top
=
"
body
"
print
(
"
2
"
)
else
:
key
=
(
top
,
curr_string
)
print
(
f
"
Key =>
{
key
}
"
)
if
key
not
in
table
and
len
(
stack
)
==
1
:
top
=
'
body
'
print
(
"
3
"
)
key
=
(
top
,
curr_string
)
if
top
==
curr_string
:
stack
.
pop
()
idx
+=
1
if
key
not
in
table
and
top
in
productions
.
keys
()
and
input_string
[
idx
-
2
]
+
input_string
[
idx
-
1
]
in
follow
[
top
]:
stack
.
pop
()
print
(
"
Try exempting
"
,
top
)
top
=
stack
[
-
1
]
key
=
(
top
,
curr_string
)
if
key
not
in
table
and
top
in
productions
.
keys
():
accepted
=
False
print
(
"
Invalid literal =
"
,
curr_string
)
break
elif
key
not
in
table
and
top
==
'
&
'
:
accepted
=
False
print
(
"
Invalid literal =
"
,
curr_string
)
break
if
key
not
in
table
and
top
in
productions
.
keys
()
and
input_string
[
idx
-
1
]
in
follow
[
top
]:
stack
.
pop
()
print
(
"
Try exempting
"
,
top
)
...
...
@@ -200,6 +224,7 @@ def check_validity(string, start, table,follow,productions,first):
stack
.
append
(
"
body
"
)
elif
top
!=
curr_string
:
print
(
"
pop
"
)
stack
.
pop
()
if
accepted
:
...
...
@@ -217,13 +242,10 @@ def mean_squared_error(act, pred):
def
main
():
productions
=
{}
grammar
=
open
(
"
grammar2.txt
"
,
"
r
"
)
first
=
{}
follow
=
{}
table
=
{}
table
=
{}
start
=
""
for
prod
in
grammar
:
l
=
re
.
split
(
"
> |
\n
|
"
,
prod
)
m
=
[]
...
...
@@ -275,7 +297,7 @@ def main():
# print(pred)
# print(mean_squared_error(1,pred))
ans
=
check_validity
(
input
(),
start
,
table
,
follow
,
productions
,
first
)
print
(
"
ANSWER=
"
,
ans
)
print
(
"
SMILES:
"
,
"
ANSWER=
"
,
ans
)
grammar
.
close
()
import
numpy
as
np
import
sys
...
...
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