Here's a reformatted version of Raul's method for parsing pythonish tree 
descriptions.  The formatting does a good job identifying where train elements 
begin and end, and verb phrases.  Another rule I didn't specify:  When a noun 
is used as a leftmost fork element instead of a left dyad argument, it should 
be spaced like a verb.

words=: < @(((a:  ,: @; ~  }. ~)  ;  ])  (0 i. ~  ' '  =  ])) ;._2
Blank=: <  ,:  0 ; ~  i.  0 2
parse=: [:  value  [:  crate ^:(<: @#) @>  [:  shift &.> /  Blank |. @,  words
value=: 0  {::  ,
level=: >: @* @- &(1 &{::)
shift=: leave `group `enter @.(level  {:)

NB. x - new word, y - parse stack
enter=: , ~
group=: }: @]  ,  [  (, ~ &.> &{.  ,  {: @[) {: @]
leave=: [  group  (]  bunch  [:  + /  < &(1 &{:: "1))

bunch=: crate @] ^:[ ~ NB. x - levels to package
crate=: _2 &}.  (,  <)  _1 0 &{::  stuff  _2 0 &{::
stuff=: < @[  (<  _1 _1) }  ]

for reference,
test =: 0 : 0
html
 head
 body
  p stuff
  p div='adiv'
   more stuff    
  table
   tr
    td 1
    td 2
  p last stuff

)
parse test NB. produces equivalent J tree.

A practical shortcut to the spacing rules would be to use reduced spacing on 
straightforward sections. for example (+/ % #) or the above level=: >:@[EMAIL 
PROTECTED] &(1&{::).  The most helpful spacing rule proposed is the double 
spaces between verb phrases and between their right arguments.

----- Original Message ----
From: Pascal Jasmin <[EMAIL PROTECTED]>
To: General forum <[email protected]>
Sent: Saturday, May 19, 2007 1:38:13 PM
Subject: [Jgeneral] Suggested syntax conventions

I'd suggest the following syntax conventions for J:

Variable names:
Adverbs and Nouns start with upper case
conjunctions and verbs start with lower case
(Useful but optional: VARIABLENOUN vs CONSTANt or VariableNoun vs CONSTANT)

Spacing between words is to be relative to minimal spacing which varies (0 or 
1) between built-ins, literals, and variables.  There are 3 recommended spacing 
minimal, minimal +1, and minimal+2

Spacing rules:
Conjunctions have minimal spacing to their right arg.
Adverbs have minimal+1 spacing to their left arg
Verbs have minimal+2 spacing to their right arg
Dyadic verbs have minimal +1 spacing to their left arg.

With these rules, any expression can be read without knowing the form of speech 
of individual words.
(where v=verb, n=noun, a=adverb, c= conjunction (x)=parenthesised expression)
a   B  c   D     is v n v n
<  2 -  1         is same

a   +  2 &(c  d E)  is v + 2 &(v c n)


a B or a b is adverb (c n or c v)
A  B is verb phrase or adverb: n a or  a a
A  B  C is verb phrase or adverb: n a a or  a a a
A  b   C is noun: n v n 
A  B   C is noun: n a n

a   B is noun: v n
a  b is adverb: v c
a  b c is verb phrase: v c v
a  B is verb phrase : v a

a  B  C is verb phrase : v a a 
A  B  C is verb phrase or adverb : n a a or a a a

a   b is hook: v v
a   b  C is hook: v v a
a   b   C is noun: v v n

(x)a or (x)A is adverb: x must resolve to c
(x) a  B is noun: n v n
(x)  a is hook: v v
(x)  a   b is fork: v v v or n v v
A (x) is adverb or verb phrase: a a or n c or n a
A (x)  B is noun: n a n 
A (x) B is adverb or verb phrase: n a a or a a a
A (x)b is  verb phrase: n c v 
a (x) is v c or v a
a (x)b is verb phrase: v c v 
a (x) B is verb phrase: v a a 
a  (x) is hook or noun: v v or v n

Some Notes:
The spacing corresponds to the bonding order (closer words bond higher than 
distant words)
The ambiguous cases of whether the left most word of an expression is a noun or 
adverb when all other elements of the leftmost verb phrase are adverbs would 
come up less frequently than the alternate ambiguities that occur when you make 
conjunctions and nouns be the designated upper case variables.
Higher order adjectives (adjectives that return adjectives) can be spaced 
appropriately by parenthesising them as shown in the (x) examples above, with a 
lot of ambiguity resolved.


On another note, why must this be a syntax error:
a c v  while a (c v) is not?  I might be missing something (as usual), but 
would understand the 2 expressions to be equivalent.



      Be smarter than spam. See how smart SpamGuard is at giving junk email the 
boot with the All-new Yahoo! Mail at http://mrd.mail.yahoo.com/try_beta?.intl=ca

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm





      Ask a question on any topic and get answers from real people. Go to 
Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to