About

A syntax-directed editor is a type of source code editor that knows the programming language grammar and uses this knowledge to guide the editing and the execution of a program. This ensures that a program is always syntactically correct.
The SDE Generator is a system capable of generating a Syntax-Directed Editor for a language written with the provided meta grammar.

Thesis

Architecture

After receiving a grammar the system will then generate the required templates to be used by the SDE to build the program tree. The parser and the lexer of the grammar will also be generated. When a text file is loaded the parser and lexer will be used to build the abstract tree which with the grammar templates will be used to generate the program tree and display it on the editor.

The Generator component is used to generate the grammar templates and the parser and lexer of the grammar. The Program Tree component represents the program in the editor and is modified by the user while editing. When loading a text file, the Program Tree Generator component will generate the program tree using the grammar templates and the text syntax tree.

Meta Grammar

The generator accepts grammars written using the defined meta language. This meta language is based on the ANTLR grammar definition with the particular feature that the user can annotate the production terms. Since the annotations are optional the generator accepts pure ANTLR grammars.

The grammar annotations are used to change the appearance of the text in the editor as well as displaying tips on the tree nodes.
instr : ifInstruction
      | whileInstruction
      | forInstruction
      | atr ';' @nl
      ;

ifInstruction : 'if' '(' cond ')' '{'@nlt instrs  '}' @nl elseCondition?
              ;

atr : ID@c=red '=' exp
    ;

Annotations



  • Placed after a production term
  • Used to color a terminal term
  • @c=<color-name>
grammar Simple;

example : 'a' @c=red 'b' ;


  • Placed after a production term
  • Places a new line after a term.
  • @nl
grammar Simple;

example : 'a' @nl 'b' ;


  • Placed after a production term
  • Places a new line and a tab after a term.
  • @nlt
grammar Simple;

example : 'a' @nlt 'b' ;


  • Placed after a production term
  • Places a helping tip next to the tree node.

grammar Simple;

example : 'a' 'b'@h='Helping tip'  ;
  • Placed before the grammar definition
  • Defines the start and the end of a comment.
  • Begin comment: @bc='<sequence of chars>'
  • End comment: @ec='<sequence of chars>'

@bc='/*'
@ec='*/'
grammar Simple;

programa : 'a' 'b' ;

Examples

JSON text written using a JSON grammar.
Editing of a program from scratch using a simple grammar.

Download

The application can be downloaded here.
The SDE Generator is also available as a web application.