9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Replacements for lex
@ 2007-01-19 18:58 Joel Salomon
  2007-01-19 19:12 ` Dan Cross
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Joel Salomon @ 2007-01-19 18:58 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Has anyone had success with lexer-generators other than lex under Plan
9?  I'm taking a compilers class this semester and I'd like to do as
much work under Plan 9 as possible.

I looked around online and found re2c, which looked interesting except
it's written in C++.

For languages sufficiently like C, is regexp(2) suitable?

--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 18:58 [9fans] Replacements for lex Joel Salomon
@ 2007-01-19 19:12 ` Dan Cross
  2007-01-19 19:26   ` Joel Salomon
  2007-01-19 19:13 ` Brantley Coile
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Dan Cross @ 2007-01-19 19:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Jan 19, 2007 at 01:58:06PM -0500, Joel Salomon wrote:
> Has anyone had success with lexer-generators other than lex under Plan
> 9?  I'm taking a compilers class this semester and I'd like to do as
> much work under Plan 9 as possible.
>
> I looked around online and found re2c, which looked interesting except
> it's written in C++.
>
> For languages sufficiently like C, is regexp(2) suitable?

I think that most people roll their own lexical analyzers under Plan 9.
That's typically not too hard to do, though.

	- Dan C.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 18:58 [9fans] Replacements for lex Joel Salomon
  2007-01-19 19:12 ` Dan Cross
@ 2007-01-19 19:13 ` Brantley Coile
  2007-01-19 19:18 ` erik quanstrom
  2007-01-20  8:44 ` William Josephson
  3 siblings, 0 replies; 13+ messages in thread
From: Brantley Coile @ 2007-01-19 19:13 UTC (permalink / raw)
  To: 9fans

My suggestion is just to write scanners by hand.  I've written dozens
and they take only a few minutes.  While a half hour seems long
compared to the speed of an automaticly generated scanner, the time
difference over the total project is quite small.  And besides.  You
want to learn how to write compilers.


> Has anyone had success with lexer-generators other than lex under Plan
> 9?  I'm taking a compilers class this semester and I'd like to do as
> much work under Plan 9 as possible.
>
> I looked around online and found re2c, which looked interesting except
> it's written in C++.
>
> For languages sufficiently like C, is regexp(2) suitable?
>
> --Joel



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 18:58 [9fans] Replacements for lex Joel Salomon
  2007-01-19 19:12 ` Dan Cross
  2007-01-19 19:13 ` Brantley Coile
@ 2007-01-19 19:18 ` erik quanstrom
  2007-01-19 19:24   ` Federico Benavento
  2007-01-20  8:44 ` William Josephson
  3 siblings, 1 reply; 13+ messages in thread
From: erik quanstrom @ 2007-01-19 19:18 UTC (permalink / raw)
  To: 9fans

take a look at the lexing in the c compiler -- /sys/src/cmd/cc/lex.c.

- erik


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 19:18 ` erik quanstrom
@ 2007-01-19 19:24   ` Federico Benavento
  0 siblings, 0 replies; 13+ messages in thread
From: Federico Benavento @ 2007-01-19 19:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

yeah, great example :)

On 1/19/07, erik quanstrom <quanstro@coraid.com> wrote:
> take a look at the lexing in the c compiler -- /sys/src/cmd/cc/lex.c.
>
> - erik
>


--
Federico G. Benavento


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 19:12 ` Dan Cross
@ 2007-01-19 19:26   ` Joel Salomon
  2007-01-19 20:35     ` C H Forsyth
  2007-01-20  8:47     ` William Josephson
  0 siblings, 2 replies; 13+ messages in thread
From: Joel Salomon @ 2007-01-19 19:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> I think that most people roll their own lexical analyzers under Plan 9.
> That's typically not too hard to do, though.

That's likely what I'll do for the final project (probably yet another
C complier, but I might try my hand with [a subset of] D), but the
professor has said he'll want us to learn to use
mechanically-generated scanners and compare the results.

I expect the lexer in /sys/src/cmd/cc/ will be a good example.

--Joel


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 19:26   ` Joel Salomon
@ 2007-01-19 20:35     ` C H Forsyth
  2007-01-19 21:06       ` erik quanstrom
  2007-01-19 21:09       ` Taj Khattra
  2007-01-20  8:47     ` William Josephson
  1 sibling, 2 replies; 13+ messages in thread
From: C H Forsyth @ 2007-01-19 20:35 UTC (permalink / raw)
  To: 9fans

>I expect the lexer in /sys/src/cmd/cc/ will be a good example.

it's a little more elaborate than some (not gcc!) because it takes on limited C preprocessing
duties as well.  you might also observe that the author enjoys his gotos, but since it is essentially
a finite state machine that seems fair enough, and furthermore he's allowed to take advantage of his
`licence to GOTO' awarded after a killer early paper. (Since that was about automata, it should probably
be an Earley paper, except that it's slightly earlier than that.)  anyway, he meant no harm.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 20:35     ` C H Forsyth
@ 2007-01-19 21:06       ` erik quanstrom
  2007-01-19 21:09       ` Taj Khattra
  1 sibling, 0 replies; 13+ messages in thread
From: erik quanstrom @ 2007-01-19 21:06 UTC (permalink / raw)
  To: 9fans

i think the ken c lexer is a very good example.  it shows how
goto, well applied, can be a very useful tool for an ad hoc problem.
it also shows that in practice lexers and parsers are seldom as
separate as they appear in textbooks.

