Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on How to initialize variable assignment in a non-OOP interpreter?

Post

How to initialize variable assignment in a non-OOP interpreter?

+0
−1

I'm still in the process of making MarkFuncs and having given up from copy-pasting open-source interpreters, them using OOP too, I decided to make one without OOP and with scratch alongside with the help of @Moshi in the Discord server.

test4 is where I'm currently at right now. interpreter.py currently has an output syntax for strings, and 2 functions that solve a challenge each in Code Golf CD. Right now, I want to do some math, in other words, deal with integers. The first problem to encounter, however is variable assignment.

I still have no idea how to get a specific keyword stored into the program and its value, then be reused and/or outputted. Here's what I have in mind for the syntax to be like:

x=9;y=10;→x+y; # Full program
x=9            # Assign 9 in variable named x
   ;           # Semicolon to terminate the assigning process
    y=10       # Assign 10 in variable named y
        ;      # Semicolon to terminate the assigning process
         →x+y  # Output the sum of x and y (uses the in-progress calculate() function)
             ; # Semicolon to terminate the outputting process

This will be put in the Input section of the TIO link.

Since I'm not using OOP--and I want to keep it that way--, it'll be tricky to even make variable assigning possible, and that's why I need help here.

Question: How to make variable assigning possible in my Python-written interpreter?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

A simple approach is to have a dictionary (so you store as `vars['x'] = x_value`). Of course this doe... (1 comment)
A simple approach is to have a dictionary (so you store as `vars['x'] = x_value`). Of course this doe...
hkotsubo‭ wrote over 3 years ago · edited over 3 years ago

A simple approach is to have a dictionary (so you store as vars['x'] = x_value). Of course this doesn't handle different scopes, but for a very simple interpreter, it's a starting point...

As a side note, this has absolutely nothing to do with being OOP or not.