|a token scanner DFA for indirection operator * ? firstname.lastname@example.org (RonG) (2004-03-26)|
|Re: a token scanner DFA for indirection operator * ? email@example.com (Alex Colvin) (2004-04-03)|
|Re: a token scanner DFA for indirection operator * ? firstname.lastname@example.org (2004-04-03)|
|Re: a token scanner DFA for indirection operator * ? email@example.com (Dmitry A. Kazakov) (2004-04-03)|
|Re: a token scanner DFA for indirection operator * ? firstname.lastname@example.org (=?ISO-8859-1?Q?Cass=E9_Hugues?=) (2004-04-15)|
|From:||"Dmitry A. Kazakov" <email@example.com>|
|Date:||3 Apr 2004 09:12:08 -0500|
|Posted-Date:||03 Apr 2004 09:12:08 EST|
On 26 Mar 2004 22:38:44 -0500, RonG <firstname.lastname@example.org> 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
>PS. I haven't looke at it yet, but I suspect the same situation can arise
>[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.
Return to the
Search the comp.compilers archives again.