bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does runtime stack work?


From: arnold
Subject: Re: How does runtime stack work?
Date: Fri, 21 May 2021 03:59:27 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi,
>
> I see a stack is used in gawk. I don't understand what this is used
> for. Could anybody help explain? Thanks.

Out of curiosity, why do you ask?

To briefly answer the question, gawk reads the program and converts
it into an internal form, often called "byte code". The internal form
represents instructions for a "virtual machine" that is stack based.
Operands are pushed onto the stack. Operators pop the operands, do the
operation, and push the result back onto the stack. For example,

        x = 3 + 5

would turn into something like:

        PUSH    3
        PUSH    5
        ADD             # 3 and 5 are popped off the stack, 8 is pushed on it
        STORE   x       # 8 popped off the stack and stored into 'x'

This is one of several standard mechanisms for implementing programming
language interpreters.

There have been hardware computers that are stack based as well,
although I am not sure which modern architectures, if any, are
stack based.

HTH,

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]