C#'s greatest mistakes
BLS
windevguy at hotmail.de
Sat Nov 27 15:58:03 PST 2010
On 27/11/2010 23:47, Kagamin wrote:
> BLS Wrote:
>
>> Hi Andrej,
>> I was not aware that GCC has plugin support. (being a Windows guy, well
>> almost)
>> ..an interesting EBNF in -> EBNF out ->Translator read is ..
>>
>> http://www.tools.vlampe.de/depot4/Depot4.html
>>
>> Bjoern
>
> There's also xoc http://pdos.csail.mit.edu/xoc/
Thanks for the link. I am watching xoc for quite a while now. In my
humble opinion xoc wants a bit tooo much.
what i am trying to archive is based on ..
You can describe EBNF (E) in EBNF. Writing an EBNF parser (E1) is simple.
Generating parser D source code based on (E1) and target language
transformation(E2)
In other words whenever the lwxer finds LanguageX{ call the adequate 2D
translator mixin the generated D code an carry on, as usual)
/Given a spooky PASCAL TO Kinda D Translator-EBNF:/
Differnce to standard EBNF is
EBNFin ->EBNFout
program = block '.' -> 'import std.io\n' block_ .
block = ['VAR' ident {',' ident[i]} ';']
'BEGIN' statement {/..c/';' statement[i] } 'END'
-> ['int ' ident_ {',' ident_[i]} ';\n']
'main() \n{\n'
statement_ {/..c/ '\n' statement_[i] }
'}\n'.
statement = 'WRITE' expression |
'READ' ident|
'BEGIN' statement[1] {';' statement[i+1] } 'END' |
'IF' expression 'THEN' st:statement ['ELSE' ste:statement] |
'WHILE' expression 'DO' st:statement |
ident ':=' expression |
-> 'printf("%d",' expression_ ');' |
'scanf("%d", &' ident_ ');' |
'{' {/..N+1/ statement_[i] '\n' } '}' |
'if (' expression_ ') ' st_ ['else ' ste_ ]|
'while (' expression_ ') ' st_ |
ident_ '=' expression_ ';'| .
expression = simpleExpr
[('='|'<='|'>='|'<>'|'<'|'>') sE: simpleExpr ]
-> simpleExpr_
[('=='|'<='|'>='|'!='|'<'|'>') sE_ ].
simpleExpr =
VAR op: FLEX OF INT;
['+'|'-'] term
{(/op[i]/'+'|'-'|'OR') term[i] }
-> ['+'|'-'] term_
{(/op[i]/'+'|'-'|'||') term_[i] }.
term =
VAR op: FLEX OF INT;
factor {(/op[i]/'*'|'DIV'|'AND') f2:factor[i]}
-> factor_ {(/op[i]/ '*'|'/'|'&&') f2_[i]}.
factor = num | '(' expression ')'| 'NOT' factor | ident
-> num_ |'(' expression_ ')'|'!' factor_ | ident_ .
/Will translate spooky source Pascal into Cish target source/
SOURCE TARGET
VAR X, Y, H, GGT; import std.io
BEGIN int X,Y,H,GGT;
READ X; READ Y; main()
WHILE X<>0 DO {
BEGIN scanf("%d", &X);
IF X<Y THEN BEGIN scanf("%d", &Y);
H:= X; X:= Y; Y:= H while (X!=0) {if (X<Y) {H=X;
END; X=Y;
X:= X-Y; Y=H;
WHILE X<Y DO X:= X-Y }
X:= X-Y X=X-Y;
END; while (X<Y) X=X-Y;
GGT:= Y; WRITE GGT }
END. GGT=Y;
printf("%d",GGT);}
So in order to create a Tool which is able to create an SQL2D Translator
(as D2 DLL/so) just by descrining Source an Target EBNF could be a great
help.. Calling such an ready to use Translator whenever the standard D
Lexer finds SQL{ or Pascal{ or Go { should not be that difficult.
More information about the Digitalmars-d
mailing list