english-script
english-script copied to clipboard
How will EnglishScript be translated into other programming languages?
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?
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?
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!
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
For a discussion on automatic global static typing also see https://github.com/manastech/crystal/issues/1824
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
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?
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!
generous method_tokens
once you get to generics we need to discuss again. Vector < Integer > should probably be mapped to EnglishScript "list of numbers"
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
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