My analyzer is working. However, I’m just now realizing that my parser must somehow distinguish between variable assignment and reference/expression (ie, initializing, setting and getting variables).
Does this usually get handled by the parser or the analyzer? Should I write new productions to handle variable reference or assignment?
Here’s my productions script:
script = [
FuncDef("hello",
Params([
ExprVariable('x'), ExprVariable('y')
]),
Body([
FuncCall("print",
Params([
ExprPlus(ExprVariable('x'), ExprVariable('y'))
])
)
])),
FuncCall("hello",
Params([ExprNumber(10), ExprNumber(20)])
)
]
Here’s some output from my analyzer:
>>> variables: {'x': None, 'y': None}
>>> functions: {'hello':
<FUNCDEF>
name: hello
params:
<PARAMS>
parameters: [
<EXPRVAR>
identifier: x
</EXPRVAR>,
<EXPRVAR>
identifier: y
</EXPRVAR>]
</PARAMS>
body:
<BODY indent: 0 >
contents: [
<FUNCCALL>
name: print
params:
<PARAMS>
parameters: [
<EXPRPLUS>
left:
<EXPRVAR>
identifier: x
</EXPRVAR>
right:
<EXPRVAR>
identifier: y
</EXPRVAR>
</EXPRPLUS>]
</PARAMS>
</FUNCCALL>]
</BODY>
</FUNCDEF>}