Main Page | Class List | Directories | File List | Class Members | File Members

cc_parse.c File Reference

CKPM C compiler parser. More...

#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "cpp_io.h"
#include "cpp_conv.h"
#include "cpp_token.h"
#include "cc_scan.h"
#include "cc_parse.h"
#include "cc_message_list.h"
#include "cc_code_gen.h"

Functions

int Struct_Declaration (struct _parser *p, char *name)
 handle a struct declaration statement
int Array_Declaration (struct _parser *p, char *typ, int pointer, char *name)
 handle a array declaration statement
int Array_Initialisation (struct _parser *p, char *typ, int pointer, char *name, int dim)
 handle the initialisation of an array declaration statement
int Variable_Declaration (struct _parser *p, char *typ, int pointer, char *name)
 handle a function declaration statement
int Function_Declaration (struct _parser *p, char *typ, int pointer, char *name)
 handle a function declaration statement
int extern_Declaration (struct _parser *p)
 handle a extern declaration statement
int Block (struct _parser *p, struct _item *s)
 handle a function declaration statement
int Data_Declaration (struct _parser *p)
 handle a data declaration statement
int if_Statement (struct _parser *p, struct _item *s)
 handle a if statement
int while_Statement (struct _parser *p, struct _item *s)
 handle a while statement
int break_Statement (struct _parser *p, struct _item *s)
 handle a break statement
int continue_Statement (struct _parser *p, struct _item *s)
 handle a continue statement
int return_Statement (struct _parser *p, struct _item *s)
 handle a return statement
int Assignment_Expression (struct _parser *p, struct _item *sx)
 handle an assignment expression
int Statement (struct _parser *p, struct _item *s)
 handle a statement
int List_Value (struct _parser *p, int sym, struct _item *x)
 handle a list value
int Selector (struct _parser *p, struct _item *x)
 handle a selector
int Logical_Or_Expression (struct _parser *p, struct _item *x)
 handle a logical or expression
int Logical_And_Expression (struct _parser *p, struct _item *x)
 handle a logical and expression
int Conditional_Expression (struct _parser *p, struct _item *x)
 handle a conditional expression
int Simple_Expression (struct _parser *p, struct _item *x)
 handle a simple expression
int Term (struct _parser *p, struct _item *x)
 handle a term
int Factor (struct _parser *p, struct _item *x)
 handle a factor
_parserParser_Create (int fd_in, int fd_out, int fd_err)
 create and initialize a new parse
void Parser_Destroy (struct _parser *p)
 destroy a parser and all its components
void Parser_Error (struct _parser *p, char *s1, char *s2)
 write a parser error message
void Parser_Warning (struct _parser *p, char *s1, char *s2)
 write a parser warning message
void Parser_Info (struct _parser *p, char *s1, char *s2)
 write a parser info message
void Print_Token (struct _parser *p)
 print a token
void GetSymCC (struct _parser *p)
 get next scanner symbol
void SkipToSymCC (struct _parser *p, int sym)
 skip symbols until the desired symbol is found or the file has ended
int SetSavePoint (struct _parser *p)
 set save point for token saving
void Rewind (struct _parser *p, int sph)
 rewind to last save point and deliver the tokens again
void Block_Rewind (struct _parser *p)
 disallow rewinding to last savepoint
void Release (struct _parser *p, int sph)
 release last save point
int is_SimpleType (int sym)
 check if a given symbol is a simple (builtin) type
int Declaration_Statement (struct _parser *p, int no_fct)
 handle a declaration statement
int Is_Parameter (struct _object *par)
 check if object is a function parameter
int Is_Type_Equal (struct _type *a, struct _type *b)
 check if two type descriptions are equivalent
int cc_parse (struct _parser *p)
 the C compiler parser
_objectNewObj (struct _parser *p, class_t cls, char *ident)
 create a new object node
void DelObj (struct _parser *p, struct _object *o)
 delete an object from the symbol table
_objectFind (struct _parser *p, char *ident, int err)
 find an object
_objectFindField (struct _parser *p, struct _object *list)
 find an object field
int Compare_Field_Types (struct _parser *p, struct _object *f1, struct _object *f2)
 compare the types of two field lists
void Destroy_Fields (struct _parser *p, struct _object *f)
 destroy a field list
void Make_Item (struct _parser *p, struct _item *x, struct _object *obj)
 create a named item
void Make_Const_Item (struct _parser *p, struct _item *x, struct _type *typ, int val)
 create a named item
void Make_Link_Item (struct _parser *p, struct _item *x, struct _type *typ, int st, int end, int ret, int wl)
 create a link item
void Make_Void_Item (struct _parser *p, struct _item *x)
 create a void item
void Make_Boolean_Item (struct _parser *p, struct _item *x)
 create a boolean item
