Nav:  [home][ani][anivision] > [ani-grammar]
 
Go:  [ANI] [POV]
← [What are these? Why?]

AniVision: Animation Grammar

Animation Lexer

(Primary) files read in by Anivision are written in the animation (description) language which is a full-featured programming language.

The lexical analysis of this language will perform the following actions:

  • Strip C-style comments (/*comment*/). Note that C-style comments may be nestee.
  • Strip C++-style comments (//comment\n).
  • Process include directives (#include "file"\n).
  • Recognize reserved tokens as well as literals TS_INTEGER, TS_FLOAT, TS_STRING, TS_IDENTIFIER. These follow the usual rules as known from C(++) quite closely.

Animation Syntax in EBNF

Here is the EBNF grammar of the animation (description) language. It is context-free but there were some tweaks in the lexer (e.g. to interprete "1..2" as range and not as two successing floats). Note also that the operators have the usual precedence (not explicitly enforced by the rules of the below grammar).

literal ::=
	  TS_INTEGER   // 123, 0x37, 0777
	| TS_FLOAT     // 1.3, .54, 2e7
	| TS_STRING .  // "foo"

identifier ::= TS_IDENTIFIER .  // bar_bar

name_notabs ::=
	  identifier
	| identifier "::" name .

name ::=
	  name_notabs
	| "::" name_notabs .

builtin_name_raw ::= "this" .

builtin_name ::= builtin_name_raw .

vector ::= "<" expr_list_ne ">" .

/* May not be empty! (Otherwise r/r conflict with empty compound expr {}.) */
array_expr_list ::=
	      expr_list_ne
	| "," expr_list_ne
	|     expr_list_ne ","
	| "," expr_list_ne "," .

/* Explicit empty array spec "{.}" : */
/* Cannot use "{" "}" because of s/r conflict with empty compound stmt. */
array ::=
	  "{" array_expr_list "}"
	| "{" "." "}" .

/******************* EXPESSION *******************/

primary_expr ::=
	  literal
	| vector
	| array
	| name
	| builtin_name
	| "(" expr ")"
	| "NULL" .

postfix_expr ::=
	  primary_expr
	| postfix_expr "[" expr "]"              // array subscript
	| postfix_expr "(" fcall_expr_list ")"   // function call
	| pod_type_name "(" expr ")"             // cast to POD-type
	| postfix_expr "." name
	| postfix_expr "." builtin_name
	| postfix_expr "->" name
	| postfix_expr "->" builtin_name
	| postfix_expr "++"
	| postfix_expr "--" .

unary_op ::= "+" | "-" | "!" .

new_array_spec ::=
	  type_name "[" expr "]"
	| new_array_spec bracket_bracket
	| new_array_spec "[" expr "]" .

unary_expr ::=
	  postfix_expr
	| "++" unary_expr
	| "--" unary_expr
	| unary_op unary_expr
	| "new" name "(" fcall_expr_list ")"  // allocation (no arrays)
	| "new" new_array_spec   // allocation (arrays)
	| "delete" unary_expr .   // <-- not implemented

binary_expr ::=
	  unary_expr
	| binary_expr "^" binary_expr
	| binary_expr "*" binary_expr
	| binary_expr "/" binary_expr
	| binary_expr "%" binary_expr
	| binary_expr "+" binary_expr
	| binary_expr "-" binary_expr
	| binary_expr "<" binary_expr
	| "(" binary_expr ">" binary_expr ")"   // <-- s/r conflict with vector (w/o "()")
	| binary_expr "> " binary_expr          // <-- (special)
	| binary_expr "<=" binary_expr
	| binary_expr ">=" binary_expr
	| binary_expr "==" binary_expr
	| binary_expr "!=" binary_expr
	| binary_expr "&&" binary_expr
	| binary_expr "||" binary_expr .

cond_expr ::=
	  binary_expr
	| binary_expr "?" expr ":" cond_expr
	| binary_expr "?" ":" cond_expr .

range_expr ::=
	  cond_expr
	| cond_expr ".." cond_expr
	|           ".." cond_expr
	| cond_expr ".." .

expr ::= range_expr .

expr_list_ne ::=
	  expr
	| expr_list_ne "," expr .

fcall_expr_list_ent ::=
	  initializer
	| name "=" initializer .

fcall_expr_list_ne ::=
	  fcall_expr_list_ent
	| fcall_expr_list_ne "," fcall_expr_list_ent .

fcall_expr_list ::=
	  /* empty */
	| fcall_expr_list_ne .


/******************* STATEMENT *******************/

pod_type_name ::=
	  "int"
	| "scalar"
	| "range"
	| "vector"
	| "vector" "<" expr ">"
	| "matrix"
	| "matrix" "<" expr "," expr ">"
	| "string" .

type_name ::=
	  pod_type_name
	| name
	| "anyobj" .

bracket_bracket ::= "[" "]" .

array_spec ::=
	  bracket_bracket
	| array_spec bracket_bracket .

initializer ::=
	  expr
	| "{" "}" .

declarator_noinit ::=
	  name_notabs
	| declarator_noinit "[" expr "]"
	| declarator_noinit "[" "]" .
declarator ::=
	  declarator_noinit
	| declarator_noinit "=" initializer .

declarator_list_ne ::=
	  declarator
	| declarator_list_ne "," declarator .

decl_stmt_nonstatic ::=
	  type_name declarator_list_ne ";"
	| "const" type_name declarator_list_ne ";" .

decl_stmt ::=
	  decl_stmt_nonstatic
	| "static" decl_stmt_nonstatic .

compound_stmt ::= "{" statement_list "}" .

selection_stmt ::=
	  "if" "(" expr ")" statement
	| "if" "(" expr ")" statement "else" statement .

_for_init_stmt ::=
	  expr_stmt
	| assign_stmt
	| decl_stmt .

_for_inc_stmt ::=
	  /* empty */
	| expr
	| assignment .

iteration_stmt ::=
	  "for" "(" _for_init_stmt expr_stmt _for_inc_stmt ")" statement
	| "while" "(" expr ")" statement
	| "do" statement "while" "(" expr ")" ";" .

jump_stmt ::=
	  "break" ";"
	| "return" expr ";"
	| "return" ";" .

assign_op ::= "=" | "+=" | "-=" | "*=" | "/=" .

assignment ::= unary_expr assign_op initializer .

assign_stmt ::= assignment ";" .

expr_stmt ::=
	  /* empty */ ";"
	| expr ";" .

ani_stmt ::=
	  "%" ani_block ";"
	| "%" cond_expr ani_block ";"
	| "%" name ":" ani_block ";"
	| "%" name ":" cond_expr ani_block ";" .

statement ::=
	  expr_stmt
	| assign_stmt
	| decl_stmt
	| compound_stmt
	| selection_stmt
	| iteration_stmt
	| jump_stmt
	| ani_stmt .

statement_list_ne ::=
	  statement
	| statement_list_ne statement .

statement_list ::=
	  /* empty */
	| statement_list_ne .


/******************* OBJECT *******************/

fdef_decl_list_ent ::= type_name declarator .

fdef_decl_list_ne ::=
	  fdef_decl_list_ent
	| fdef_decl_list_ne "," fdef_decl_list_ent .

fdef_decl_list ::=
	  /* empty */
	| fdef_decl_list_ne .

function_mod ::=
	  /* empty */
	| "const" .

function_def_nonstatic ::=
	  /*void*/  name_notabs "(" fdef_decl_list ")" function_mod compound_stmt
	| type_name name_notabs "(" fdef_decl_list ")" function_mod compound_stmt
	| type_name array_spec name_notabs "(" fdef_decl_list ")" function_mod compound_stmt .

function_def ::=
	  function_def_nonstatic
	| "static" function_def_nonstatic .

obj_function_def ::=
	  function_def
	| "method" function_def  // <-- deprecated
	| "~" name_notabs "(" ")" compound_stmt .  /* destructor (not implemented) */

object_body_ent ::=
	  obj_function_def
	| decl_stmt .

object_body_ne ::=
	  object_body_ent
	| object_body_ne object_body_ent .

object_body ::=
	  /* empty */
	| object_body_ne .

object_def ::= "object" name "{" object_body "}" .


/******************* SETTING *******************/

setting_body_ent ::=
	  function_def
	| decl_stmt
	| object_def .

setting_body_ne ::=
	  setting_body_ent
	| setting_body_ne setting_body_ent .

setting_body ::=
	  /* empty */
	| setting_body_ne .

setting_def ::= "setting" name "{" setting_body "}"

/******************* ANIMATION *******************/

animation_def ::= "animation" name compound_stmt .

/******************* ANI MOVE/CHANGE... BLOCK *******************/

typed_scope ::=
	  identifier "{" typed_scope_list "}"
	| identifier name "{" typed_scope_list "}" .

typed_scope_expr ::= typed_scope .

typed_scope_ent ::=
	  typed_scope_expr
	| name "=" typed_scope_expr
	| expr ";"
	| name "=" expr ";" .

typed_scope_list_ne ::=
	  typed_scope_ent
	| typed_scope_list_ne typed_scope_ent .

typed_scope_list ::=
	  /* empty */
	| typed_scope_list_ne .

ani_block ::= "{" typed_scope_list "}" .

/******************* START *******************/

top_node ::=
	  setting_def
	| object_def
	| function_def
	| decl_stmt
	| animation_def .

top_node_list_ne ::=
	  top_node
	| top_node_list_ne top_node
	| top_node_list_ne error top_node .

top_node_list ::=
	  /* empty */
	| top_node_list_ne .

animation ::= top_node_list .

START ::= animation .

[home] [site map]
Valid HTML 4.01!
Copyright © 2003-2004 by Wolfgang Wieser
Last modified: 2004-06-27 17:00:49