Python has been my programming language of choice. There are many reasons behind this decision. I’ve briefly dealt with other languages in the past and they tend to require a larger learning curve than Python. It has an immense user base, many of which are willing to help you. It has an incredible collection of advanced libraries and toolkits. A lot of great libraries are included as a part of the Python standard library. But you can find a library that can be used to do just about anything. Installing these are relatively easy with Python’s pip module. Just go to the PyPI website (https://pypi.org/) and do a search for whatever you desire to do and select one of the results and copy the pip text. PyPI is the Python Package Installer, its an online repository for all the Python packages. Then if you have Python installed and it is on your environment path, you can call Python up and run the pip module to install it. In my case the terminal command is as follows:
py -m pip install [whatever module text is]
py is the command to run Python, -m is a flag to indicate the following is a module, pip is the module, install is a call to a function to perform the installation, everything in the brackets would be the package to be installed. Pip already has the remote path to the package figured in. This will grab the module from the repository and install it into the proper location. It’s features like this that make the language powerful. Many tools are built in. If it has any drawbacks, it must be the fact that its a scripting language rather than a compiled language. This means that there seems to be an intermediate step before it can run. Most languages are lexed, parsed, and then compiled into machine code (0’s & 1’s). Python and other scripting languages get lexed and parsed into bytecode. This bytecode then get interpreted in a runtime environment. The bytecode has to be interpreted into machine code, whereas code that has been compiled only needs to run. This extra step consumes the resource of time. It does have the advantage of being faster to prototype and develop. The runtime environment also makes the code easily accessible to more machines. A programmer only has to right the code once and it is supported by any machine that has an environment. Machine code is based on a chipset’s instructions. These instructions vary from chip to chip. Instructions in machine code written for one chipset (Apple iPhone’s A8, an ARM 64bit SoC) may not work in another (Lenovo laptop’s Intel Core i5 8th Gen). So this scripting language thing is kind of small trade of time for versatility. I imagine bytecode looks a lot like any other Assembler language variation. There is a Python module called ‘dis’ (dis for disassembler) you can use to view this bytecode.
Lexing and parsing; a lexer reads text input and breaks it into packets called tokens. Think about how you interpret sentences. You read in characters and break them into words. Words are like your tokens, and so are spaces and periods and all the symbols. Symbols many times have to be combined to give it meaning; ‘p’ by itself might not have any meaning, but ‘people’ does. These tokens are based on your English grammar. Your programming language also has a grammar to it. It’s tokens are defined by it’s programming grammar. The parser takes the tokens and builds an AST (Abstract Syntax Tree), this is an organized structure giving the tokens a logical meaning. I think of it like diagraming a sentence in English class. You place the noun and the verb on horizontal line, separate them with a sturdy vertical line and then modifiers are added to branches that dangle out from under what they modify at angles, while indirect objects protrude from horizontal lines under the main trunk. The parts of speech are the tokens and diagraming them indicated their logical meaning and showed their relationships. Those exercises were designed to help students build their grammar and comprehend the meaning behind sentences. The interpreter can use the logic derived from AST to perform the requested tasks. Shuffling memory, performing calculations, and running peripherals.