on the other hand, rc has a very hairy lexer. hoc has a small, elegant one.
i believe the _practice of programming_ goes into detail about it.

- erik

On Fri Jan 19 15:37:42 EST 2007, forsyth@vitanuova.com wrote:
> >I expect the lexer in /sys/src/cmd/cc/ will be a good example.
>
> it's a little more elaborate than some (not gcc!) because it takes on limited C preprocessing
> duties as well.  you might also observe that the author enjoys his gotos, but since it is essentially
> a finite state machine that seems fair enough, and furthermore he's allowed to take advantage of his
> `licence to GOTO' awarded after a killer early paper. (Since that was about automata, it should probably
> be an Earley paper, except that it's slightly earlier than that.)  anyway, he meant no harm.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 20:35     ` C H Forsyth
  2007-01-19 21:06       ` erik quanstrom
@ 2007-01-19 21:09       ` Taj Khattra
  2007-01-19 21:18         ` Brantley Coile
  1 sibling, 1 reply; 13+ messages in thread
From: Taj Khattra @ 2007-01-19 21:09 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> you might also observe that the author enjoys his gotos

If you want to go somewhere, goto is the best way to get there. - ken

:)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 21:09       ` Taj Khattra
@ 2007-01-19 21:18         ` Brantley Coile
  0 siblings, 0 replies; 13+ messages in thread
From: Brantley Coile @ 2007-01-19 21:18 UTC (permalink / raw)
  To: 9fans

>> you might also observe that the author enjoys his gotos
>
> If you want to go somewhere, goto is the best way to get there. - ken
>
> :)

Goto Statements Considered Harmful
		-- Niklaus Wirth

(Dijkstra wrote the letter, but Wirth gave it its title.)

There's a really good scanner in Wirth's compiler book.

http://www.oberon.ethz.ch/WirthPubl/CBEAll.pdf



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 18:58 [9fans] Replacements for lex Joel Salomon
                   ` (2 preceding siblings ...)
  2007-01-19 19:18 ` erik quanstrom
@ 2007-01-20  8:44 ` William Josephson
  3 siblings, 0 replies; 13+ messages in thread
From: William Josephson @ 2007-01-20  8:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Jan 19, 2007 at 01:58:06PM -0500, Joel Salomon wrote:
> For languages sufficiently like C, is regexp(2) suitable?

For something that simple, you might as well just hand write it,
particularly if you're going to have to support somethig typedef-like.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-19 19:26   ` Joel Salomon
  2007-01-19 20:35     ` C H Forsyth
@ 2007-01-20  8:47     ` William Josephson
  2007-01-20  9:08       ` Bruce Ellis
  1 sibling, 1 reply; 13+ messages in thread
From: William Josephson @ 2007-01-20  8:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Jan 19, 2007 at 02:26:47PM -0500, Joel Salomon wrote:
> >I think that most people roll their own lexical analyzers under Plan 9.
> >That's typically not too hard to do, though.
>
> That's likely what I'll do for the final project (probably yet another
> C complier, but I might try my hand with [a subset of] D), but the

You'll learn a lot more if you don't try anything like C
let alone C++ or D.  For a semester-length project, you'll
learn far more if you work on a much smaller language --
ideally domain specific, in my opinion -- and really see it
through in detail.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [9fans] Replacements for lex
  2007-01-20  8:47     ` William Josephson
@ 2007-01-20  9:08       ` Bruce Ellis
  0 siblings, 0 replies; 13+ messages in thread
From: Bruce Ellis @ 2007-01-20  9:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I taught a course in advanced compiler construction where the
students were required to write a lisp interpreter in C and then
write a rudimentry C compiler in their lisp.

The "bits you don't have to do" included the c lex function which
was presented to them in lisp as a (c:token) function.  I've written
a lot of lex-ers and it was just the same code again (in c) which
stopped the students from spending all of their time trying to do
the same in lisp.  This enabled them to concentrate on the more
interesting tasks (I also supplied the lisp alloc and gc code).

It was a fun course and I hope things were learnt.

For most stuff something like lex is fine.  Have a try at getting
<integer/float constant> reg-exp useable and I'll type in a lex-er
faster than you can debug the reg-exps (a chore i decided was
a waste of time for the course).

brucee

On 1/20/07, William Josephson <jkw@eecs.harvard.edu> wrote:
> On Fri, Jan 19, 2007 at 02:26:47PM -0500, Joel Salomon wrote:
> > >I think that most people roll their own lexical analyzers under Plan 9.
> > >That's typically not too hard to do, though.
> >
> > That's likely what I'll do for the final project (probably yet another
> > C complier, but I might try my hand with [a subset of] D), but the
>
> You'll learn a lot more if you don't try anything like C
> let alone C++ or D.  For a semester-length project, you'll
> learn far more if you work on a much smaller language --
> ideally domain specific, in my opinion -- and really see it
> through in detail.
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-01-20  9:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-19 18:58 [9fans] Replacements for lex Joel Salomon
2007-01-19 19:12 ` Dan Cross
2007-01-19 19:26   ` Joel Salomon
2007-01-19 20:35     ` C H Forsyth
2007-01-19 21:06       ` erik quanstrom
2007-01-19 21:09       ` Taj Khattra
2007-01-19 21:18         ` Brantley Coile
2007-01-20  8:47     ` William Josephson
2007-01-20  9:08       ` Bruce Ellis
2007-01-19 19:13 ` Brantley Coile
2007-01-19 19:18 ` erik quanstrom
2007-01-19 19:24   ` Federico Benavento
2007-01-20  8:44 ` William Josephson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).