Re: newbie: lexing and multi-character operators

Hans =?ISO-8859-1?Q?K=F6rber?= <>
14 Mar 2003 11:31:07 -0500

          From comp.compilers

Related articles
newbie: lexing and multi-character operators (2003-03-09)
Re: newbie: lexing and multi-character operators (Hans =?ISO-8859-1?Q?K=F6rber?=) (2003-03-14)
| List of all articles for this month |

From: Hans =?ISO-8859-1?Q?K=F6rber?= <>
Newsgroups: comp.compilers
Date: 14 Mar 2003 11:31:07 -0500
Organization: Wanadoo, l'internet avec France Telecom
References: 03-03-038
Keywords: lex
Posted-Date: 14 Mar 2003 11:31:06 EST


Ajwitte wrote:
  > I'm hand-coding (for fun :) a lexer and parser for an interpreted
  > language. Somewhat like Mathematica, only *much* simpler. My
  > question is, how does one deal with multi-character operators (for
  > example, ++ [increment])? For example, x++1 should be understood as
  > [x] [plus] [unary plus] [1], while, x+++1 should be [x] [increment]
  > [plus] [1]. At what stage of the translation should this distinction
  > be made?

++ is a multi-character operator that has actually another operator + as
prefix, thus the ambiguity. You cannot decide which operator + or ++ to
use, in the first example x++1 that you give above, until the 1 has been

Until there your scanner must keep track of both alternatives, [x]
[incr] and [x] [plus] [unary plus]. With the grammar I have in mind, the
former alternative will be ruled out, during the syntax analysis phase.


Post a followup to this message

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