2005/5/10

     
 

AAL as Intentional Programming System

artefaktur

| Intentional Programming | ACI Concept | AAL definition | AAL syntax | AAL parser | Object Representation | OpCode | Reference Links |

How to use AAL as Intentional Programming System.

Content of this chapter:

   Topics
   Internal Architecture
   Builin Attributes
   User defined Attributes
   Type Library interface
   Extend Language
   Language switch
   Code Weafer
   Implementation Issues
     Multipass Parser
   Links

 Topics

  • Multipass Parser.
  • Parser allows ambiguitys.
  • Parsing allows to modify the Parse Tree.
  • Nodes has Attributes to identify the level of Parse/Interpret/Compile pass.

 Internal Architecture

Language definition levels:
  • Abstract Parse Syntax definition (ParseNode). -> generates an Abstract Code Tree (Code).
  • Code -> Semantic analysis. -> mapps semantic to Object Representation (ClazzInfo). -> generates SymbolTable . -> generates OpCodes.
  • OpCode. -> stack based operations. -> can be executed using ClazzInfo.

 Builin Attributes

String s = new [StackAlloc] String("asdf");

 User defined Attributes

void foo(int i)
{
}

  compiler.findNode("FunctionDecl").getType().attatchAttribute("Key", "Value);
]

 Type Library interface

[
  compiler.loadTypeLib(new JavaLib("java/net"));
  // all classes of java.net are available
]
java.net.SocketServer ss = new java.net.SocketServer();

 Extend Language


  compiler.pushGrammar(); // make new scope block for the grammar
  compiler.registerRule("RegExpExpr", new RegExp("Expression [ '=~' REGEX_EXPRESSION ]" )); 
  compiler.replaceRule("Expression", "RegExpExpr");
]  // now this new Grammar element is available
  ("asdf" + b) =~ /asdf/;
[
  // remove the Grammar defintion.
  compiler.popGrammar();
]

 Language switch


  compiler.registerToken("END_OF_LISP", "<<EndOfLisp");
  compiler.replaceGrammarUntil(new LispInterpreter(), "END_OF_LISP");
]
 (defun x (a b) (+ a b))
<<EndOfLisp

acdk.lang.System.println("now back in ACDK");
// using the method defined in lisp
acdk.lang.System.println(x(1, 2));

 Code Weafer

[
  Code logAdder = new LogInOutAdder(orgRule: compiler.getRule("FunctionBody"), classname: "MyClass", funcname: "foo");
  compiler.replaceRule("FunctionBody", locAdder);
]

class MyClass
{
  public void bar() {}
  public int foo(int i) 
  { 
    // LogInOutAdder whould insert a statement to print out something like "MyClass.foo(42) entered"
    return i + 1;
  }
}

 Implementation Issues

 Multipass Parser

PassLevel:
  • Abstract Syntax Tree (AST): Context Free Tree with Rules and Token
  • Language Syntax Tree (LST): AST, but fixed ambiguities.
  • Semantik Resolution Tree (SRT): Based on the LST Check and fix semantic issues. For example the construct
    Object o = "asdf";
        o.length(); // this line will be explained
    Will translated from Rule "Expression Operator('.') Function" to "Expression" DmiObjFuncCall Function in case the o is a Object available via DMI functionality. Inlining, static overloading, etc. may be resolved here.
  • Interpret Syntax Tree (IST): Does interpret the code.
  • CodeGen Syntax Tree (CST): Does generate byte code or asm.
class AClass 
{
  void foo();
} // commit point to generate LST here fore the class Rule.

[ // AClass as LST definition is alrady available 
  compiler.dosomething();
  // has to be interpreted.
]

Maybe the transforming from Source to AST to LST to IST and CST may be restarted by one Rule, because it modified the ST.

 Links