Re: lex question
- From: Nathan Moore <nathan.moore@xxxxxxx>
- Date: 8 Dec 2005 02:33:05 -0500
Mina Doroudi wrote:
> I am writing a parser with lex. I have some problems:
> In the definition section I define a whole bunch of stuff and I also
> used them to define other things.
> So I have
> X [something]
> and I want Y to be anything but X so when I define it like:
> Y [^{X}] it only exclude the characters '{' , '}' ,and X
> I can't find a way to exclude the definitions and use them in
> other definitions.
I don't think that there is any automatic way to do what you want unless
you can use
{X} ACTION_FOR_X
..+ ACTION_FOR_EVERYTHING_ELSE
which is not likely to work unless you are trying to match the entire
input as either X or Y.
I had to do something similar for C style comments and ended up just
drawing out several DFAs for them and then converting those to
regular expressions. It was a lot of work, and I had to go back and
fix things that I messed up a lot, but it did work.
There are things about "match anything but" for anything that is not
simply character or character class that are a lot more complicated
to compute than you would think. It's really that lex can't really
always tell what you might want it to match.
>
> Also I'm trying to set rules for Oct, but lex doesn't let me logical ORs them
> together. and I can't do ranging either ([\001-\006])
> any Idea how to parse text with Oct?
Just to be clear -- You are trying to match the characters whose values
are between 1 and 6, right? Well I don't know how to do that. Very
interesting. It would be trivial to actually do, but I just don't know
the syntax or even if there is a syntax to do it b/c they all have no
short escape like \n, \a, ....
You could do:
((\001)|(\002)|(\003)|(\004)|(\005)|(\006))
It's ugly (esp since I used a bunch of extra () so that you could use it
in the middle of something else if you wanted to.
> -Mina Doroudi (dormina@xxxxxxxxxxxxx)
I wish I was at GA Tech, but I'm down the road in Macon.
Hope I was some help,
Nathan
.
- References:
- lex question
- From: Mina Doroudi
- lex question
- Prev by Date: Re: Global versus Stack variables
- Next by Date: WANTED: One good retargettable compiler back end
- Previous by thread: lex question
- Next by thread: Re: lex question
- Index(es):
Relevant Pages
|
|