english-script icon indicating copy to clipboard operation
english-script copied to clipboard

How will EnglishScript be translated into other programming languages?

Open jarble opened this issue 8 years ago • 11 comments

One of the long-term goals of EnglishScript is to make the language available on multiple platforms. I have written a program called transpiler-generator that is intended to translate EnglishScript into several other programming languages, and vice-versa.

Which features will I need to implement in order to make transpiler-generator compatible with EnglishScript?

jarble avatar Jan 08 '16 22:01 jarble

Also, transpiler-generator will be able to convert EnglishScript into C and C++ if the EnglishScript source code is statically typed. Is it possible yet to write statically-typed code in EnglishScript?

jarble avatar Jan 08 '16 22:01 jarble

Nice!

EnglishScript / Angle parses into a canonical AST which is meant to be language agnostic. From that Abstract syntax tree we generate bytecode. The kast subproject is work in progress, but it was already used to transpile the Ruby version to the better Python version.

It would be very sweet if we had a kast -> transpiler adapter!

pannous avatar Jan 09 '16 10:01 pannous

Is it possible yet to write statically-typed code in EnglishScript?

Absolutely!

types are optional but if they are used they will be enforced: x=8 x="hi" // ok int x=9 x="hi" // error, x typed as int

same for function arguments

tests variable_test and other

pannous avatar Jan 09 '16 10:01 pannous

For a discussion on automatic global static typing also see https://github.com/manastech/crystal/issues/1824

pannous avatar Jan 09 '16 10:01 pannous

Here was the first draft for a schema, however out of lazyness we sticked to the relatively clean python AST for now. It would be nice though if we could map

    <complexType name="method">
        <choice maxOccurs="unbounded">
            <element name="name" type="string"/>
            <element name="returns" type="a:type"/>
            <element name="modifiers" type="a:modifiers"/>
            <element name="arguments" type="a:arguments"/>
            <element name="body" type="a:block"/>
            <!-- IMPLICIT: BODY!!-->
        </choice>

to your anonymous_function,params:function_parameters,b:series_of_statements,return_type:type etc

pannous avatar Jan 09 '16 11:01 pannous

I'm also planning to write a translator that converts Java and C# code into statically typed EnglishScript code. Has the syntax for statically typed parameters been decided yet?

jarble avatar Jan 09 '16 15:01 jarble

See below for syntax of statically typed parameters

here is the grammar and parser for method definitions:


@Starttokens(method_tokens)
def method_definition(name=None):
  if not name:
    # annotations=maybe(annotations)
    modifiers=maybe_tokens(modifier_words)
    return_type = maybe(typeName)
    tokens(method_tokens)  # how to
    no_rollback()
    name = word(include=english_operators)  # maybe(noun) or verb()  # integrate or word
  brace = maybe_token('(')

  args = []
  def arguments():
    angle.in_params = True
    a = param(len(args))
    maybe_token(',')
    args.append(a)
    return a
  # obj= maybe( endNode ) # a sine wave  TODO: invariantly get as argument book.close==close(book)
  star(arguments)  # i.e. 'over an interval i' 'from a to b' 'int x, int y=7'
  angle.in_params = False
  if brace: token(')')

  return_type = return_type or maybe_tokens(['as']) and maybe(typeNameMapped) or None
  return_type = maybe_tokens([ 'returns', 'returning', '=>', '->']) and maybe(typeNameMapped) or return_type
  maybe_tokens([ 'return', '=']) # as block starters, NOT as return_type indicators!

for params follow through to here

pannous avatar Jan 09 '16 15:01 pannous

generous method_tokens

pannous avatar Jan 09 '16 16:01 pannous

once you get to generics we need to discuss again. Vector < Integer > should probably be mapped to EnglishScript "list of numbers"

pannous avatar Jan 09 '16 16:01 pannous

the preferred verbose typed method declaration would be define fibonacci number n as integer: <block> "as integer" specifying the return type

the shortest typed method declaration would be def square of int n as int: n*n

pannous avatar Jan 09 '16 16:01 pannous

it's kind of fascinating that the same grammar above parses these stylistically quite different complete method definitions:

define addition of number a and number b as number: a plus b

to add a to b return a + b

pannous avatar Jan 09 '16 16:01 pannous