Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.os.development > #8790
| From | "James Harris" <james.harris.1@gmail.com> |
|---|---|
| Newsgroups | alt.os.development |
| Subject | Re: C parser ramblings, language design, etc |
| Date | 2015-09-13 19:02 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <mt4dje$5l3$1@dont-email.me> (permalink) |
| References | <op.x4tmp0ssyfako5@localhost> <mt16t1$bsu$1@dont-email.me> <op.x4wcoua0yfako5@localhost> |
"Rod Pemberton" <boo@fasdfrewar.cdm> wrote in message
news:op.x4wcoua0yfako5@localhost...
> On Sat, 12 Sep 2015 08:49:21 -0400, James Harris
> <james.harris.1@gmail.com> wrote:
>
>> "Rod Pemberton" <boo@fasdfrewar.cdm> wrote in message
>> news:op.x4tmp0ssyfako5@localhost...
...
>>> do while(x--); while(x--);
...
>>> That's confusing for a human and a simple parser. It could be
>>> recognized by both as either of these:
>>>
>>> do { while(x--); } while(x--);
>>> do {} while (x--); while(x--);
>>>
>>> Which 'while' goes with the 'do'? Only the first one is correct,
>>> but how do you determine that from the braceless syntax above?
>>> You get a 'while' prior to the 'while' you need.
>>
>> This should be easy for a compiler, IMO, as long as the compiler is
>> properly written. I say that because a compiler will work forward a
>> symbol at a time.
>
> Yes, 'long' then forward to another symbol 'long' ...
>
> Where is the "long long"? ;-) I.e., the two 'longs' must be
> combined in the AST, perhaps? This would've been easier to
> parse with one keyword.
A number of C types can be expressed by multiple keywords:
signed char
unsigned long
long double
And those can have qualifiers such as const and static and auto etc.
That's just something the compiler has to live with.
>> After
>>
>> do
>>
>> the compiler will expect a statement. Note, a statement, not a
>> {compound
>> statement}. Only *after* the statement will it expect a while clause.
>> What the compiler should look for, then, is
>>
>> DO statement WHILE '(' expression ')' ';'
>>
>> (That is from the link I will place at the end.)
>>
>> As long as it sees a recognisable *statement* it will accept it, even
>> if
>> that statement is a while loop. Easy.
>
> That works for grammar based parsers. That make not work
> for others which might detect a 'while' too early, without
> an easy way to track scope level, such as braces for a compound
> statement. They would need a method to track and pair do's
> and while's correctly. Solutions like counters and flags
> might not work, i.e., may need stack or state-machine.
There are areas where parsing C is difficult but this isn't one of them.
Consider a typical simple hand-written parser which includes the
following code.
if (token == DO) {
skip(); /* Skip the DO keyword */
statement_parse(); /* Parse the statement following DO */
if (token != WHILE) { /* Check for WHILE keyword */
.... exception handling code ....
} else {
skip(); /* Skip the WHILE keyword */
require(LPAREN);
expression_parse();
require(RPAREN);
etc.
In case it's not obvious the check (token != WHILE) on the fourth line
only takes place *after* statement_parse() returns. As such it would
find the *second* "while" in your example. The first "while" validly
begins a statement so it would be recognised in statement_parse() and
your example would parse properly and all without any special effort on
the part of the parser writer. I cannot understand why you think that is
hard to parse. You have mentioned a simple parser a few times. If you
still think there's a problem perhaps you can say what you mean by a
simple parser and why would it not parse the example as naturally as the
code above.
James
Back to alt.os.development | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-11 19:11 -0400
Re: C parser ramblings, language design, etc "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-12 05:10 -0700
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 04:41 -0400
Re: C parser ramblings, language design, etc "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 02:37 -0700
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 07:20 -0400
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-13 18:37 +0100
Re: C parser ramblings, language design, etc "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 21:03 -0700
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-12 13:49 +0100
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 06:27 -0400
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-13 19:02 +0100
Re: C parser ramblings, language design, etc "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 15:10 -0700
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 20:30 -0400
Re: C parser ramblings, language design, etc "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 20:07 -0700
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-14 22:29 +0100
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-20 18:48 -0400
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-22 20:04 +0100
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-30 20:32 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2015-12-27 13:51 +0000
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-12-27 17:35 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-16 17:09 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-16 14:30 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-16 21:40 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-18 07:34 -0500
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-18 08:37 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-18 23:35 +0000
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-19 12:52 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-19 13:09 +0000
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-19 21:46 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-21 11:15 +0000
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-21 21:48 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-22 15:16 +0000
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-22 23:02 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-01-23 17:04 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-27 15:27 +0000
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-02-29 09:26 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-02-29 19:02 +0000
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-03-02 20:48 +0000
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-03-09 22:29 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-03-17 16:41 +0000
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-03-29 09:00 +0200
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-03-09 22:29 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-03-17 17:36 +0000
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-03-29 09:01 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-02 10:13 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-04-10 19:33 +0200
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-04-15 16:27 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-26 08:10 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-03 20:14 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-04 09:17 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-21 21:10 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-29 08:44 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-29 12:05 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-29 12:28 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-06-01 19:22 +0200
OT: Obama in the UK (was: C parser ramblings, language design, etc) James Harris <james.harris.1@gmail.com> - 2016-04-26 08:46 +0100
Re: OT: Obama in the UK (was: C parser ramblings, language design, etc) Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-26 23:58 -0400
Re: OT: Obama in the UK (was: C parser ramblings, language design, etc) Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 00:08 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-04-27 06:40 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 05:25 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-04-27 17:45 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 18:25 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-02 23:44 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-03 16:56 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-04 09:23 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-04 17:22 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-06 11:47 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-06 19:34 -0400
Re: OT: Obama in the UK "James Harris" <james.harris.1@gmail.com> - 2016-05-07 12:51 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-07 19:20 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-08 01:46 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-07 21:43 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-08 09:36 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-08 15:34 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-10 11:25 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-10 17:32 -0400
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-10 18:25 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-15 00:06 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-07 21:32 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-06-02 07:41 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-06-02 16:21 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-20 14:59 +0100
Re: OT: Obama in the UK "wolfgang kern" <nowhere@never.at> - 2016-05-20 21:13 +0200
Re: OT: Obama in the UK "wolfgang kern" <nowhere@never.at> - 2016-05-20 21:17 +0200
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-21 08:04 +0100
Re: OT: Obama in the UK Bernhard Schornak <schornak@web.de> - 2016-05-21 21:10 +0200
Re: OT: Obama in the UK "wolfgang kern" <nowhere@never.at> - 2016-05-21 11:16 +0200
Re: OT: Obama in the UK Bernhard Schornak <schornak@web.de> - 2016-05-21 21:11 +0200
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-20 22:51 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-21 07:29 +0100
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-06-02 08:33 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-06-02 16:21 -0400
UK pronunciation was, [Re: OT: Obama in the UK, was C lang parser ramblings] Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-06-11 14:34 -0400
Re: UK pronunciation was, [Re: OT: Obama in the UK, was C lang parser ramblings] James Harris <james.harris.1@gmail.com> - 2016-07-24 18:28 +0100
Re: UK pronunciation was, [Re: OT: Obama in the UK, was C lang parser ramblings] Rod Pemberton <NoHaveNotOne@bcczxcfrze.cam> - 2016-07-25 21:54 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-07-24 18:21 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfrze.cam> - 2016-07-25 21:54 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-07-26 10:02 +0100
Re: OT: Obama in the UK Rod Pemberton <NoHaveNotOne@bcczxcfrze.cam> - 2016-07-26 07:56 -0400
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-07-30 12:26 +0100
Re: OT: Obama in the UK Bernhard Schornak <schornak@web.de> - 2016-05-03 20:14 +0200
Re: OT: Obama in the UK James Harris <james.harris.1@gmail.com> - 2016-05-04 09:25 +0100
Re: OT: Obama in the UK Bernhard Schornak <schornak@web.de> - 2016-05-21 21:11 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-26 07:59 +0100
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 00:01 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-27 09:28 +0100
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 05:42 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-27 17:16 +0100
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-04-27 18:05 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-27 09:29 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-04-27 09:42 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-03 20:14 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-07 14:34 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-21 21:10 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-29 11:27 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-06-01 19:22 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-07 16:34 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-05-21 21:10 +0200
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-05-29 12:10 +0100
Re: C parser ramblings, language design, etc Bernhard Schornak <schornak@web.de> - 2016-06-01 19:22 +0200
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-25 18:29 -0500
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-26 11:47 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-27 17:08 +0000
Re: C parser ramblings, language design, etc "wolfgang kern" <nowhere@never.at> - 2016-01-28 11:54 +0100
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-28 11:47 +0000
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-21 10:13 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-25 18:29 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-27 17:15 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-27 17:31 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-28 11:07 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-19 22:28 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-22 15:04 +0000
Re: C parser ramblings, language design, etc Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-25 17:48 -0500
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2016-01-27 17:16 +0000
Re: cows and bulls game, was [Re: C parser ramblings, language design, etc] "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-12-27 21:19 -0500
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-30 20:32 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2015-10-05 15:13 +0100
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-10-05 21:56 -0400
Re: C parser ramblings, language design, etc James Harris <james.harris.1@gmail.com> - 2015-12-27 13:56 +0000
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-10-21 19:46 -0400
Re: C parser ramblings, language design, etc "James Harris" <james.harris.1@gmail.com> - 2015-09-12 15:38 +0100
Re: C parser ramblings, language design, etc "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 07:10 -0400
Re: C parser ramblings, language design, etc "s_dubrovich@yahoo.com" <s_dubrovich@yahoo.com> - 2015-11-01 09:07 -0800
csiph-web