3

I'm writing a paper for my Programming Languages and Compilers course about the J programming language. Since it's a relatively unknown (but interesting) programming language, I'm having trouble finding the right documentation and information regarding the formal grammar of J in (E)BNF, some open-source implementations of J, especially lexical analyzers and parsers.

Does anyone know of an accurate source for an (E)BNF for the J programming language? If so, is that an LL grammar and can it be "put through" a parser generator?

empa
  • 53
  • 4
  • 1
    Try asking the [j programming forum](http://www.jsoftware.com/mailman/listinfo/programming). Some people there will know. – Eelvex Jan 10 '20 at 12:05

2 Answers2

5

(E)BNF is a notation technique for context-free grammars. But J is a context-sensitive language [1,2]. J's parsing rules are listed in the Dictionary II. E [3].

References:

  1. https://code.jsoftware.com/wiki/Guides/Language_FAQ/J_BNF
  2. http://www.jsoftware.com/pipermail/general/2005-July/023632.html
  3. https://www.jsoftware.com/help/dictionary/dicte.htm
Igor Zhuravlov
  • 316
  • 1
  • 5
4

J uses a parsing table based on a stack that evaluates the sentence as soon as it has enough information. The best source for this, I believe, are Chapters 38 and 39 of Henry Rich's "J for C programmers". You need to be able to be comfortable with tacit J to make the most of this, but it should serve as a good introduction to the parser. https://www.jsoftware.com/help/jforc/parsing_and_execution_i.htm#_Toc191734584 https://www.jsoftware.com/help/jforc/parsing_and_execution_ii.htm#_Toc191734586

Another source for understanding J's evaluation is the trace verb, which can be found in the trace script located for recent versions of J. eg. for j901 in j901/addons/general/misc/trace.ijs This gives a hands on experience that will step through a J sentence and list the rules implemented and the current state of the stack.

If you have downloaded the addons for J this would already be available in your installation.

    load '~addons/general/misc/trace.ijs'
  trace '(+/ % #) 5 7 3 4 5 2' NB. returns the trace for the average of list of numbers
 --------------- 3 Adverb -----
 +
 /
 +/
 --------------- 5 Trident ----
 +/
 %
 #
 +/ % #
 --------------- 8 Paren ------
 (
 +/ % #
 )
 +/ % #
 --------------- 0 Monad ------
 +/ % #
 5 7 3 4 5 2
 4.33333
 ==============================
4.33333
bob
  • 4,282
  • 2
  • 22
  • 30