Re: [go-nuts] Go compiler - syntax tree vs AST?

2021-05-19 Thread messi...@gmail.com
>  I don't know of a way to dump the former, but perhaps there is one.

It seems there's no way to dump the former tree through any compiler flag 
by now. The dumper entry point is Fdum 
p
 
but one can only use it through UT. Maybe it's only for internal use for 
compiler developers.

>  As far as I know the most likely next evolutionary step in this area 
will be to replace the Node tree with the cmd/compile/internal/syntax tree.

Really? I see in master branch, all the Node tree related code has been 
moved to a separated package* ir(cmd/compile/internal/ir/)*, and a lot of 
work has been done for this change. Do you mean the compiler will use only 
one kind of Syntax Tree and this part of code will be eliminated in the end?

Thanks.
On Monday, May 17, 2021 at 10:49:28 AM UTC+8 spencer...@gmail.com wrote:

> > As far as I know the most likely next evolutionary step in this area 
> will be to replace the Node tree with the cmd/compile/internal/syntax tree.
> hello All, 
>   I have a question. As far as I know, the AST transformation phase has 
> been in existence for several years now. So I want to know the reason why the 
> AST transformation phase has not been eliminated now? 
>
>   Thanks in advance.
> 在2019年9月3日星期二 UTC+8 下午11:37:58 写道:
>
>> Hello Ian,
>>
>> Thank you for your answer.
>>
>> Why do you ask? 
>>
>>
>> Just out of curiosity, I was working with the SSA package for a tool, and 
>> since the compiler uses this package as well I wanted to go a bit deeper on 
>> that and write a small article on it. That's quite an interesting part but 
>> the usage of two different syntax tree was a bit confusing.
>>
>> Hope this helps
>>
>>
>> Yes, a lot. Thanks again!
>>
>> Le mardi 3 septembre 2019 17:54:38 UTC+4, Ian Lance Taylor a écrit :
>>>
>>> On Tue, Sep 3, 2019 at 6:23 AM Vincent Blanchon 
>>>  wrote: 
>>> > 
>>> > The compiler documentation mentions a syntax tree in the parsing phase 
>>> when the AST transformation phase mentions a conversion from the syntax 
>>> tree to the compiler's AST representation. 
>>> > If I do not misunderstand, the command "go tool compile -W" will 
>>> display the AST. 
>>> > 
>>> > I was wondering how far is different the syntax tree from the AST? 
>>> Where could I get documentation or an example of this syntax tree? 
>>>
>>> Note that AST just means Abstract Syntax Tree, so it's a little 
>>> confusing to talk converting a syntax tree to an AST.  What we really 
>>> have is two different ASTs. 
>>>
>>> Unfortunately none of this stuff is well documented.  The parser 
>>> generates a syntax tree as defined in cmd/compile/internal/syntax. 
>>> That is then converted to the Node tree defined in 
>>> cmd/compile/internal/gc/syntax.go.  The -W option dumps the latter.  I 
>>> don't know of a way to dump the former, but perhaps there is one. 
>>>
>>> > Also, is this syntax tree mandatory? Is it not possible to build the 
>>> AST directly from the lexer+parser? 
>>>
>>> The use of two different syntax trees is entirely historical due to 
>>> the evolution of the compiler.  The original code base was a C 
>>> compiler written in C which became a Go compiler written in C which 
>>> was machine translated from C to Go.  There has been a lot of cleanup 
>>> but there is still a lot of historical cruft.  As far as I know the 
>>> most likely next evolutionary step in this area will be to replace the 
>>> Node tree with the cmd/compile/internal/syntax tree. 
>>>
>>> Hope this helps, and I hope someone will correct me if I made a mistake. 
>>>
>>> Why do you ask? 
>>>
>>> Ian 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2e2c488c-1cc3-4072-b01c-e0c11a09eb13n%40googlegroups.com.


Re: [go-nuts] Go compiler - syntax tree vs AST?

2021-05-16 Thread liu si
> As far as I know the most likely next evolutionary step in this area will 
be to replace the Node tree with the cmd/compile/internal/syntax tree.
hello All, 
  I have a question. As far as I know, the AST transformation phase has 
been in existence for several years now. So I want to know the reason why the 
AST transformation phase has not been eliminated now? 

  Thanks in advance.
在2019年9月3日星期二 UTC+8 下午11:37:58 写道:

> Hello Ian,
>
> Thank you for your answer.
>
> Why do you ask? 
>
>
> Just out of curiosity, I was working with the SSA package for a tool, and 
> since the compiler uses this package as well I wanted to go a bit deeper on 
> that and write a small article on it. That's quite an interesting part but 
> the usage of two different syntax tree was a bit confusing.
>
> Hope this helps
>
>
> Yes, a lot. Thanks again!
>
> Le mardi 3 septembre 2019 17:54:38 UTC+4, Ian Lance Taylor a écrit :
>>
>> On Tue, Sep 3, 2019 at 6:23 AM Vincent Blanchon 
>>  wrote: 
>> > 
>> > The compiler documentation mentions a syntax tree in the parsing phase 
>> when the AST transformation phase mentions a conversion from the syntax 
>> tree to the compiler's AST representation. 
>> > If I do not misunderstand, the command "go tool compile -W" will 
>> display the AST. 
>> > 
>> > I was wondering how far is different the syntax tree from the AST? 
>> Where could I get documentation or an example of this syntax tree? 
>>
>> Note that AST just means Abstract Syntax Tree, so it's a little 
>> confusing to talk converting a syntax tree to an AST.  What we really 
>> have is two different ASTs. 
>>
>> Unfortunately none of this stuff is well documented.  The parser 
>> generates a syntax tree as defined in cmd/compile/internal/syntax. 
>> That is then converted to the Node tree defined in 
>> cmd/compile/internal/gc/syntax.go.  The -W option dumps the latter.  I 
>> don't know of a way to dump the former, but perhaps there is one. 
>>
>> > Also, is this syntax tree mandatory? Is it not possible to build the 
>> AST directly from the lexer+parser? 
>>
>> The use of two different syntax trees is entirely historical due to 
>> the evolution of the compiler.  The original code base was a C 
>> compiler written in C which became a Go compiler written in C which 
>> was machine translated from C to Go.  There has been a lot of cleanup 
>> but there is still a lot of historical cruft.  As far as I know the 
>> most likely next evolutionary step in this area will be to replace the 
>> Node tree with the cmd/compile/internal/syntax tree. 
>>
>> Hope this helps, and I hope someone will correct me if I made a mistake. 
>>
>> Why do you ask? 
>>
>> Ian 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c765be68-1745-4d98-84b3-7762745cea6en%40googlegroups.com.


Re: [go-nuts] Go compiler - syntax tree vs AST?

2019-09-03 Thread Vincent Blanchon
Hello Ian,

Thank you for your answer.

Why do you ask? 


Just out of curiosity, I was working with the SSA package for a tool,  and 
since the compiler uses this package as well I wanted to go a bit deeper on 
that and write a small article on it. That's quite an interesting part but 
the usage of two different syntax tree was a bit confusing.

Hope this helps


Yes, a lot. Thanks again!

Le mardi 3 septembre 2019 17:54:38 UTC+4, Ian Lance Taylor a écrit :
>
> On Tue, Sep 3, 2019 at 6:23 AM Vincent Blanchon 
>  wrote: 
> > 
> > The compiler documentation mentions a syntax tree in the parsing phase 
> when the AST transformation phase mentions a conversion from the syntax 
> tree to the compiler's AST representation. 
> > If I do not misunderstand, the command "go tool compile -W" will display 
> the AST. 
> > 
> > I was wondering how far is different the syntax tree from the AST? Where 
> could I get documentation or an example of this syntax tree? 
>
> Note that AST just means Abstract Syntax Tree, so it's a little 
> confusing to talk converting a syntax tree to an AST.  What we really 
> have is two different ASTs. 
>
> Unfortunately none of this stuff is well documented.  The parser 
> generates a syntax tree as defined in cmd/compile/internal/syntax. 
> That is then converted to the Node tree defined in 
> cmd/compile/internal/gc/syntax.go.  The -W option dumps the latter.  I 
> don't know of a way to dump the former, but perhaps there is one. 
>
> > Also, is this syntax tree mandatory? Is it not possible to build the AST 
> directly from the lexer+parser? 
>
> The use of two different syntax trees is entirely historical due to 
> the evolution of the compiler.  The original code base was a C 
> compiler written in C which became a Go compiler written in C which 
> was machine translated from C to Go.  There has been a lot of cleanup 
> but there is still a lot of historical cruft.  As far as I know the 
> most likely next evolutionary step in this area will be to replace the 
> Node tree with the cmd/compile/internal/syntax tree. 
>
> Hope this helps, and I hope someone will correct me if I made a mistake. 
>
> Why do you ask? 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/73d829f2-bdcc-4615-b82e-3dce43abd8cf%40googlegroups.com.


Re: [go-nuts] Go compiler - syntax tree vs AST?

2019-09-03 Thread Ian Lance Taylor
On Tue, Sep 3, 2019 at 6:23 AM Vincent Blanchon
 wrote:
>
> The compiler documentation mentions a syntax tree in the parsing phase when 
> the AST transformation phase mentions a conversion from the syntax tree to 
> the compiler's AST representation.
> If I do not misunderstand, the command "go tool compile -W" will display the 
> AST.
>
> I was wondering how far is different the syntax tree from the AST? Where 
> could I get documentation or an example of this syntax tree?

Note that AST just means Abstract Syntax Tree, so it's a little
confusing to talk converting a syntax tree to an AST.  What we really
have is two different ASTs.

Unfortunately none of this stuff is well documented.  The parser
generates a syntax tree as defined in cmd/compile/internal/syntax.
That is then converted to the Node tree defined in
cmd/compile/internal/gc/syntax.go.  The -W option dumps the latter.  I
don't know of a way to dump the former, but perhaps there is one.

> Also, is this syntax tree mandatory? Is it not possible to build the AST 
> directly from the lexer+parser?

The use of two different syntax trees is entirely historical due to
the evolution of the compiler.  The original code base was a C
compiler written in C which became a Go compiler written in C which
was machine translated from C to Go.  There has been a lot of cleanup
but there is still a lot of historical cruft.  As far as I know the
most likely next evolutionary step in this area will be to replace the
Node tree with the cmd/compile/internal/syntax tree.

Hope this helps, and I hope someone will correct me if I made a mistake.

Why do you ask?

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWpRLeV1_jGnGszRUfLviQ0B1a%2BgTJfOeNjZUHV0tSDnA%40mail.gmail.com.


[go-nuts] Go compiler - syntax tree vs AST?

2019-09-03 Thread Vincent Blanchon
Hi all,

The compiler documentation mentions a syntax tree in the parsing phase when 
the AST transformation phase mentions a conversion from the syntax tree to 
the compiler's AST representation.
If I do not misunderstand, the command "*go tool compile -W" *will display 
the AST.

I was wondering how far is different the syntax tree from the AST? Where 
could I get documentation or an example of this syntax tree?
Also, is this syntax tree mandatory? Is it not possible to build the AST 
directly from the lexer+parser?

Thanks in advance

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a48a5771-e504-4078-8f45-bb803e10ea75%40googlegroups.com.