Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2942

Re: What stage should entities be resolved?

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: What stage should entities be resolved?
Date 2022-03-18 14:08 -0700
Organization Compilers Central
Message-ID <22-03-040@comp.compilers> (permalink)
References <22-03-019@comp.compilers> <22-03-025@comp.compilers> <22-03-032@comp.compilers> <22-03-037@comp.compilers>

Show all headers | View raw


On Friday, March 18, 2022 at 11:00:40 AM UTC-7, Kaz Kylheku wrote:

> So to answer the questions, if you're assuming that you're going to be
> using the traditional framework, with a regular-expression-driven
> lexer and a LR parser with 1 token of lookahead, the way you divide
> the work, roughly, is by identifying the token-like elements in the
> language that have regular syntax. Anything that exhibits nesting,
> requiring rule recursion, will be farmed off to the parser. Your
> decision could sometimes also be informed by the lookahead concern;
> you could choose to clump together several items that might plausibly
> be individual tokens into a "supertoken" if there is some parsing
> advantage in it, or other simplification.

Besides simplifying parsing, it also makes better error messages.

For one, if it has a whole token, the message can indicate that.

> Other kinds of decisions interact with the language definition.
> For instance, what is -1234? In Common Lisp, and most other Lisp
> dialect, I suspect, that is a token denoting a negative integer.
> It may not be written - 1234. In C, and languages imitating its syntax,
> -1234 is a unary expression: the unary - operator applied to the
> integer 1234, and so there are two tokens. They may be separated
> by whitespace, or a comment.

> This strikes at the language definition, becuase what it implies is
> that C does not have negative constants.

It gets more interesting in Fortran.

Fortran mostly doesn't have signed constants, so it would be a unary
expression, except that there are some places where constants are allowed
and not expressions, so in those cases it allows for signed constants.

The most important one, and maybe only one left, is the DATA statement.

Well, it used to be that constants and variables, but not expressions, were
allowed for DO statements, but then again it didn't even allow for 0,
and especially not negative constants.

I suspect, though, that even though DATA statements are defined to have
signed constants, that the parser can allow unary expressions and not
tell anyone.  Well, it might affect error messages, too.

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? Roger L Costello <costello@mitre.org> - 2022-03-09 17:22 +0000
  Re: What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-10 09:48 +0100
    Re: What stage should entities be resolved? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-12 14:11 +0200
      Re: What stage should entities be resolved? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-14 19:43 +0100
    Re: What stage should entities be resolved? Roger L Costello <costello@mitre.org> - 2022-03-15 11:49 +0000
      Re: What stage should entities be resolved? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-18 00:31 +0100
      Re: What stage should entities be resolved? gah4 <gah4@u.washington.edu> - 2022-03-17 17:06 -0700
      Re: What stage should entities be resolved? Kaz Kylheku <480-992-1380@kylheku.com> - 2022-03-18 17:50 +0000
        Re: What stage should entities be resolved? gah4 <gah4@u.washington.edu> - 2022-03-18 14:08 -0700
        Re: What stage should entities be resolved? Martin Ward <martin@gkc.org.uk> - 2022-03-19 18:17 +0000
      Re: What stage should entities be resolved? "matt.ti...@gmail.com" <matt.timmermans@gmail.com> - 2022-03-20 07:32 -0700
  RE: What stage should entities be resolved? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-10 12:54 +0200
  Re: What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? matt.timmermans@gmail.com - 2022-03-12 05:12 -0800

csiph-web