Commits

Corentin Derbois committed f770c52

Make beginnin of the ast generation

Comments (0)

Files changed (3)

 	| FUN_dec_list of declarator * declaration_list * compound_statement
 	| FUN_dec of declarator * compound_statement
 	
-type not_implemented = 
-	NotImplemented
+
          Lexing.pos_lnum = pos.Lexing.pos_lnum + 1;
          Lexing.pos_bol = pos.Lexing.pos_cnum - delta;
        }
-;;
+       
 }
 
 let eol = '\013' '\010' | '\013' | '\010'
 | "void"		{VOID}
 | "volatile"{VOLATILE}
 | "while"		{WHILE}
+
 (* Not totaly sure part *)
-| L(L|D*)*   {IDENTIFIER}
-| D+        {CONSTANT}
+
+| L(L|D*)*   {IDENTIFIER(get lexbuf)}
+| D+        {CONSTANT(get lexbuf)}
 | L?['"']L*['"'] {STRING_LITERAL}
 
 (* end of Not totaly ... *)
+
 | "..."			{ELLIPSIS}
 | ">>="			{RIGHT_ASSIGN}
 | "<<="			{LEFT_ASSIGN}
-%token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
+%{
+   exception NotImplemented of string
+%}
+
+%token <string> IDENTIFIER
+%token <string> CONSTANT
+%token STRING_LITERAL SIZEOF
 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
 %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
 %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
 %%
 
 primary_expression
-	: IDENTIFIER { Ast.None }
-	| CONSTANT { Ast.None }
-	| STRING_LITERAL { Ast.None }
-	| LEFTPARA expression RIGHTPARA { Ast.None }
+	: IDENTIFIER
+		{ Ast.PE_IDENTIFIER $1 }
+	| CONSTANT
+		{ Ast.PE_CONSTANT $1 }
+	| STRING_LITERAL
+		{ raise (NotImplemented "PE_STRING_LITERAL") }
+	| LEFTPARA expression RIGHTPARA
+		{ raise (NotImplemented "PE_Expression") }
 	;
 
 postfix_expression
-	: primary_expression { Ast.None }
-	| postfix_expression LEFTCRO expression RIGHTCRO { Ast.None }
-	| postfix_expression LEFTPARA RIGHTPARA { Ast.None }
-	| postfix_expression LEFTPARA argument_expression_list RIGHTPARA { Ast.None }
-	| postfix_expression POINT IDENTIFIER { Ast.None }
-	| postfix_expression PTR_OP IDENTIFIER { Ast.None }
-	| postfix_expression INC_OP { Ast.None }
-	| postfix_expression DEC_OP { Ast.None }
+	: primary_expression
+		{ Ast.PE_pri_exp $1 }
+	| postfix_expression LEFTCRO expression RIGHTCRO
+		{ raise (NotImplemented "PE_exp") }
+	| postfix_expression LEFTPARA RIGHTPARA
+		{ raise (NotImplemented "PE_empty") }
+	| postfix_expression LEFTPARA argument_expression_list RIGHTPARA
+		{ raise (NotImplemented "PE_arg_exp_list") }
+	| postfix_expression POINT IDENTIFIER
+		{ raise (NotImplemented "PE_id") }
+	| postfix_expression PTR_OP IDENTIFIER
+		{ raise (NotImplemented "PE_prt") }
+	| postfix_expression INC_OP
+		{ raise (NotImplemented "PE_inc") }
+	| postfix_expression DEC_OP
+		{ raise (NotImplemented "PE_dec") }
 	;
 
 argument_expression_list
 	;
 
 unary_expression
-	: postfix_expression { Ast.None }
-	| INC_OP unary_expression { Ast.None }
-	| DEC_OP unary_expression { Ast.None }
-	| unary_operator cast_expression { Ast.None }
-	| SIZEOF unary_expression { Ast.None }
-	| SIZEOF LEFTPARA type_name RIGHTPARA { Ast.None }
+	: postfix_expression
+		{ Ast.UE_post_exp $1 }
+	| INC_OP unary_expression
+		{ raise (NotImplemented "UE_inc") }
+	| DEC_OP unary_expression
+		{ raise (NotImplemented "UE_dec") }
+	| unary_operator cast_expression
+		{ raise (NotImplemented "UE_cast") }
+	| SIZEOF unary_expression
+		{ raise (NotImplemented "UE_size_ue") }
+	| SIZEOF LEFTPARA type_name RIGHTPARA
+		{ raise (NotImplemented "UE_size_type") }
 	;
 
 unary_operator
