[e-lang] Proposed Kernel-E abstract syntax

Mark Miller erights at gmail.com
Fri Jun 9 20:23:39 EDT 2006


Proposed Kernel-E grammar and schema. Please view in a fixed width font.

I am *not* proposing the grammar-description syntax used here. Dean is
working on another one, as part of the Packrat-like parser generator
he's writing in E. Once he posts that, then we can discuss what syntax
we'd like to use to describe grammars. I'm using the notation below
for now because I understand it and have some limited ability to process
it.[*]

The syntax used here is essentially EBNF with the conventional meanings
for "*", "+", and "?". In addition, I've adopted Dean's suggested
    x ** y
To mean any number of xs separated by ys, and Dean's suggested
    x ++ y
To mean at least one x separated by ys.

"->" followed by a function name is an action. x=n provides the value
associated with x's action as the n'th argument to this production's
action. (In a LaTeX document, x=n might be rendered as x subscript n.)

---------------- from kernel-e.grammar ------------------------
e ::=
     (.char.=1 | .int.=1 | .float64.=1 | .String.=1)           -> quote
  |  e=1 "." verb=2 "(" e=3**"," ")"                           -> call
  |  e=1 ";" e=2                                               -> seq
  |  noun=1                                                    -> noun
  |  "&" noun=1                                                -> slot
  |  "def" p=1 ("exit" e=2)? ":=" e=3                          -> def
  |  "{" e=1 "}"                                               -> hide
  |  "if" "(" e=1 ")" "{" e=2 "}" "else" "{" e=3 "}"           -> if
  |  "try" "{" e=1 "}" "catch" p=2 "{" e=3 "}"                 -> catch
  |  "try" "{" e=1 "}" "finally" "{" e=2 "}"                   -> finally
  |  "escape" p=1 "{" e=2 "}" ("catch" p=3 "{" e=4 "}")?       -> escape
  |  comment=1 "def" oname=2 ("implements" e=3++",")? script=4 -> object
  |  "meta" "." "context" "(" ")"                              ->
metaContext
  |  "meta" "." "getState" "(" ")"                             -> metaState;

p ::=
     oname=1 (":" e=2)?                                        ->
guardedPatt
  |  "[" e=1**"," "]"                                          -> listPatt
  |  "via" "(" e=1 ")" p=2                                     -> via;
oname ::=
     noun=1                                                    -> defFinal
  |  "var" noun=1                                              -> defVar
  |  "&" noun=1                                                -> defSlot
  |  "_"                                                       -> ignore;

script ::=
     matcher
  |  "{" method=1* matcher=2* "}"                              -> script;
method ::=
     comment=1
     "method" verb=2 "(" p=3**"," ")" (":" e=4)? "{" e=5 "}"   -> method;
matcher ::= "match" p=1 "{" e=2 "}"                            -> matcher;

verb ::= <Ident>=1 | .String.=1;
noun ::= <Ident>=1 | "::" .String.=1;
comment ::= <Comment>=1?;
--------------------------------------------------------------

kernel-e.schema below shows a propsed grammar of the terms trees to be
used to represent Kernel-E ASTs.

The schema description language is the essentially the grammar description
language extended for describing trees of symbols, rather than sequences
of symbols. In order for this to work, it also uses "," rather than
juxtaposition for left-to-right order.

---------------- from kernel-e.schema ------------------------
<e> ::=
     quote(.char. | .int. | .float64. | .String.)
                                      # String | Char | Integer | Float64
  |  call(<e>,<verb>,[<e>*])          # e.verb(<e>**,)
  |  seq(<e>,<e>)                     # e1; e2
  |  noun(<noun>)                     # noun
  |  slot(<noun>)                     # &noun
  |  def(<p>,(<e>|null),<e>)          # def p <exit e1>? := e2
  |  hide(<e>)                        # {e}
  |  if(<e>,<e>,<e>)                  # if (e1) {e2} else {e3}
  |  catch(<e>,<p>,<e>)               # try {e1} catch p {e2}
  |  finally(<e>,<e>)                 # try {e1} finally {e2}
  |  escape(<p>,<e>,(<p>,<e>)?)       # escape p1 {e1} <catch p2 {e2}>?
  |  object(<comment>,<oname>,[<e>*],<script>)
                                # comment def oname <implements <e>++,>?
script
  |  metaContext()                    # meta.context()
  |  metaState();                     # meta.getState()

<p> ::=
     guardedPatt(<oname>, <e>?)       # oname <:e>?
  |  listPatt([<p>*])                 # [<p>**,]
  |  viaPatt(<e>,<p>);                # via (e) p
<oname> ::=
     defFinal(<noun>)                 # noun
  |  defVar(<noun>)                   # var noun
  |  defSlot(<noun>)                  # &noun
  |  ignore();                        # _

<script> ::=
     <matcher>                        # matcher
  |  script(<method>*, <matcher>*);   # {<method>* <matcher>*}
<method> ::= method(<comment>,<verb>,[<p>*],(<e>|null),<e>);
                                      # comment method verb(<p>**,) <:e1>?
{e2}
<matcher> ::= matcher(<p>,<e>);       # match p {e}

<verb> ::= .String.;                  # Ident | String
<noun> ::= .String.;                  # Ident | ::String
<comment> ::= .String.;               # </** ... */>?
----------------------------------------------------------------------------


[*] In an E >= 0.8.36t, you can parse these descriptions into term trees as
follows:

? def makeSchema := <import:org.quasiliteral.schema.makeSchema>
? def <schema> := <resource:org/quasiliteral/schema/>
? makeSchema.parseGrammar(<schema:kernel-e.grammar>.getTwine())
? makeSchema.parseSchema(<schema:kernel-e.schema>.getTwine())

However, nothing yet processes the term trees that results from parsing
these descriptions. Dean's parser generator uses a similar but different
grammar description representation.

In any case, the purpose of sending this out is not to discuss grammar
descriptions and parsers yet, but to discuss Kernel-E. The one substantive
change from previous Kernel-E discussions is the
object-definition-expression,
to be covered in upcoming email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.eros-os.org/pipermail/e-lang/attachments/20060609/862b8e42/attachment-0001.html 


More information about the e-lang mailing list