<p>C (and other languages which allow variable argument lists) process function arguments from right-to-left.</p>
<p>Pascal (and other languages with fixed-length argument lists) process function arguments from left-to-right.</p>
<p>From a <em>parsing</em> perspective, which is more efficient?</p>

<parsing>
From a parsing perspective, which is more efficient? Right-to-left or left-to-right argument parsing?
CC BY-SA 4.0
2024-05-13T12:38:00.753Z
I don't think that the C language *requires* right to left processing of arguments; it's just the only practical way to do it (especially given the evolution of C as it didn't have prototypes in the early days, so any function *could* be varargs).
Erik Eidt
CC BY-SA 4.0
2024-05-13T12:41:02.977Z
I don't think the parser changes for C vs. Pascal re: processing direction of arguments.  I'd write them both the same, just read text/tokens from input stream and build AST.
Erik Eidt
CC BY-SA 4.0
2024-05-13T14:33:14.080Z
I can't think of any way to *parse* an argument list from right-to-left, unless the whole language is parsed from right-to-left. How do you know where the end of the argument list is, to start parsing backwards from there, without first parsing forwards to find the closing parenthesis for the function call? Then once you find it, how do you know where the last argument *begins* so you can parse the expression from there?
kaya3
CC BY-SA 4.0
2024-05-13T19:47:06.863Z
What does variable-length argument lists have to do with the order of processing during parsing?
Barmar
<p>Neither because the argument list gets parsed the same way and stored into a list for later processing.</p>
<p>Only if you do a single pass compiler (interleaving parsing and code gen) is left to right better because then you don't need to store the previous argument expressions on a stack for later processing.</p>
<p>However as soon as you store the entire thing in some data structure it does not matter.</p>

CC BY-SA 4.0
2024-05-13T13:45:12.150Z
2024-05-13T13:45:12.150Z
ratchet freak
# From a parsing perspective, which is more efficient? Right-to-left or left-to-right argument parsing?
Posted by: username_0 on 2024-05-13
C (and other languages which allow variable argument lists) process function arguments from right-to-left.

Pascal (and other languages with fixed-length argument lists) process function arguments from left-to-right.

From a *parsing* perspective, which is more efficient?
**Tags:** parsing
> **Comments:**
> **username_1**: I don't think that the C language *requires* right to left processing of arguments; it's just the only practical way to do it (especially given the evolution of C as it didn't have prototypes in the early days, so any function *could* be varargs).  
> **username_1**: I don't think the parser changes for C vs. Pascal re: processing direction of arguments.  I'd write them both the same, just read text/tokens from input stream and build AST.  
> **username_2**: I can't think of any way to *parse* an argument list from right-to-left, unless the whole language is parsed from right-to-left. How do you know where the end of the argument list is, to start parsing backwards from there, without first parsing forwards to find the closing parenthesis for the function call? Then once you find it, how do you know where the last argument *begins* so you can parse the expression from there?  
> **username_3**: What does variable-length argument lists have to do with the order of processing during parsing?  
---
## 1 answers
### Answer by username_4 on 2024-05-13. Score: 4
Neither because the argument list gets parsed the same way and stored into a list for later processing.

Only if you do a single pass compiler (interleaving parsing and code gen) is left to right better because then you don't need to store the previous argument expressions on a stack for later processing.

However as soon as you store the entire thing in some data structure it does not matter.
---