void Make_Temp_Item (struct _parser *p, struct _item *x, class_t md, struct _type *ty)
 create a temporary item
void Pre_Increment (struct _parser *p, struct _item *x)
 increment a given variable before its use
void Pre_Decrement (struct _parser *p, struct _item *x)
 decrement a given variable before its use
void Post_Increment (struct _parser *p, struct _item *x)
 increment a given variable after its use
void Post_Decrement (struct _parser *p, struct _item *x)
 decrement a given variable after its use
void Index (struct _parser *p, struct _item *x, struct _item *y)
 array access
void Field (struct _parser *p, struct _item *x, struct _object *y)
 struct field access x = x.y
void PointerField (struct _parser *p, struct _item *x, struct _object *y)
 struct field access x = x->y
void Load_Boolean (struct _parser *p, struct _item *x)
 load a boolean variable onto the stack
void Store (struct _parser *p, struct _item *x, struct _item *y)
 store a variable x = y;
void Relation (struct _parser *p, int op, struct _item *x, struct _item *y)
 store a variable x = y;
int Get_Unary_Operator (struct _parser *p)
 get an unary operator
void Unary_Operator (struct _parser *p, int op, struct _item *x)
 generate code for unary operators: x = op x;
void Dual_Operator (struct _parser *p, int op, struct _item *x, struct _item *y)
 generate code for dual operators: x = y op z;
void Conditional_Jump (struct _parser *p, struct _item *x)
 handle a conditional jump


Detailed Description

CKPM C compiler parser.


Function Documentation

int Array_Declaration struct _parser p,
char *  typ,
int  pointer,
char *  name
 

handle a array declaration statement

Parameters:
p a pointer to the parser
typ the name of the array variable type
pointer contains how many times the type has to be dereferenced
name the name of the array variable
Returns:
1 on success, otherwise 0 This subroutine is called after the left bracket was recognised.

int Array_Initialisation struct _parser p,
char *  typ,
int  pointer,
char *  name,
int  dim
 

handle the initialisation of an array declaration statement

Parameters:
p a pointer to the parser
typ the name of the array variable type
pointer contains how many times the type has to be dereferenced
name the name of the array variable
dim the dimenstion of the array
Returns:
1 on success, otherwise 0

int Assignment_Expression struct _parser p,
struct _item sx
 

handle an assignment expression

Parameters:
p a pointer to the parser
sx the statement item
Returns:
1 on success, otherwise 0

int Block struct _parser p,
struct _item s
 

handle a function declaration statement

Parameters:
p a pointer to the parser
s the associated link item
Returns:
1 on success, otherwise 0

void Block_Rewind struct _parser p  ) 
 

disallow rewinding to last savepoint

Parameters:
p a pointer to the parser

int break_Statement struct _parser p,
struct _item s
 

handle a break statement

Parameters:
p a pointer to the parser
s the associated link item
Returns:
1 on success, otherwise 0

int cc_parse struct _parser p  ) 
 

the C compiler parser

Parameters:
p a pointer to the parser
Returns:
1 on success, otherwise 0

int Compare_Field_Types struct _parser p,
struct _object f1,
struct _object f2
 

compare the types of two field lists

Parameters:
p a pointer to the parser
f1 the first field list
f2 the second field list
Returns:
1 if the field list have the same types in the same order, otherwise 0

int Conditional_Expression struct _parser p,
struct _item x
 

handle a conditional expression

Parameters:
p a pointer to the parser
x the statement item
Returns:
1 on success, otherwise 0

void Conditional_Jump struct _parser p,
struct _item x
 

handle a conditional jump

Parameters:
p a pointer to the parser
x jump target

int continue_Statement struct _parser p,
struct _item s
 

handle a continue statement

Parameters:
p a pointer to the parser
s the associated link item
Returns:
1 on success, otherwise 0

int Data_Declaration struct _parser p  ) 
 

handle a data declaration statement

Parameters:
p a pointer to the parser
Returns:
1 on success, otherwise 0

int Declaration_Statement struct _parser p,
int  no_fct
 

handle a declaration statement

Parameters:
p a pointer to the parser
no_fct != 0 allows no function declaration
Returns:
1 on success, otherwise 0

void DelObj struct _parser p,
struct _object o
 

delete an object from the symbol table

Parameters:
p a pointer to the parser
o a pointer to the object to be deleted

void Destroy_Fields struct _parser p,
struct _object f
 

destroy a field list

Parameters:
p a pointer to the parser
f the field list to be destroyed

void Dual_Operator struct _parser p,
int  op,
struct _item x,
struct _item y
 

generate code for dual operators: x = y op z;

Parameters:
p a pointer to the parser
op the operator
x the first item
y the second item

int extern_Declaration struct _parser p  ) 
 

handle a extern declaration statement

