Re: a token scanner DFA for indirection operator * ?

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
3 Apr 2004 09:12:08 -0500

          From comp.compilers

Related articles
a token scanner DFA for indirection operator * ? rgesell@mb.sympatico.ca (RonG) (2004-03-26)
Re: a token scanner DFA for indirection operator * ? alexc@std.com (Alex Colvin) (2004-04-03)
Re: a token scanner DFA for indirection operator * ? vbdis@aol.com (2004-04-03)
Re: a token scanner DFA for indirection operator * ? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2004-04-03)
Re: a token scanner DFA for indirection operator * ? casse@netcourrier.fr (=?ISO-8859-1?Q?Cass=E9_Hugues?=) (2004-04-15)
| List of all articles for this month |
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Newsgroups: comp.compilers
Date: 3 Apr 2004 09:12:08 -0500
Organization: Compilers Central
References: 04-03-102
Keywords: lex
Posted-Date: 03 Apr 2004 09:12:08 EST

On 26 Mar 2004 22:38:44 -0500, RonG <rgesell@mb.sympatico.ca> wrote:


>I'm trying to write a token scanner for C, and I'm wondering if there is a
>detrministic finite automata (DFA) or state machine for the '*'
>indirection operator(IOP), or if differentiation between the multiply
>operator and the IOP is better left to the parser. Right now my scanner
>keeps track of the previous token and also has a lookahead char. My
>biggest problem occurs when the previous token is a right parenthesis. In
>this case, the parenthesis can enclolse:
>1.an expression ( in which case '*' is the multiply operator )
>2.a boolean expressian after an 'if' or 'while' ( in which case '*', if
> followed by an alphabetic char or underscore, is an IOP )
>3.the conditions for a 'for' statement.
>
>I imagine that I could have a flag variable telling me whether the
>previous right parenthesis token closed an arithmetic expression, but I
>was wondering if I was overlooking something.
>Is it possible to determine '*' with just the previous token and a
>lookahead char, or do I need to introduce a flag?


Whether "*" is an unary or dyadic operator depends on the context. You
can keep track on its switching:


prefix context ->
operand (= literal/identifier) ->
postfix context ->
infix context (dyadic operator, comma) ->
prefix context ->
...


When "*" appears in the prefix context, then it is an unary prefix
operator, when it does in the infix context, then it is a dyadic
operator and so on.


>thanks in advance
>Ron Gesell
>
>PS. I haven't looke at it yet, but I suspect the same situation can arise
>with '&'.
>[I think your life will be a lot easier if you interpret the tokens in
>the parser, not the lexer. -John]


Yes, when both lexer and parser are integrated in one.


--
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de


Post a followup to this message

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