Skip to content

Commit b3a4cfb

Browse files
authored
Merge pull request #7 from BeyondMagic/marcomarquesdc-patch-1
2 parents df2f690 + 9647a1e commit b3a4cfb

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/parser.y

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ int yyerror(AstProgram **out_program, const char *msg);
1111
extern int yylex(void);
1212
extern FILE *yyin;
1313
static void parser_error_cleanup(AstProgram **out_program);
14-
1514
%}
1615

1716
%code requires {
@@ -27,19 +26,19 @@ static void parser_error_cleanup(AstProgram **out_program);
2726
%parse-param { AstProgram **out_program }
2827

2928
%union {
30-
long long intValue;
31-
double floatValue;
32-
char *id;
33-
TypeKind type;
34-
AstExpr *expr;
35-
AstStmt *stmt;
36-
AstBlock block;
37-
AstStmtList stmt_list;
38-
AstExprList expr_list;
39-
AstParam param;
40-
AstParamList param_list;
41-
AstFunction *function;
42-
AstProgram *program;
29+
long long intValue;
30+
double floatValue;
31+
char *id;
32+
TypeKind type;
33+
AstExpr *expr;
34+
AstStmt *stmt;
35+
AstBlock block;
36+
AstStmtList stmt_list;
37+
AstExprList expr_list;
38+
AstParam param;
39+
AstParamList param_list;
40+
AstFunction *function;
41+
AstProgram *program;
4342
}
4443

4544
%token <intValue> INT_LITERAL
@@ -55,6 +54,7 @@ static void parser_error_cleanup(AstProgram **out_program);
5554
%token LPAREN RPAREN
5655
%token LBRACE RBRACE
5756

57+
/* ---------- Precedência ---------- */
5858
%left PLUS MINUS
5959
%left TIMES DIVIDE MOD
6060
%right UMINUS
@@ -80,7 +80,6 @@ program
8080
*out_program = $1;
8181
}
8282
;
83-
8483
function_sequence
8584
: function_definition
8685
{
@@ -404,7 +403,7 @@ int yyerror(AstProgram **out_program, const char *msg)
404403
{
405404
(void)out_program;
406405
fprintf(stderr, "syntax error: %s\n", msg);
407-
return 0;
406+
return 0;
408407
}
409408

410409
AstProgram *c2lua_parse(FILE *input)

tests/expressions.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
1 + 2 * 3;
2-
(4 + 5) / 2;
3-
10 % 3;
4-
true;
5-
false;
1+
int main()
2+
{
3+
int a = 10;
4+
int b = 20;
5+
int sum = a + b;
6+
printf("Sum: %d\n", sum);
7+
return 0;
8+
}

0 commit comments

Comments
 (0)