Re: Newbie parsing a simple bespoke language questions

"Chris Morley" <>
Wed, 12 Dec 2007 19:25:22 -0000

          From comp.compilers

Related articles
Newbie parsing a simple bespoke language questions (Chris Morley) (2007-12-10)
Re: Newbie parsing a simple bespoke language questions (Chris Morley) (2007-12-12)
| List of all articles for this month |

From: "Chris Morley" <>
Newsgroups: comp.compilers
Date: Wed, 12 Dec 2007 19:25:22 -0000
Organization: Zen Internet
References: 07-12-034
Keywords: parse, errors
Posted-Date: 12 Dec 2007 23:17:07 EST

> [My advice is invariably to have the parser accept a larger language
> and do the type checking in your semantic code. That lets you
> produce useful error messages like "foo command requires two
> integers" rather than a generic syntax error. -John]

Humm... With %error-verbose you easily get "got integer expected
float" type messages but that is about the limit I guess without
jumping through too many hoops. Thanks. I have chosen the generic
parse + semantic check route now.

I need to parse fixed point numbers as well as integers. Is it better
to do things like this in the scanner & return a FP token + value or
make some rules and parse as 2 ints & '.'? (my scanner dumps all
whitespace between tokens at the moment so "123 . 456" is legal... but
I can fix that...) Is one way good/bad form?

Also is it bad form to use hints from the parser state to decipher
tokens (I have seen some webpages describing how to do this) -
e.g. for flag lookup "/f", change lookup from identifier string table
to flag string table to tokenise f after a '/'?

[Scanning floats can be surprisingly ugly, particularly if you allow
Fortran style 12.3E+4 exponents. I'd do it in the lexer. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.