9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] hoc's behaviour, unary operators
Date: Fri, 30 Oct 2009 14:28:52 -0400	[thread overview]
Message-ID: <332ccdbfcadf7769acbbd00931f5cde4@brasstown.quanstro.net> (raw)
In-Reply-To: <<a560a5d00910301119t4ee76736j80bdebbb9fa9bd31@mail.gmail.com>>

> Python handles correctly e.g. 2-----7, 2+-+-7, 2+++-7,...
> C-compiler that I use in my linux, gcc, is ok for a+-b and a-+b, also
> for a+-+-b, but not for a++b or a--b or any alike.

you're confusing tokens and productions.  the c tokenizer
has the following rules
--	-> 	DEC
++	->	INC
+	->	PLUS
-	->	MINUS

therefore the string "a++b" can't be valid, since the tokens
the parser sees are "a" INC "b".  that's not kosher c.  way
back when in primoridal c, there were no seperate tokens
for INC and DEC, they were productions in the parser and
goofiness like you describe was allowed.

i'll leave as an excersize why k&r thought that making --
and ++ tokens was worth while.

also, this is a very long discussion for a one-line fix.  if
you care, please apply this largely do-nothing patch to
your hoc:

; diffy -c /sys/src/cmd/hoc/hoc.y
/n/dump/2009/1030/sys/src/cmd/hoc/hoc.y:98,103 - /sys/src/cmd/hoc/hoc.y:98,104
  	| expr '%' expr	{ code(mod); }
  	| expr '^' expr	{ code (power); }
  	| '-' expr   %prec UNARYMINUS   { $$=$2; code(negate); }
+ 	| '+' expr   %prec UNARYMINUS   { $$=$2; }
  	| expr GT expr	{ code(gt); }
  	| expr GE expr	{ code(ge); }
  	| expr LT expr	{ code(lt); }

- erik



       reply	other threads:[~2009-10-30 18:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<a560a5d00910301119t4ee76736j80bdebbb9fa9bd31@mail.gmail.com>
2009-10-30 18:28 ` erik quanstrom [this message]
2009-10-30 19:03   ` matt
2009-10-30 19:39   ` Rudolf Sykora
2009-11-02  9:56   ` Dennis Ritchie
2009-10-30 15:20 Rudolf Sykora
2009-10-30 15:44 ` Rudolf Sykora
2009-10-30 15:55   ` Jorden Mauro
2009-10-30 16:09     ` Rudolf Sykora
2009-10-30 16:27       ` Martin Neubauer
2009-10-30 18:19         ` Rudolf Sykora
2009-10-30 16:22     ` Martin Neubauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=332ccdbfcadf7769acbbd00931f5cde4@brasstown.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).