Parser Examples

The example below is rudimentary, but it illustrates well the information required from parser output.

Source code

int f[2] ;

int print (int x) {
  return 8 ;
}

int main (void) {
  int a ;
  int b ;

  f = f - a ;

  if ( a < f ) {
    print ( 9 ) ;
  } else {
    print ( a < f ) ;
  }

  print ( a+b ) ;
  return 12 ;
}

Parser output

** Symbol table
** Symbol table
** Symbol table
** Symbol table
** Symbol table
a is integer
b is integer
** Symbol table
** Symbol table
f is integer of size 2
print is integer function:
| Parameter: x of type int
** Abstract Syntax Tree:
Array declaration: f of type int and length Constant: 2
Function print returns int
Parameters:
| Parameter: x of type int
Body:
| Return statement
|   Constant: 8
Function main returns int
Body:
| Variable declaration: a of type int
| Variable declaration: b of type int
| Expression statement:
| | Assignment:
| | | Variable: f
| | | Operator: -
| | | | Variable: f
| | | | Variable: a
| If statement
| | Operator: <
| | | Variable: a
| | | Variable: f
| Then part
| | Expression statement:
| | | Function call: print
| | | | Argument: 
| | | | | Constant: 9
| Else part
| | Expression statement:
| | | Function call: print
| | | | Argument: 
| | | | | Operator: <
| | | | | | Variable: a
| | | | | | Variable: f
| Expression statement:
| | Function call: print
| | | Argument: 
| | | | Operator: +
| | | | | Variable: a
| | | | | Variable: b
| Return statement
|   Constant: 12