Parameters:
p a pointer to the parser
Returns:
1 on success, otherwise 0

int Factor struct _parser p,
struct _item x
 

handle a factor

Parameters:
p a pointer to the parser
x the statement item
Returns:
1 on success, otherwise 0

void Field struct _parser p,
struct _item x,
struct _object y
 

struct field access x = x.y

Parameters:
p a pointer to the parser
x a pointer to the item structure
y a pointer to the object structure

struct _object* Find struct _parser p,
char *  ident,
int  err
 

find an object

Parameters:
p a pointer to the parser
ident the name of the identifier
err print an error message if the identifier is not found
Returns:
a pointer to the found object

struct _object* FindField struct _parser p,
struct _object list
 

find an object field

Parameters:
p a pointer to the parser
list the field list
Returns:
a pointer to the found object field

int Function_Declaration struct _parser p,
char *  typ,
int  pointer,
char *  name
 

handle a function declaration statement

Parameters:
p a pointer to the parser
typ the name of the return type
pointer contains how many times the return type has to be dereferenced
name the name of the function
Returns:
1 on success, otherwise 0 This subroutine is called after the left parenthesis was recognised.

int Get_Unary_Operator struct _parser p  ) 
 

get an unary operator

Parameters:
p a pointer to the parser
Returns:
if present the unary operator, otherwise SYM_OTHER

void GetSymCC struct _parser p  ) 
 

get next scanner symbol

Parameters:
p a pointer to the parser

int if_Statement struct _parser p,
struct _item s
 

handle a if statement

Parameters:
p a pointer to the parser
s the statement item
Returns:
1 on success, otherwise 0

void Index struct _parser p,
struct _item x,
struct _item y
 

array access

Parameters:
p a pointer to the parser
x a pointer to the item structure
y a pointer to the item structure
this subroutine is responsible to emit code for this construct x = x[y]

int Is_Parameter struct _object par  ) 
 

check if object is a function parameter

Parameters:
par a pointer to the parameter object
Returns:
!= 0 if par is a parameter, otherwise 0

int is_SimpleType int  sym  ) 
 

check if a given symbol is a simple (builtin) type

Parameters:
sym the symbol
Returns:
1 if the symbol is a simple type, otherwise 0

int Is_Type_Equal struct _type a,
struct _type b
 

check if two type descriptions are equivalent

Parameters:
a pointer to the first type description
b a pointer to the second type description
Returns:
!= 0 if the two type descriptions are equivalent

int List_Value struct _parser p,
int  sym,
struct _item x
 

handle a list value

Parameters:
p a pointer to the parser
sym the previous symbol
x a pointer to the actual item
Returns:
1 on success, otherwise 0

void Load_Boolean struct _parser p,
struct _item x
 

load a boolean variable onto the stack

Parameters:
p a pointer to the parser
x the item to be loaded

int Logical_And_Expression struct _parser p,
struct _item x
 

handle a logical and expression

Parameters:
p a pointer to the parser
x the statement item
Returns:
1 on success, otherwise 0

int Logical_Or_Expression struct _parser p,
struct _item x
 

handle a logical or expression

Parameters:
p a pointer to the parser
x the statement item
Returns:
1 on success, otherwise 0

void Make_Boolean_Item struct _parser p,
struct _item x
 

create a boolean item

Parameters:
p a pointer to the parser
x a pointer to the item structure

void Make_Const_Item struct _parser p,
struct _item x,
struct _type typ,
int  val
 

create a named item

Parameters:
p a pointer to the parser
x a pointer to the item structure
typ a pointer to the type description of the constant
val the address in the data segment ?

void Make_Item struct _parser p,
struct _item x,
struct _object obj
 

create a named item

Parameters:
p a pointer to the parser structure
x a pointer to the item structure
obj a pointer to the corresponding object

void Make_Link_Item struct _parser p,
struct _item x,
struct _type typ,
int  st,
int  end,
int  ret,
int  wl
 

create a link item

Parameters:
p a pointer to the parser
x a pointer to the item structure
typ a pointer to the type description of the function
st the start address of the surrounding block
end the end address of the surrounding block
ret the return address of the surrounding subroutine
wl if != 0 a surrounding while loop exists

void Make_Temp_Item struct _parser p,
struct _item x,
class_t  md,
struct _type ty
 

create a temporary item

Parameters:
p a pointer to the parser
x a pointer to the item structure
md the item's mode
ty the item's type

void Make_Void_Item struct _parser p,
struct _item x
 

create a void item

Parameters:
p a pointer to the parser
x a pointer to the item structure

struct _object* NewObj struct _parser p,
class_t  cls,
char *  ident
 

create a new object node

Parameters:
p a pointer to the parser
cls the object class
ident the name of the identifier
Returns:
a pointer to the new object

