Re: [Q] How Is AST structured for entire program??

"Paul B Mann" <paul@paulbmann.com>
Wed, 24 Oct 2007 02:31:18 -0600

          From comp.compilers

Related articles
[Q] How Is AST structured for entire program?? heliboy2003@yahoo.com.tw (2007-10-16)
Re: [Q] How Is AST structured for entire program?? gneuner2@comcast.net (George Neuner) (2007-10-17)
Re: [Q] How Is AST structured for entire program?? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-10-17)
Re: [Q] How Is AST structured for entire program?? cfc@shell01.TheWorld.com (Chris F Clark) (2007-10-18)
Re: [Q] How Is AST structured for entire program?? paul@paulbmann.com (Paul B Mann) (2007-10-24)
| List of all articles for this month |

From: "Paul B Mann" <paul@paulbmann.com>
Newsgroups: comp.compilers
Date: Wed, 24 Oct 2007 02:31:18 -0600
Organization: Compilers Central
References: 07-10-051 07-10-056
Keywords: AST

Using the free version of LRGen (http://lrgen.com)
I get this output file (shown below) with an AST.
Make sure to view with using a fixed pitch font.


You can experiment with the C grammar and see how it
affects the structure of the AST. Textbooks are good
but hands on experience is useful too.




// LRGen Parser
// Parsing test.inp ...
// 1
// 2
// 3 void main()
// 4 {
// 5 int a;
// 6 int b;
// 7 int c;
// 8 int i;
// 9
// 10 a = 3;
// 11 b = 4;
// 12 c = a + b;
// 13
// 14 for (i = 0; i < 10; i++)
// 15 {
// 16 c = a - b;
// 17 }
// 18 }
// 19
// Parsing done, 19 lines, 0 errors.
// Symbols 99, AST nodes 50.


// Abstract Syntax Tree ...
// node next child line sti
// 49 0 5 0 0 + funcdef
// 5 48 1 0 0 + funcdecl
// 1 4 0 3 29 | + type void
// 4 0 2 0 0 | + function
// 2 3 0 3 90 | + ident main
// 3 0 0 0 0 | + absarg
// 48 0 47 0 0 + funcbody
// 47 0 6 0 0 + block
// 6 7 0 5 26 + type int
// 7 8 0 5 91 + ident a
// 8 9 0 6 26 + type int
// 9 10 0 6 92 + ident b
// 10 11 0 7 26 + type int
// 11 12 0 7 93 + ident c
// 12 13 0 8 26 + type int
// 13 17 0 8 94 + ident i
// 17 21 16 0 0 + exp
// 16 0 14 0 0 | + equals
// 14 15 0 10 91 | + ident a
// 15 0 0 10 95 | + const 3
// 21 27 20 0 0 + exp
// 20 0 18 0 0 | + equals
// 18 19 0 11 92 | + ident b
// 19 0 0 11 96 | + const 4
// 27 46 26 0 0 + exp
// 26 0 22 0 0 | + equals
// 22 25 0 12 93 | + ident c
// 25 0 23 0 0 | + add
// 23 24 0 12 91 | + ident a
// 24 0 0 12 92 | + ident b
// 46 0 31 0 0 + for
// 31 35 30 0 0 + exp1
// 30 0 28 0 0 | + equals
// 28 29 0 14 94 | + ident i
// 29 0 0 14 97 | + const 0
// 35 38 34 0 0 + exp2
// 34 0 32 0 0 | + lt
// 32 33 0 14 94 | + ident i
// 33 0 0 14 98 | + const 10
// 38 45 37 0 0 + exp3
// 37 0 36 0 0 | + postinc
// 36 0 0 14 94 | + ident i
// 45 0 44 0 0 + block
// 44 0 43 0 0 + exp
// 43 0 39 0 0 + equals
// 39 42 0 16 93 + ident c
// 42 0 40 0 0 + sub
// 40 41 0 16 91 + ident a
// 41 0 0 16 92 + ident b




Paul B Mann


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.