Re: question about linker

Liste des GroupesRevenir à cl c 
Sujet : Re: question about linker
De : cr88192 (at) *nospam* gmail.com (BGB)
Groupes : comp.lang.c
Date : 04. Dec 2024, 20:21:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <viqa4g$124jc$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Mozilla Thunderbird
On 12/4/2024 10:49 AM, Scott Lurndal wrote:
BGB <cr88192@gmail.com> writes:
On 12/3/2024 1:27 PM, Janis Papanagnou wrote:
On 03.12.2024 19:57, BGB wrote:
On 12/2/2024 12:13 PM, Scott Lurndal wrote:
>
Indeed.  One wonders at Bart's familiarity with formal grammars.
>
In my case, personally I haven't encountered much that doesn't work well
enough with a recursive-descent parser.
>
Is that meant as a contradiction? - If so, how?
>
>
Formal grammars and parser generators aren't usually necessary IME,
since recursive descent can deal with most everything (and is generally
more flexible than what one can deal with in a formal grammar).
 How can you write a correct recursive descent parser without a
formal grammar (at least on paper) for the language being parsed?
 
It is usually a thing of pattern matching the next N tokens, based on the structure of the language.
You can write or reference a syntax in BNF or EBNF or similar, but it is not necessary, and some languages (like C) may contain things that can't be fully expressed via an BNF (say, for example, things that depend on prior typedefs, etc).
One doesn't necessarily need a BNF though, if a bunch of syntax examples exist and the syntactic rules are sufficiently obvious.
If designing a language, granted, better to avoid having a bunch of obvious "gotchas" (such as tricky edge cases or ambiguities).
With parsing C, 2 tokens works well. Some other languages may only need a single token at a time.
Sometimes, a path can "fail" (and return NULL) if something is encountered that does not match an expected pattern. Then you go down the next path and see if this parses.
For example, for every statement, one can first try to parse a declaration, and if the declaration fails, then one can try to parse an "inner statement" and if this fails to find anything, try to parse an expression.
And, in expression parsing, if one encounters an '(' in prefix position, one may need to check if the following token(s) can be parsed as a type, if true, assume we are looking at a cast, if false, assume an expression. On the other side, if one encounters a '(' where one might expect a binary operator, it can be assumed to be a function call.
Where, say, one of the main fail paths in a C parser being "can the following tokens be parsed as a type?" (which does often have the overhead of effectively causing nearly every identifier to need to be checked if it is identifying a previous typedef).
One can eliminate the "path failed" scenario, but then the language may end up looking more like JavaScript or similar (needing things like 'var'/'function' keywords, or "EXPR as TYPE" for casts, ...). Or, eliminate checking for typedefs, at which point it might look more like C# (where "foo bar;" at a statement-level will always be assumed to be a declaration, and one is otherwise forbidden to have identifier-identifier pairs in this context).
In some of my previous languages, there was a "feature" where the last statement in a function could be an expression lacking a semicolon, and it would be understood as an implicit return:
   function foo(x, y) { var z=x*y; 2*z-y }
But, this has the downside of creating an ambiguity where one doesn't necessarily know whether the final statement is a tail expression until after being able to observe its lack of a semicolon.
Or, alternatively, using the fail-path strategy and requiring all other cases (which could potentially be mistaken for a tail expression) to have a semicolon:
   foo* bar;  //declaration, implicitly mandates the semicolon.