struct _parser* Parser_Create int  fd_in,
int  fd_out,
int  fd_err
 

create and initialize a new parse

Parameters:
fd_in file descriptor index of the input file
fd_out file descriptor index of the output file
fd_err file descriptor index of the error output file
Returns:
a pointer to the parser

void Parser_Destroy struct _parser p  ) 
 

destroy a parser and all its components

Parameters:
p a pointer to the parser

void Parser_Error struct _parser p,
char *  s1,
char *  s2
 

write a parser error message

Parameters:
p a pointer to the parser
s1 first string of the error message
s2 first string of the error message

void Parser_Info struct _parser p,
char *  s1,
char *  s2
 

write a parser info message

Parameters:
p a pointer to the parser
s1 first string of the warning message
s2 first string of the warning message

void Parser_Warning struct _parser p,
char *  s1,
char *  s2
 

write a parser warning message

Parameters:
p a pointer to the parser
s1 first string of the warning message
s2 first string of the warning message

void PointerField struct _parser p,
struct _item x,
struct _object y
 

struct field access x = x->y

Parameters:
p a pointer to the parser
x a pointer to the item structure
y a pointer to the object structure

void Post_Decrement struct _parser p,
struct _item x
 

decrement a given variable after its use

Parameters:
p a pointer to the parser
x a pointer to the item structure

void Post_Increment struct _parser p,
struct _item x
 

increment a given variable after its use

Parameters:
p a pointer to the parser
x a pointer to the item structure

void Pre_Decrement struct _parser p,
struct _item x
 

decrement a given variable before its use

Parameters:
p a pointer to the parser
x a pointer to the item structure

void Pre_Increment struct _parser p,
struct _item x
 

increment a given variable before its use

Parameters:
p a pointer to the parser
x a pointer to the item structure

void Print_Token struct _parser p  ) 
 

print a token

Parameters:
p a pointer to the parser

void Relation struct _parser p,
int  op,
struct _item x,
struct _item y
 

store a variable x = y;

Parameters:
p a pointer to the parser
op the operation to be performed
x the item where y should be stored
y the item of the calculated value

void Release struct _parser p,
int  sph
 

release last save point

Parameters:
p a pointer to the parser
sph the handle of the save point

int return_Statement struct _parser p,
struct _item s
 

handle a return statement

Parameters:
p a pointer to the parser
s the associated link item
Returns:
1 on success, otherwise 0

void Rewind struct _parser p,
int  sph
 

rewind to last save point and deliver the tokens again

Parameters:
p a pointer to the parser
sph the handle of the save point

int Selector struct _parser p,
struct _item x
 

handle a selector

Parameters:
p a pointer to the parser
x a pointer to the actual item
Returns:
1 on success, otherwise 0

int SetSavePoint struct _parser p  ) 
 

set save point for token saving

Parameters:
p a pointer to the parser
Returns:
a handle to the actual save point

int Simple_Expression struct _parser p,
struct _item x
 

handle a simple expression

Parameters:
p a pointer to the parser
x a pointer to the actual item
Returns:
1 on success, otherwise 0

void SkipToSymCC struct _parser p,
int  sym
 

skip symbols until the desired symbol is found or the file has ended

Parameters:
p a pointer to the parser
sym the symbol to skip to

int Statement struct _parser p,
struct _item s
 

handle a statement

Parameters:
p a pointer to the parser
s the statement item
Returns:
1 on success, otherwise 0

void Store struct _parser p,
struct _item x,
struct _item y
 

store a variable x = y;

Parameters:
p a pointer to the parser
x the item where y should be stored
y the item of the calculated value

int Struct_Declaration struct _parser p,
char *  name
 

handle a struct declaration statement

Parameters:
p a pointer to the parser
name the name of the struct
Returns:
1 on success, otherwise 0 This subroutine is called after the left brace was recognised. It collects the declarations of all struct members.

int Term struct _parser p,
struct _item x
 

handle a term

Parameters:
p a pointer to the parser
x the statement item
Returns:
1 on success, otherwise 0

void Unary_Operator struct _parser p,
int  op,
struct _item x
 

generate code for unary operators: x = op x;

Parameters:
p a pointer to the parser
op the operator
x the item

int Variable_Declaration struct _parser p,
char *  typ,
int  pointer,
char *  name
 

handle a function declaration statement

Parameters:
p a pointer to the parser
typ the name of the variable type
pointer contains how many times the type has to be dereferenced
name the name of the variable
Returns:
1 on success, otherwise 0

int while_Statement struct _parser p,
struct _item s
 

handle a while statement

Parameters:
p a pointer to the parser
s the statement item
Returns:
1 on success, otherwise 0


Generated on Thu Jul 13 03:56:36 2006 for CKPMcc by  doxygen 1.4.4