-	: EPERLUET { Ast.None }
-	| FOIS { Ast.None }
-	| PLUS { Ast.None }
-	| MOIN { Ast.None }
-	| VAGUE { Ast.None }
-	| POINTEXCLA { Ast.None }
+	: EPERLUET
+		{ Ast.UO_EPERLUET }
+	| FOIS
+		{ Ast.UO_FOIS }
+	| PLUS
+		{ Ast.UO_PLUS }
+	| MOIN
+		{ Ast.UO_MOIN }
+	| VAGUE
+		{ Ast.UO_VAGUE }
+	| POINTEXCLA
+		{ Ast.UO_POINTEXCLA }
 	;
 
 cast_expression
-	: unary_expression { Ast.None }
-	| LEFTPARA type_name RIGHTPARA cast_expression { Ast.None }
+	: unary_expression
+		{ Ast.CA_unary_expression $1 }
+	| LEFTPARA type_name RIGHTPARA cast_expression
+		{ raise (NotImplemented "CA_type") }
 	;
 
 multiplicative_expression
-	: cast_expression { Ast.None }
-	| multiplicative_expression FOIS cast_expression { Ast.None }
-	| multiplicative_expression DIV cast_expression { Ast.None }
-	| multiplicative_expression POURCENT cast_expression { Ast.None }
+	: cast_expression
+		{ Ast.ME_exp $1 }
+	| multiplicative_expression FOIS cast_expression
+		{ raise (NotImplemented "ME_fois") }
+	| multiplicative_expression DIV cast_expression
+		{ raise (NotImplemented "ME_div") }
+	| multiplicative_expression POURCENT cast_expression
+		{ raise (NotImplemented "ME_pourcent") }
 	;
 
 additive_expression
-	: multiplicative_expression { Ast.None }
-	| additive_expression PLUS multiplicative_expression { Ast.None }
-	| additive_expression MOIN multiplicative_expression { Ast.None }
+	: multiplicative_expression
+		{ Ast.AE_exp $1 }
+	| additive_expression PLUS multiplicative_expression
+		{ raise (NotImplemented "AE_plus") }
+	| additive_expression MOIN multiplicative_expression
+		{ raise (NotImplemented "AE_moin") }
 	;
 
 shift_expression
-	: additive_expression { Ast.None }
-	| shift_expression LEFT_OP additive_expression { Ast.None }
-	| shift_expression RIGHT_OP additive_expression { Ast.None }
+	: additive_expression
+		{ Ast.SE_exp $1 }
+	| shift_expression LEFT_OP additive_expression
+		{ raise (NotImplemented "SE_left") }
+	| shift_expression RIGHT_OP additive_expression
+		{ raise (NotImplemented "SE_right") }
 	;
 
 relational_expression
-	: shift_expression { Ast.None }
-	| relational_expression LEFTCHE shift_expression { Ast.None }
-	| relational_expression RIGHTCHE shift_expression { Ast.None }
-	| relational_expression LE_OP shift_expression { Ast.None }
-	| relational_expression GE_OP shift_expression { Ast.None }
+	: shift_expression 
+		{ Ast.RE_exp $1 }
+	| relational_expression LEFTCHE shift_expression 
+		{ raise (NotImplemented "RE_left") }
+	| relational_expression RIGHTCHE shift_expression 
+		{ raise (NotImplemented "RE_right") }
+	| relational_expression LE_OP shift_expression 
+		{ raise (NotImplemented "RE_less") }
+	| relational_expression GE_OP shift_expression 
+		{ raise (NotImplemented "RE_gretter") }
 	;
 
 equality_expression