My last significant original language (BS2, nearly a decade ago now) had instead required the use of a 'return' statement (where BS2 was meant to simplify and clean up a lot of the painful cases in its predecessor; essentially going from a weird JavaScript variant to something more like a Java/C# hybrid). This language has not seen much use though, as my recent projects have mostly used C.
...
There is some variation for how to deal with input and tokens:
   Early parsers (still used in my C parser):
     "char **" pointer gives the input position;
     Token reading function takes an input position,
       fills in a buffer supplied by the caller;
       sets a token-type (pointer argument);
       Returns the next position.
   Had later tried a different strategy (short lived):
     Break entire input buffer into an array of token strings;
       Each token string encoded its token-type as a prefix character.
     This strategy works OK for small things, but did not scale well.
   More recent strategy:
     Read a token, passing a "char **" string;
     Called function advances the pointer to the next token;
     Returns a token, with the type as a prefix character.
       The token is held in a temporary circular buffer.
In the first tokenizer strategy, a temporary lookup table would be kept mapping input-string positions to previous tokens (with the length and type), reducing the cost of trying to read the same tokens again. Calling the tokenizer function with a NULL input clears this table (say, if one is reusing the same buffer multiple times and rewriting its contents each time, such as in a preprocessor).
The third strategy can also use a similar lookup table. This can reduce how quickly the circular buffer wraps around. But, if one wants to hold onto a token for later use, it is necessary to copy it somewhere else (if too many tokens are read, the memory for previous tokens will be silently overwritten).
Say, for example:
   foo ( 123 "test" )
Might give token strings:
   "Ifoo", "X(", "|123", "Stest", "X)"
...

Date Sujet#  Auteur
26 Nov 24 * question about linker383Thiago Adams
26 Nov 24 +* Re: question about linker16Thiago Adams
26 Nov 24 i`* Re: question about linker15Bart
26 Nov 24 i `* Re: question about linker14Thiago Adams
27 Nov 24 i  +* Re: question about linker2BGB
27 Nov 24 i  i`- Re: question about linker1Bart
27 Nov 24 i  +* Re: question about linker5David Brown
27 Nov 24 i  i`* Re: question about linker4Thiago Adams
27 Nov 24 i  i +* Re: question about linker2David Brown
27 Nov 24 i  i i`- Re: question about linker1Thiago Adams
2 Dec 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker6Michael S
27 Nov 24 i   `* Re: question about linker5Thiago Adams
27 Nov 24 i    `* Re: question about linker4Michael S
27 Nov 24 i     +- Re: question about linker1David Brown
28 Nov 24 i     +- Re: question about linker1Tim Rentsch
2 Dec 24 i     `- Re: question about linker1BGB
26 Nov 24 +* Re: question about linker20Bart
26 Nov 24 i`* Re: question about linker19Thiago Adams
26 Nov 24 i `* Re: question about linker18Bart
27 Nov 24 i  +* Re: question about linker3BGB
27 Nov 24 i  i`* Re: question about linker2fir
27 Nov 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker14Bart
27 Nov 24 i   +* Re: question about linker12Thiago Adams
27 Nov 24 i   i+- Re: question about linker1Thiago Adams
27 Nov 24 i   i`* Re: question about linker10Bart
27 Nov 24 i   i +* Re: question about linker6Bart
27 Nov 24 i   i i`* Re: question about linker5Thiago Adams
27 Nov 24 i   i i +* Re: question about linker3Thiago Adams
27 Nov 24 i   i i i`* Re: question about linker2Thiago Adams
27 Nov 24 i   i i i `- Re: question about linker1Bart
27 Nov 24 i   i i `- Re: question about linker1Bart
27 Nov 24 i   i `* Re: question about linker3Thiago Adams
27 Nov 24 i   i  `* Re: question about linker2Bart
27 Nov 24 i   i   `- Re: question about linker1Thiago Adams
28 Nov 24 i   `- Re: question about linker1Tim Rentsch
27 Nov 24 `* Re: question about linker346Waldek Hebisch
27 Nov 24  `* Re: question about linker345Thiago Adams
28 Nov 24   `* Re: question about linker344Keith Thompson
28 Nov 24    `* Re: question about linker343Thiago Adams
28 Nov 24     +* Re: question about linker338Bart
28 Nov 24     i`* Re: question about linker337Keith Thompson
28 Nov 24     i `* Re: question about linker336Bart
28 Nov 24     i  `* Re: question about linker335Keith Thompson
29 Nov 24     i   `* Re: question about linker334Bart
29 Nov 24     i    +* Re: question about linker3Keith Thompson
29 Nov 24     i    i`* Re: question about linker2Bart
29 Nov 24     i    i `- Re: question about linker1Keith Thompson
29 Nov 24     i    `* Re: question about linker330David Brown
29 Nov 24     i     `* Re: question about linker329Bart
29 Nov 24     i      +- Re: question about linker1Ike Naar
29 Nov 24     i      +* Re: question about linker326Michael S
29 Nov 24     i      i+* Re: question about linker323Bart
29 Nov 24     i      ii`* Re: question about linker322Michael S
29 Nov 24     i      ii +* Re: question about linker320David Brown
29 Nov 24     i      ii i`* Re: question about linker319Bart
29 Nov 24     i      ii i +* Re: question about linker165Keith Thompson
29 Nov 24     i      ii i i`* Re: question about linker164Bart
30 Nov 24     i      ii i i `* Re: question about linker163Keith Thompson
30 Nov 24     i      ii i i  +* Re: question about linker95Waldek Hebisch
30 Nov 24     i      ii i i  i+- Re: question about linker1Keith Thompson
30 Nov 24     i      ii i i  i+* Re: question about linker3James Kuyper
30 Nov 24     i      ii i i  ii`* Re: question about linker2Michael S
3 Dec 24     i      ii i i  ii `- Re: question about linker1Tim Rentsch
1 Dec 24     i      ii i i  i`* Re: question about linker90David Brown
1 Dec 24     i      ii i i  i +* Re: question about linker88Bart
1 Dec 24     i      ii i i  i i`* Re: question about linker87David Brown
1 Dec 24     i      ii i i  i i `* Re: question about linker86Bart
2 Dec 24     i      ii i i  i i  `* Re: question about linker85David Brown
2 Dec 24     i      ii i i  i i   `* Re: question about linker84Bart
2 Dec 24     i      ii i i  i i    +* Re: question about linker78David Brown
2 Dec 24     i      ii i i  i i    i+* Re: question about linker72Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii+* Re: question about linker70Bart
2 Dec 24     i      ii i i  i i    iii+* Re: question about linker68David Brown
2 Dec 24     i      ii i i  i i    iiii`* Re: question about linker67Bart
3 Dec 24     i      ii i i  i i    iiii `* Re: question about linker66David Brown
3 Dec 24     i      ii i i  i i    iiii  +* Re: question about linker53Bart
3 Dec 24     i      ii i i  i i    iiii  i`* Re: question about linker52David Brown
3 Dec 24     i      ii i i  i i    iiii  i `* Re: question about linker51Bart
4 Dec 24     i      ii i i  i i    iiii  i  `* Re: question about linker50David Brown
4 Dec 24     i      ii i i  i i    iiii  i   `* Re: question about linker49Bart
4 Dec 24     i      ii i i  i i    iiii  i    `* Re: question about linker48David Brown
4 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker24Bart
5 Dec 24     i      ii i i  i i    iiii  i     i`* Re: question about linker23David Brown
5 Dec 24     i      ii i i  i i    iiii  i     i +- Re: question about linker1Janis Papanagnou
5 Dec 24     i      ii i i  i i    iiii  i     i `* Re: question about linker21Bart
6 Dec 24     i      ii i i  i i    iiii  i     i  `* Re: question about linker20David Brown
6 Dec 24     i      ii i i  i i    iiii  i     i   `* Re: question about linker19Bart
6 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker5Ike Naar
6 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker2Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker10David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker9Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `* Re: question about linker8David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i  `* Re: question about linker7Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i   `* Re: question about linker6David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i    `* Re: question about linker5Bart
8 Dec 24     i      ii i i  i i    iiii  i     i    i     +* Re: question about linker3Ben Bacarisse
8 Dec 24     i      ii i i  i i    iiii  i     i    i     `- Re: question about linker1David Brown
8 Dec 24     i      ii i i  i i    iiii  i     i    `* Re: question about linker3Waldek Hebisch
5 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker15Waldek Hebisch
11 Dec 24     i      ii i i  i i    iiii  i     `* Re: question about linker8James Kuyper
3 Dec 24     i      ii i i  i i    iiii  `* Re: question about linker12Bart
3 Dec 24     i      ii i i  i i    iii`- Re: question about linker1Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii`- Re: question about linker1Bart
2 Dec 24     i      ii i i  i i    i`* Re: question about linker5Bart
4 Dec 24     i      ii i i  i i    `* Re: question about linker5Waldek Hebisch
1 Dec 24     i      ii i i  i `- Re: question about linker1Janis Papanagnou
30 Nov 24     i      ii i i  +* Re: question about linker44Bart
30 Nov 24     i      ii i i  +- Re: question about linker1Janis Papanagnou
1 Dec 24     i      ii i i  `* Re: question about linker22David Brown
30 Nov 24     i      ii i `* Re: question about linker153David Brown
5 Dec 24     i      ii `- Re: question about linker1Tim Rentsch
30 Nov 24     i      i`* Re: question about linker2Tim Rentsch
29 Nov 24     i      `- Re: question about linker1David Brown
28 Nov 24     `* Re: question about linker4Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal