Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parser-fplo
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
parser-fplo
Commits
13c94b2b
Commit
13c94b2b
authored
8 years ago
by
Henning Glawe
Browse files
Options
Downloads
Patches
Plain Diff
map 'flag' datatype to struct-like AST_datatype_flag
parent
e1ad1e0c
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/parser-fplo/FploInputParser.py
+50
-2
50 additions, 2 deletions
parser/parser-fplo/FploInputParser.py
with
50 additions
and
2 deletions
parser/parser-fplo/FploInputParser.py
+
50
−
2
View file @
13c94b2b
...
...
@@ -266,6 +266,9 @@ class AST_datatype_struct(AST_datatype):
for
src_child
in
src_block
.
child
:
self
.
append
(
src_child
)
class
AST_datatype_flag
(
AST_datatype_struct
):
pass
class
AST_declaration
(
AST_node
):
"""
variable declaration in abstract syntax tree
"""
...
...
@@ -391,6 +394,17 @@ class concrete_statement(concrete_node):
struct
.
append_block
(
self
.
items
[
1
].
to_AST
())
result
=
AST_declaration
(
self
.
items
[
2
].
value
,
struct
)
pos_in_statement
=
3
elif
isinstance
(
self
.
items
[
0
],
token_datatype
)
and
self
.
items
[
0
].
value
==
'
flag
'
:
# special case for non-C-primtype 'flag'
# we will map this to struct of logicals, but need to evaluate
# RHS to get the names. messy.
flag
=
AST_datatype_flag
()
result
=
AST_declaration
(
self
.
items
[
1
].
value
,
flag
)
if
isinstance
(
self
.
items
[
2
],
concrete_subscript
):
# skip array shape
pos_in_statement
=
3
else
:
pos_in_statement
=
2
elif
isinstance
(
self
.
items
[
0
],
token_datatype
):
primtype
=
AST_datatype_primitive
(
self
.
items
[
0
].
value
)
if
primtype
.
name
==
'
char
'
and
isinstance
(
self
.
items
[
1
],
concrete_subscript
):
...
...
@@ -435,9 +449,16 @@ class concrete_statement(concrete_node):
return
new_assignment
if
isinstance
(
concrete_values
,
concrete_block
):
new_value
=
AST_value_list
()
new_value
.
child
=
concrete_values
.
python_value
()
if
isinstance
(
result
.
child
[
1
],
AST_datatype_flag
):
# special case for 'flag' datatype, need to evaluate RHS for names
(
flag_names
,
flag_values
)
=
concrete_values
.
flag_names_values
()
for
flag_name
in
flag_names
:
result
.
child
[
1
].
append
(
AST_declaration
(
flag_name
,
AST_datatype_primitive
(
'
logical
'
)))
for
flag_value
in
flag_values
:
new_value
.
append
(
flag_value
)
else
:
new_value
.
child
=
concrete_values
.
python_value
()
new_assignment
.
append
(
new_value
)
return
new_assignment
return
new_assignment
def
python_value
(
self
):
...
...
@@ -473,6 +494,28 @@ class concrete_statement(concrete_node):
# raise Exception('stop here')
return
result
def
flag_names_values
(
self
):
result_names
=
[]
result_values
=
[]
accum
=
[]
for
item
in
self
.
items
:
if
isinstance
(
item
,
(
token_identifier
,
token_flag_value
)):
accum
.
append
(
item
.
value
)
elif
isinstance
(
item
,
token_operator
)
and
item
.
value
==
'
,
'
:
if
len
(
accum
)
!=
2
:
raise
RuntimeError
(
'
flag_names_values encountered non-pair:
'
,
str
(
accum
))
result_names
.
append
(
accum
[
0
])
result_values
.
append
(
accum
[
1
])
accum
=
[]
else
:
raise
RuntimeError
(
'
flag_names_values encountered unhandled item:
'
+
repr
(
item
))
if
len
(
accum
)
>
0
:
if
len
(
accum
)
!=
2
:
raise
RuntimeError
(
'
flag_names_values encountered non-pair:
'
,
str
(
accum
))
result_names
.
append
(
accum
[
0
])
result_values
.
append
(
accum
[
1
])
return
(
result_names
,
result_values
)
class
concrete_block
(
concrete_node
):
def
nomadmetainfo
(
self
,
prefix
,
indent
):
if
len
(
self
.
items
)
<
1
:
...
...
@@ -497,6 +540,11 @@ class concrete_block(concrete_node):
raise
RuntimeError
(
'
python_value for block containing !=1 statement
'
)
return
self
.
items
[
0
].
python_value
()
def
flag_names_values
(
self
):
if
len
(
self
.
items
)
!=
1
:
raise
RuntimeError
(
'
flag_names for block containing !=1 statement
'
)
return
self
.
items
[
0
].
flag_names_values
()
class
concrete_subscript
(
concrete_statement
):
def
__str__
(
self
):
...
...
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