-	: relational_expression { Ast.None }
-	| equality_expression EQ_OP relational_expression { Ast.None }
-	| equality_expression NE_OP relational_expression { Ast.None }
+	: relational_expression
+		{ Ast.EE_exp $1 }
+	| equality_expression EQ_OP relational_expression
+		{ raise (NotImplemented "EE_eq") }
+	| equality_expression NE_OP relational_expression
+		{ raise (NotImplemented "EE_ne") }
 	;
 
 and_expression
-	: equality_expression { Ast.None }
-	| and_expression EPERLUET equality_expression { Ast.None }
+	: equality_expression 
+		{ Ast.ANE_eq $1 }
+	| and_expression EPERLUET equality_expression 
+		{ raise (NotImplemented "ANE_and") }
 	;
 
 exclusive_or_expression
-	: and_expression { Ast.None }
-	| exclusive_or_expression CIRCON and_expression { Ast.None }
+	: and_expression 
+		{ Ast.EXEX_and $1 }
+	| exclusive_or_expression CIRCON and_expression 
+		{ raise (NotImplemented "EXEX_circon") }
 	;
 
 inclusive_or_expression
-	: exclusive_or_expression { Ast.None }
-	| inclusive_or_expression PIPE exclusive_or_expression { Ast.None }
+	: exclusive_or_expression
+		{ Ast.INE_exp $1 }
+	| inclusive_or_expression PIPE exclusive_or_expression
+		{ raise (NotImplemented "INE_pipe") }
 	;
 
 logical_and_expression
-	: inclusive_or_expression { Ast.None }
-	| logical_and_expression AND_OP inclusive_or_expression { Ast.None }
+	: inclusive_or_expression 
+		{ Ast.LAE_exp $1 }
+	| logical_and_expression AND_OP inclusive_or_expression 
+		{ raise (NotImplemented "LAE_and") }
 	;
 
 logical_or_expression
-	: logical_and_expression { Ast.None }
-	| logical_or_expression OR_OP logical_and_expression { Ast.None }
+	: logical_and_expression
+		{ Ast.LOE_exp $1 }
+	| logical_or_expression OR_OP logical_and_expression
+		{ raise (NotImplemented "LOE_or") }
 	;
 
 conditional_expression
-	: logical_or_expression { Ast.None }
-	| logical_or_expression POINTINTERO expression TWOPOINT conditional_expression { Ast.None }
+	: logical_or_expression
+		{ Ast.COE_exp $1 }
+	| logical_or_expression POINTINTERO expression TWOPOINT conditional_expression
+		{ raise (NotImplemented "COE_int") }
 	;
 
 assignment_expression
-	: conditional_expression { Ast.None }
-	| unary_expression assignment_operator assignment_expression { Ast.None }
+	: conditional_expression
+		{ Ast.ASE_exp $1 }
+	| unary_expression assignment_operator assignment_expression
+		{ raise (NotImplemented "ASE_op") }
 	;
 
 assignment_operator
 	;
 
 expression
-	: assignment_expression { Ast.None }
-	| expression VIRGULE assignment_expression { Ast.None }
+	: assignment_expression
+		{ Ast.E_exp $1 }
+	| expression VIRGULE assignment_expression
+		{ raise (NotImplemented "E_list") }
 	;
 
 constant_expression
 	;
 
 declaration_specifiers
-	: storage_class_specifier { Ast.None }
-	| storage_class_specifier declaration_specifiers { Ast.None }
-	| type_specifier { Ast.None }
-	| type_specifier declaration_specifiers { Ast.None }
-	| type_qualifier { Ast.None }
-	| type_qualifier declaration_specifiers { Ast.None }
+	: storage_class_specifier 
+		{ raise (NotImplemented "DES_class") }
+	| storage_class_specifier declaration_specifiers 
+		{ raise (NotImplemented "DES_class_dec") }
+	| type_specifier 
+		{ Ast.DES_type $1 }
+	| type_specifier declaration_specifiers 
+		{ raise (NotImplemented "DES_type_dec") }
+	| type_qualifier 
+		{ raise (NotImplemented "DES_type_qua") }
+	| type_qualifier declaration_specifiers 
+		{ raise (NotImplemented "DES_type_qua_dec") }
 	;
 
 init_declarator_list
 	;
 
 type_specifier
