Path: csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Gene Newsgroups: comp.compilers Subject: Re: Languages with optional spaces Date: Tue, 14 Apr 2020 10:08:31 -0700 (PDT) Organization: Compilers Central Lines: 14 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <20-04-007@comp.compilers> References: <20-02-015@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="1286"; mail-complaints-to="abuse@iecc.com" Keywords: lex, parse Posted-Date: 14 Apr 2020 16:18:15 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <20-02-015@comp.compilers> Xref: csiph.com comp.compilers:2510 On Wednesday, February 19, 2020 at 11:24:02 AM UTC-5, Maury Markowitz wrote: > I'm trying to write a lex/yacc (flex/bison) interpreter for classic BASICs > like the original DEC/MS, HP/DG etc. ... > > The problem is that FORI part. Some BASICs allow variable names with more than > two characters, so in theory, FORI could be a variable. ... > Is there a canonical cure for this sort of problem that isn't worse than the > disease? Flex regexes alone don't have enough power. But you could add a conditional REJECT when a normal ID match has a prefix that's a keyword. (This could be made fast with a trie of that's an issue.) REJECT causes fallback to the "next best" rule, which seems to be what you want.