Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create append #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/chuck.y
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "chuck_absyn.h"

// function
int yydebug = 1;
int yylex( void );

void yyerror( char *s )
Expand Down Expand Up @@ -297,7 +298,8 @@ arg_list

statement_list
: statement { $$ = new_stmt_list( $1, EM_lineNum ); }
| statement statement_list { $$ = prepend_stmt_list( $1, $2, EM_lineNum ); }
| statement_list statement { $$ = append_stmt_list( $1, $2, EM_lineNum ); }
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting a Bison error for this rule

bison --debug --verbose -dv -b chuck chuck.y
chuck.y: conflicts: 73 shift/reduce
chuck.y: expected 38 shift/reduce conflicts
make: *** [chuck.tab.c] Error 1

// | statement statement_list { $$ = prepend_stmt_list( $1, $2, EM_lineNum ); }
;

statement
Expand Down
9 changes: 9 additions & 0 deletions src/chuck_absyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ a_Stmt_List prepend_stmt_list( a_Stmt stmt, a_Stmt_List stmt_list, int pos )
return a;
}

a_Stmt_List append_stmt_list( a_Stmt_List stmt_list, a_Stmt stmt, int pos )
{
a_Stmt_List a = new_stmt_list( stmt, pos );
a->next = stmt_list;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function signature accepts the statment_list as the first argument and the statement as the second argument, as specified in the chuck.y file.

The body of this function was simply copied over from the previous function prepend_stmt_list. Should I append a to stmt by finding the first NULL next value in the linked list and assign a?

a->linepos = pos;
return a;
}


a_Stmt new_stmt_from_expression( a_Exp exp, int pos )
{
a_Stmt a = (a_Stmt)checked_malloc( sizeof( struct a_Stmt_ ) );
Expand Down
1 change: 1 addition & 0 deletions src/chuck_absyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ a_Section new_section_func_def( a_Func_Def func_def, int pos );
a_Section new_section_class_def( a_Class_Def class_def, int pos );
a_Stmt_List new_stmt_list( a_Stmt stmt, int pos );
a_Stmt_List prepend_stmt_list( a_Stmt stmt, a_Stmt_List stmt_list, int pos );
a_Stmt_List append_stmt_list( a_Stmt_List stmt_list, a_Stmt stmt, int pos );
a_Stmt new_stmt_from_expression( a_Exp exp, int pos );
a_Stmt new_stmt_from_code( a_Stmt_List code, int pos );
a_Stmt new_stmt_from_while( a_Exp cond, a_Stmt body, int pos );
Expand Down
4 changes: 3 additions & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ chuck: $(OBJS)
$(LD) -o chuck $(OBJS) $(LDFLAGS) $(ARCHOPTS)

chuck.tab.c chuck.tab.h: chuck.y
$(YACC) -dv -b chuck chuck.y
# $(YACC) -dv -b chuck chuck.y
$(YACC) --debug --verbose -dv -b chuck chuck.y


chuck.yy.c: chuck.lex
$(LEX) -ochuck.yy.c chuck.lex
Expand Down