-	: VOID { Ast.None }
-	| CHAR { Ast.None }
-	| SHORT { Ast.None }
-	| INT { Ast.None }
-	| LONG { Ast.None }
-	| FLOAT { Ast.None }
-	| DOUBLE { Ast.None }
-	| SIGNED { Ast.None }
-	| UNSIGNED { Ast.None }
-	| struct_or_union_specifier { Ast.None }
-	| enum_specifier { Ast.None }
-	| TYPE_NAME { Ast.None }
+	: VOID 
+		{ Ast.TYPE_VOID }
+	| CHAR
+		{ Ast.TYPE_CHAR }
+	| SHORT
+		{ Ast.TYPE_SHORT }
+	| INT
+		{ Ast.TYPE_INT }
+	| LONG
+		{ Ast.TYPE_LONG }
+	| FLOAT
+		{ Ast.TYPE_FLOAT }
+	| DOUBLE
+		{ Ast.TYPE_DOUBLE }
+	| SIGNED
+		{ Ast.TYPE_SIGNED }
+	| UNSIGNED
+		{ Ast.TYPE_UNSIGNED }
+	| struct_or_union_specifier
+		{ raise (NotImplemented "TYPE_struct") }
+	| enum_specifier
+		{ raise (NotImplemented "TYPE_enum") }
+	| TYPE_NAME
+		{ Ast.TYPE_TYPE_NAME }
 	;
 
 struct_or_union_specifier
 	;
 
 declarator
-	: pointer direct_declarator { Ast.None }
-	| direct_declarator { Ast.None }
+	: pointer direct_declarator { raise (NotImplemented "DECL_point") }
+	| direct_declarator { Ast.DECL_direct $1 }
 	;
 
 direct_declarator
-	: IDENTIFIER { Ast.None }
-	| LEFTPARA declarator RIGHTPARA { Ast.None }
-	| direct_declarator LEFTCRO constant_expression RIGHTCRO { Ast.None }
-	| direct_declarator LEFTCRO RIGHTCRO { Ast.None }
-	| direct_declarator LEFTPARA parameter_type_list RIGHTPARA { Ast.None }
-	| direct_declarator LEFTPARA identifier_list RIGHTPARA { Ast.None }
-	| direct_declarator LEFTPARA RIGHTPARA { Ast.None }
+	: IDENTIFIER 
+		{ Ast.DIDE_id $1 }
+	| LEFTPARA declarator RIGHTPARA 
+		{ raise (NotImplemented "DIDE_dec") }
+	| direct_declarator LEFTCRO constant_expression RIGHTCRO 
+		{ raise (NotImplemented "DIDE_cro_const") }
+	| direct_declarator LEFTCRO RIGHTCRO 
+		{ raise (NotImplemented "DIDE_void_cro") }
+	| direct_declarator LEFTPARA parameter_type_list RIGHTPARA 
+		{ Ast.DIDE_param_list ($1, $3) }
+	| direct_declarator LEFTPARA identifier_list RIGHTPARA 
+		{ raise (NotImplemented "DIDE_id_list") }
+	| direct_declarator LEFTPARA RIGHTPARA 
+		{ raise (NotImplemented "DIDE_void_para") }
 	;
 
 pointer
 
 
 parameter_type_list
-	: parameter_list { Ast.None }
-	| parameter_list VIRGULE ELLIPSIS { Ast.None }
+	: parameter_list
+		{ Ast.PTL_list $1 }
+	| parameter_list VIRGULE ELLIPSIS
+		{ raise (NotImplemented "PTL_variatique") }
 	;
 
 parameter_list
-	: parameter_declaration { Ast.None }
-	| parameter_list VIRGULE parameter_declaration { Ast.None }
+	: parameter_declaration 
+		{ Ast.PALI_dec $1 }
+	| parameter_list VIRGULE parameter_declaration 
+		{ raise (NotImplemented "PALI_list") }
 	;
 
 parameter_declaration
