|newbie: lexing and multi-character operators email@example.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>|
|Date:||14 Mar 2003 11:31:07 -0500|
|Organization:||Wanadoo, l'internet avec France Telecom|
|Posted-Date:||14 Mar 2003 11:31:06 EST|
> 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] , while, x+++1 should be [x] [increment]
> [plus] . 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.
Return to the
Search the comp.compilers archives again.