Related articles |
---|
newbie: lexing and multi-character operators ajwitte@aol.com (2003-03-09) |
Re: newbie: lexing and multi-character operators Hans.Koerber@web.de (Hans =?ISO-8859-1?Q?K=F6rber?=) (2003-03-14) |
From: | Hans =?ISO-8859-1?Q?K=F6rber?= <Hans.Koerber@web.de> |
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 |
Hallo,
Ajwitte wrote:
> I'm hand-coding (for fun :) a lexer and parser for an interpreted
mathematical
> 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
scanned.
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.
Hans
Return to the
comp.compilers page.
Search the
comp.compilers archives again.