Can be ANTLR
used for parsing source code of one language and create source code for another language?
Because so far, looking at all those listeners I cannot see a way to segregate separate facilities - like different statement
blocks and etc. - in order to create another language facilities
(program (programHeading program (identifier HelloWorld) ;)
(block (procedureAndFunctionDeclarationPart (procedureOrFunctionDeclaration
(procedureDeclaration procedure (identifier myprocedure) (formalParameterList (
(formalParameterSection (parameterGroup (identifierList (identifier x) , (identifier y)) : (typeIdentifier integer))) )) ;
(block (compoundStatement begin (statements (statement (unlabelledStatement (simpleStatement (procedureStatement (identifier writeln) (
(parameterList (actualParameter (expression (simpleExpression (term (signedFactor (factor (variable (identifier x))))) + (term (signedFactor
(factor (unsignedConstant (string ' : '))))) + (term (signedFactor (factor (variable (identifier y))))))))) ))))) ;
(statement (unlabelledStatement (simpleStatement emptyStatement)))) end)))) ;) (compoundStatement begin (statements
(statement (unlabelledStatement (simpleStatement (procedureStatement (identifier from))))) i := 1 to 10 do begin writeln ( i ) ;) end)) ; writeln ( 'Hello, World!' ) ; end .)
For example there I cannot see a way to define where one begin
statement started and another ended end
.
Well I can do something using stack
helpers but I can parse file line by line myself in that case...
It is the parse result of this code
program HelloWorld;
procedure myprocedure(x, y: integer);
begin
writeln(x + ' : ' + y);
end;
begin
from i := 1 to 10 do
begin
writeln(i);
end;
writeln('Hello, World!');
end.
Maybe I am just looking from the wrong side or do not understand something?