Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2474
| From | "Ev. Drikos" <drikosev@gmail.com> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: Languages with optional spaces |
| Date | 2020-03-01 19:41 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <20-03-003@comp.compilers> (permalink) |
| References | <20-02-015@comp.compilers> <20-02-017@comp.compilers> <20-02-033@comp.compilers> <20-02-034@comp.compilers> |
On 29/02/2020 21:38, Ev. Drikos wrote:
> On 29/02/2020 11:48, Christopher F Clark wrote:
> ...
> Obviously, those who coded such BASIC parsers had some simpler rules,
> ie the position of the first 'TO' might be used for the statement 50.
>
Dear Mr. Clark,
I'll elaborate a little if you don't mind. IMHO, one problem here is
that an identifier before a keyword is quite difficult for a scanner.
One could possibly let the parser recognize such obscure identifiers.
Let's assume that the first 'TO' found in a for-statement after a '='
is the keyword that separates the lower bound from the upper bound of
the loop index.
As a demo example, the simplified grammar at the end of this message
fails to parse only the last statement (999) below, which looks like
a known limitation of my Simulator. An actually generated C++ parser
would need some time and effort that currently I don't plan to spend:
10 let i=1
11 letleti=1
20 i=1
30 for forj=1 to n
40 FORFORJ=1TON
50 FOR N = ITOJTOK
60 FORFORJ=IIITONTOJ
70 FORFORJ=TO TO TO
80 FORFORJ=TTTON
999 FORFORJ=TOTON
Of course, this is far away from a working solution because one needs
to know a lot of details, ie if any spaces read are indeed important.
What would you suggest apart a hand coded lexer?
Ev. Drikos
----------------------------------------------------------------------
SYNTAX RULES
----------------------------------------------------------------------
#sma <id>
#sma <idl>
#sma TO
<grm> ::=
<statements>
<statements> ::=
<statements> <statement>
| <statement>
<statement> ::=
<for-stmt>
| <assignment>
| <empty>
<for-stmt> ::=
<label> FOR <id> = <lbound> TO <ubound> <;>
<lbound> ::=
<number>
| <id-p>
<id-p> ::=
<id-p> <id-part>
| <id-start>
<id-part> ::=
<letter>
| <digit>
| $
<id-start> ::=
<letter>
<ubound> ::=
<rhs>
<rhs> ::=
<id>
| <number>
<assignment> ::=
<label> LET <id> = <rhs> <;>
| <label> <idl> = <rhs> <;>
<empty> ::=
<;>
----------------------------------------------------------------------
LEXICAL CONVENTIONS
----------------------------------------------------------------------
#ignore spaces
#sma <id>
#sma <idl>
token ::=
spaces
| END
| FOR
| LET
| NEXT
| PRINT
| TO
| <digit>
| <label>
| <number>
| <letter>
| <idl>
| <id>
| $
| =
| <;>
spaces ::=
{ \t | \s }...
END ::=
E N D
FOR ::=
F O R
LET ::=
L E T
NEXT ::=
N E X T
PRINT ::=
P R I N T
TO ::=
T O
<digit> ::=
0 .. 9
<label> ::=
{ 0 .. 9 }...
<number> ::=
{ 0 .. 9 }...
<letter> ::=
A .. Z
<idl> ::=
{ A .. Z [{$|A .. Z|0..9}...]} -= {key[{$|A..Z|0..9}...]}
key ::=
END
| FOR
| LET
| NEXT
| PRINT
<id> ::=
A .. Z [ { $ | A .. Z | 0 .. 9 }... ]
<;> ::=
;
| \n
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
Languages with optional spaces Maury Markowitz <maury.markowitz@gmail.com> - 2020-02-19 07:35 -0800
Re: Languages with optional spaces Jerry <awanderin@gmail.com> - 2020-02-20 23:38 -0700
Re: Languages with optional spaces Maury Markowitz <maury.markowitz@gmail.com> - 2020-02-25 06:13 -0800
Re: Languages with optional spaces awanderin <awanderin@gmail.com> - 2020-02-26 10:03 -0700
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-03-12 17:45 +0200
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-02-23 12:33 +0200
Re: Languages with optional spaces Martin Ward <martin@gkc.org.uk> - 2020-02-25 17:00 +0000
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-02-28 13:34 +0200
Re: Languages with optional spaces Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2020-02-29 11:48 +0200
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-02-29 21:38 +0200
Re: Languages with optional spaces Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2020-03-01 10:07 +0200
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-03-01 19:41 +0200
Re: Languages with optional spaces Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2020-03-02 08:33 +0200
Re: Languages with optional spaces "Ev. Drikos" <drikosev@gmail.com> - 2020-03-02 20:04 +0200
Re: Languages with optional spaces Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2020-03-01 00:28 +0100
Re: Languages with optional spaces Maury Markowitz <maury.markowitz@gmail.com> - 2020-02-25 06:11 -0800
Re: Languages with optional spaces Kaz Kylheku <493-878-3164@kylheku.com> - 2020-02-26 08:06 +0000
Re: Languages with optional spaces and tools Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2020-02-28 20:16 +0100
Re: Languages with optional spaces gah4@u.washington.edu - 2020-03-02 21:12 -0800
Re: Languages with optional spaces Gene <gene.ressler@gmail.com> - 2020-04-14 10:08 -0700
Re: Languages with optional spaces mertesthomas@gmail.com - 2020-04-19 04:04 -0700
Re: Languages with optional spaces aston.goldsmith@gmail.com - 2020-05-05 13:05 -0700
csiph-web