Page 1 of 1

il65- macro assembly

Posted: Wed May 10, 2017 4:52 pm
by AldoBrasil
il65- intermediate level 6502 language

Code: Select all

<crlf> := #13, #10
<commentchar> := #00..09, #11, #12, #14..#255
<anychar> := #00..#124, #126..#255
<digit> := '0'..'9'
<hexdigit> := '0'..'9', 'A'..'F', 'a'..'f'
<bindigit> := '0', '1'
<stringchar> := #32..#255
<alpha> := 'A'..'Z', 'a'..'z', '_'
<alphanumeric> := { <alpha> | <digit> }

<addop> := '+', '-', 'or', 'xor', 'shr', 'shl'
<mulop> := '*', '/', 'div', 'mod', 'and'
<relop> := '=', '>', '<', '>=', '<=', '<>'
<identifier> := <alphanumeric> [ <alphanumeric> [...] ]
<decnumber> := <digit> [ <digit> [...] ]
<hexnumber> := <hexdigit> [ <hexdigit> [...] ]
<binnumber> := <bindigit> [ <bindigit> [...] ]
<anystring> := <anychar> [ <anychar> [...] ]
<commentstring> := <commentchar> [ <commentchar> [...] ]
<crlfstring> := <crlf> [ <crlf> [...] ]
<literalstring1> := '{' <anystring> '}'
<literalstring2> := '"' <stringchar> '"'
<string> := { <literalstring1> | <literalstring2> }
<float> := <decnumber> '.' <decnumber>
<number> := { <decnumber> | '$' <hexnumber> | '%' <binnumber> }
<comment> := '//' <commentstring> <crlfstring>
<literal> := { <number> | <float> | <string> }

// Expressions
<funccall> := <identifier> '(' [ <expressionlist> ] ')'
<varref> := <identifier>
<subexpression> := '(' <expression> ')'
<unaryminus> := '-' <factor>
<notfactor> := 'not' <factor>
<factor> := { <literal> | <notfactor> | <unaryminus> | <subexpression> | <varref> | <funccall> }
<mulexpr> := <factor> [ <mulop> <factor> [...] ]
<addexpr> := <mulexpr> [ <addop> <mulexpr> [...] ]
<expression> := <addexpr> [ <relop> <addexpr> ]
<expressionlist> := <expression> [ ',' <expression> [...] ]

// Symbols
<constdec> := <identifier> '=' <constexpression>
<vardec> := <identifier> [ '=' <constexpression> ]
<constdeclist> := <constdec> [ <constdec> [...] ]
<vardeclist> := <vardec> [ <vardec> [...] ]
<parameterdeclist> := <identifier> [ <identifier> [...] ]
<funcdec> := 'func' <identifier> '(' [ <parameterdeclist> ] ')' ':' <statementlist> 'endfunc'
<macrodec> := 'macro' <identifier> '(' [ <parameterdeclist> ] ')' ':' <statementlist> 'endmacro'

// Statements
<include> := 'include' <expression>
<const> := 'const' <constdeclist> 'endconst'
<var> := 'var' <vardeclist> 'endvar'
<assignment> := <identifier> ':=' <expression>
<return> := 'return' <expression>
<break> := 'break'
<proccall> := <identifier> '(' [ <expressionlist> ] ')'
<asm> := <expression>
<for> := 'for' <identifier> ':=' <expression> 'to' <expression> [ 'step' <expression> ] <statementlist> 'endfor'
<repeat> := 'repeat' <statementlist> 'until' <expression>
<while> := 'while' <expression> 'do' <statementlist> 'endwhile'
<caselabel> := 'case' <expressionlist> ':' <statement>
<caselabellist> := <caselabel> [ <caselabel> [...] ] 
<case> := 'switch' <expression> 'of' <caselabellist> [ 'otherwise' <statementlist> ] 'endswitch'
<if> := 'if' <expression> 'then' <statementlist> [ 'elsif' <expression> 'then' <statementlist> ] [ 'else' <statementlist> ] 'endif'
<statement> := { <if> | <case> | <while> | <repeat> | <for> | <asm> | <proccall> | <break> | <return> | <assignment> | <var> | <const> | <include> }
<statementlist> := [ <statement> [ ';' <statement> [...] ] ] [ ';' ]
<mainprogstatement> := { <statement> | <funcdec> | <macrodec> }
<mainprogstatementlist> := <mainprogstatement> [ <mainprogstatement> [...] ]
This is a macro language i am developing. This language is interpreted AT COMPILE TIME, and produces 6502 assembly as output that is converted internaly into hex or s19 output. this is done so in order to compile the previously (viewtopic.php?f=2&t=4508) mentioned intermediate language (kind of 6502 llvm).

example :

Code: Select all

macro u8add(a, b)
{
   assembly code here 
  @a is replaced by the contents of A parameter,
  @b is replaced by the contents of B parameter etc
}
endmacro
the language is more powerfull than that (this example does not make justice) and uses a formal grammar to derive a descent recursive parser and an abstract syntax tree. the idea is to have a intermediate assembly (kind of llvm) between the compiler and the machine code, that translates everything at compile time into machine code.

Re: il65- macro assembly

Posted: Wed May 10, 2017 6:56 pm
by Arlet
Interesting. What does the final assembly output look like ? Does it produce native, inline code, or subroutine calls, or both (maybe adjustable) ?