-	: declaration_specifiers declarator { Ast.None }
-	| declaration_specifiers abstract_declarator { Ast.None }
-	| declaration_specifiers { Ast.None }
+	: declaration_specifiers declarator
+		{ raise (NotImplemented "PADE_dec_spec") }
+	| declaration_specifiers abstract_declarator
+		{ raise (NotImplemented "PADE_abs_spec") }
+	| declaration_specifiers
+		{ Ast.PADE_spec $1 }
 	;
 
 identifier_list
 	;
 
 statement
-	: labeled_statement { Ast.None }
-	| compound_statement { Ast.None }
-	| expression_statement { Ast.None }
-	| selection_statement { Ast.None }
-	| iteration_statement { Ast.None }
-	| jump_statement { Ast.None }
+	: labeled_statement 
+		{ raise (NotImplemented "STAT_label") }
+	| compound_statement 
+		{ raise (NotImplemented "STAT_compound") }
+	| expression_statement 
+		{ raise (NotImplemented "STAT_exp") }
+	| selection_statement 
+		{ raise (NotImplemented "STAT_selection") }
+	| iteration_statement 
+		{ raise (NotImplemented "STAT_iter") }
+	| jump_statement 
+		{ Ast.STAT_jump $1 }
 	;
 
 labeled_statement
 	;
 
 compound_statement
-	: LEFTACO RIGHTACO { Ast.None }
-	| LEFTACO statement_list RIGHTACO { Ast.None }
-	| LEFTACO declaration_list RIGHTACO { Ast.None }
-	| LEFTACO declaration_list statement_list RIGHTACO { Ast.None }
+	: LEFTACO RIGHTACO { raise (NotImplemented "CS") }
+	| LEFTACO statement_list RIGHTACO { Ast.CS_stat_list $2 }
+	| LEFTACO declaration_list RIGHTACO { raise (NotImplemented "CS") }
+	| LEFTACO declaration_list statement_list RIGHTACO { raise (NotImplemented "CS") }
 	;
 
 declaration_list
 	;
 
 statement_list
-	: statement { Ast.None }
-	| statement_list statement { Ast.None }
+	: statement { Ast.STL_stat $1 }
+	| statement_list statement { raise (NotImplemented "STL_list") }
 	;
 
 expression_statement
 	;
 
 jump_statement
-	: GOTO IDENTIFIER POINTVIRGULE { Ast.None }
-	| CONTINUE POINTVIRGULE { Ast.None }
-	| BREAK POINTVIRGULE { Ast.None }
-	| RETURN POINTVIRGULE { Ast.None }
-	| RETURN expression POINTVIRGULE { Ast.None }
+	: GOTO IDENTIFIER POINTVIRGULE
+		{ Ast.JS_GOTO $2 }
+	| CONTINUE POINTVIRGULE
+		{ Ast.JS_CONTINUE }
+	| BREAK POINTVIRGULE
+		{ Ast.JS_BREAK }
+	| RETURN POINTVIRGULE
+		{ Ast.JS_RETURN_NONE }
+	| RETURN expression POINTVIRGULE
+		{ Ast.JS_RETURN $2 }
 	;
 
 translation_unit
-	: external_declaration { Ast.None }
-	| translation_unit external_declaration { Ast.None }
+	: external_declaration
+		{ Ast.TU_dec $1 }
+	| translation_unit external_declaration
+		{ raise (NotImplemented "TU_tans") }
 	;
 
 external_declaration
-	: function_definition { Ast.None }
-	| declaration { Ast.None }
+	: function_definition 
+		{ Ast.ED_fun_def $1 }
+	| declaration 
+		{ raise (NotImplemented "")}
 	;
 
 function_definition
-	: declaration_specifiers declarator declaration_list compound_statement { Ast.None }
-	| declaration_specifiers declarator compound_statement { Ast.None }
-	| declarator declaration_list compound_statement { Ast.None }
-	| declarator compound_statement { Ast.None }
+	: declaration_specifiers declarator declaration_list compound_statement
+		{raise (NotImplemented "FUN_spec_dec_list") }
+	| declaration_specifiers declarator compound_statement
+		{ Ast.FUN_spec_dec ($1, $2, $3) }
+	| declarator declaration_list compound_statement
+		{ raise (NotImplemented "FUN_dec_list") }
+	| declarator compound_statement
+		{ Ast.FUN_dec ($1, $2) }
 	;
 
 %%