Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Yacc & lex problem
I'd like the parser to recognize the following line :
XXX.CC = YYY.CC
How should implement the '.' ?

I tried the following :

Line:
LeftObject '.' Position EQUAL RightObject '.' Position

But the '.' is not recongnized. LeftObject is equal to "XXX.CC"
I don't want to put a token on the '.' (dot) as strings may contain dots.
How should I proceed to recognize XXX and YYY ?

THX



Report this thread to moderator Post Follow-up to this message
Old Post
Farid Benzakour
09-27-04 09:01 PM


Re: Yacc & lex problem
Farid Benzakour <farid.benzakour@karelis-systemes.com> wrote:
> I'd like the parser to recognize the following line :
> XXX.CC = YYY.CC
> How should implement the '.' ?

> I tried the following :

> Line:
> LeftObject '.' Position EQUAL RightObject '.' Position

> How should I proceed to recognize XXX and YYY ?

It's unclear what you mean. If e.g. "XXX.CC" represents a single
entity you need the lexer to recognize it and pass a single token
for it to the parser, with the "XXX" and the "CC" bits in the union
for the semantic values of the token. You could have something like
this in the parser:

%union {
struct {
const char *pre_dot;
const char *after_dot;
} r_and_l;
char *str_ptr;
}

%token <r_and_l> LeftObject RightObject
%token <str_ptr> StringObject

%%

Line:
LeftObject EQUAL RightObject   { do_something( $1, $3 ); }
;
...

And in the lexer you could use e.g. the following to detect the
tokens and split them up to be able to pass them to the parser
if necessary:

"XXX\.CC"   {
yylval.r_and_l.pre_dot = "XXX";
yylval.r_and_l.after_dot = "CC";
return LeftObject;
}

"YYY\.CC"   {
yylval.r_and_l.pre_dot = "YYY";
yylval.r_and_l.after_dot = "CC";
return RightObject;
}

'='         return EQUAL;
[\t ]+      /* drop whitespace */

> But the '.' is not recongnized. LeftObject is equal to "XXX.CC"
> I don't want to put a token on the '.' (dot) as strings may contain dots.

There won't be a dot when you pass a string to the parser - the
parser gets a single integer (token) it interprets to stand for a
string while the string (with the embedded dots) gets stored in
the union for the semantic values (as I tried to indicate with
the 'str_ptr' member above and the additional token value
'StringObject').

If, on the other hand, "XXX", "YYY" and "CC" are entities completely
on their own but you don't want to allow whitespace between e.g. the
"XXX", the dot and the "CC" you need to pass all whitespace to the
parser (as well as the dot) and allow for witespace in the syntax
wherever it is allowed. Then you would need something like this in
the parser:

Line:
WS LeftObject '.' Position WS EQUAL WS RightObject '.' Position WS
;

where WS is just used to skip over optional whitespace. In the lexer
you now would have e.g.

"XXX"      return LeftPosition;
"YYY"      return RightPosition;
"CC"       return Position;
'.'        return '.';
'='        return EQUAL;
[\t ]+     return WS;

Regards, Jens
--
\   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
\__________________________  http://www.toerring.de

Report this thread to moderator Post Follow-up to this message
Old Post
Jens.Toerring@physik.fu-berlin.de
09-27-04 09:01 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:35 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.