help-bison
[Top][All Lists]
Advanced

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

Parsing a language with optional spaces


From: Maury Markowitz
Subject: Parsing a language with optional spaces
Date: Mon, 6 Jul 2020 12:25:56 -0400

Moving to a new thread - I was surprised I could even post, previous efforts 
were bounced from the list server for no obvious reason. Someone helpfully 
posted for me in the past. And now everything is magically working, so I hope 
you don't all mind the duplicate.

> On Jul 6, 2020, at 9:04 AM, Christian Schoenebeck <schoenebeck@crudebyte.com> 
> wrote:
> 
> You would simply add a RegEx pattern & rule like this:

Consider two snippets in home-computer-era BASIC:

FOREX=10

and:

FOREX=10TO20

Is the first one a broken FOR statement or a perfectly valid variable 
assignment? (Why not both?!) MS says the former, BBC the later.

In the lex/flex model of longest-match-wins, assuming any reasonable definition 
for your variable pattern, both statements are variable assignments and the 
second fails to parse.

To match the behaviour of BASIC, one has to complicate the variable pattern. 
"Complicate" varies between adding a tail pattern for every possible keyword, 
or artificially limiting the variables in length, or...

Is there a better way?

Ideally, I would love if there was an optional #keyword which is similar to 
#token but has a "higher priority" so they would match first. I suspect this 
would be valuable in a wide variety of tasks, but I'm completely noob so I 
can't say.

I'm happy to post my complete flex/bison to any reasonable location.

p.s. This applies to all BASIC keywords, not just FOR. Consider PRINTER="Epson 
LX-80"


reply via email to

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