Project Split finished
authorMarkus Bröker <mbroeker@largo.localnet>
Thu, 16 Apr 2009 12:49:11 +0200
changeset 38 48f6f3918b82
parent 37 0fbbe329c3a2
child 39 46d7ec9d63bd
Project Split finished committer: Markus Bröker <mbroeker@largo.homelinux.org>
parser/calc/Makefile
parser/calc/lexer.l
parser/calc/main.c
parser/calc/parser.y
--- a/parser/calc/Makefile
+++ b/parser/calc/Makefile
@@ -2,21 +2,21 @@
 LD=ld
 YACC=bison -y
 FLEX=flex
-CFLAGS=-Wall -O2 -ansi 
+CFLAGS=-Wall -O2 -ansi -D_XOPEN_SOURCE=500
 LDFLAGS=
 INCLUDE=include
 OBJECTS=main.o parser.o lexer.o
-TARGET=parser
+TARGET=calc
 
-.SUFFIXES: .c .yy .ll
+.SUFFIXES: .c .y .l
 
 .c.o: 
 	$(CC) -c $(CFLAGS) -I$(INCLUDE) $(CONFIG) $<
 
-.yy.c:
+.y.c:
 	$(YACC) -d $< -o $@
 
-.ll.c:
+.l.c:
 	$(FLEX) -o $@ $<
 
 all: $(TARGET)
@@ -30,6 +30,7 @@
 clean:
 	rm -f *.[oae];
 	rm -f *~;
+	rm -f parser.h
 
 distclean:
 	make clean
--- a/parser/calc/lexer.l
+++ b/parser/calc/lexer.l
@@ -10,14 +10,14 @@
 
 %%
 
-[0-9]+			{ yylval = atoi(yytext); return DIGIT;    }
-[a-zA-Z]		{ yylval = yytext[0]; return LETTER;      }
-"+"			return PLUS;	     
-"-"			return MINUS;       
-"*"			return MUL;         
-"/"			return DIV;       
-"("|")"|"="		return yytext[0]; 
-[ \t]+			;
-\n			return yytext[0];
-.			printf("FEHLER: %s\n", yytext);
+[0-9]+		{ yylval = atoi(yytext); return DIGIT; }
+[a-zA-Z]	{ yylval = yytext[0]; return LETTER; }
+"+"		{ return PLUS; }
+"-"		{ return MINUS; }
+"*"		{ return MUL; }
+"/"		{ return DIV; }
+"("|")"|"="	{ return yytext[0]; }
+[ \t]+		{}
+\n		{ return yytext[0]; }
+.		{ printf("FEHLER: %s\n", yytext); }
 %%
--- a/parser/calc/main.c
+++ b/parser/calc/main.c
@@ -1,5 +1,5 @@
 /**
- * test/demos/parser/main.c
+ * test/demos/parser/calc/main.c
  * Copyright (C) 2008 Markus Broeker
  */
 
--- a/parser/calc/parser.y
+++ b/parser/calc/parser.y
@@ -7,9 +7,9 @@
    #include <stdio.h>
    #include <ctype.h>
 
-   int regs[26]; 
+   int regs[26];
    int base;
-	
+
    int yyerror();
    int yylex();
 %}
@@ -20,65 +20,67 @@
 %left UMINUS
 %%
 
-list : /* empty */ 
-	| list stat '\n' 
+list:
+	/* empty */
+	| list stat '\n'
 	| list error '\n' { yyerrok; };
 
-stat : 
-	expr { (void) printf( "RESULT: %d\n", $1 ); } 
+stat:
+	expr { (void) printf( "RESULT: %d\n", $1 ); }
 	| LETTER '=' expr { regs[$1] = $3; }
 	;
 
-   expr      :  '(' expr ')'
-             {
-                   $$ = $2;
-             }
-             |  expr PLUS expr
-             {
-                   $$ = $1 + $3;
-             }
-             |  expr MINUS expr
-             {
-                   $$ = $1 - $3;
-             }
-             |  expr MUL expr
-             { 
-                   $$ = $1 * $3;
-             }
-             |  expr DIV expr
-             {
-                   $$ = $1 / $3;
-             }
-             |  MINUS expr  %prec UMINUS
-             {
-                   $$ = -$2;
-             }
-             |  LETTER
-             {
-                   $$ = regs[$1];
-             }
-             |  number
-             ;
+expr:
+	'(' expr ')'
+	{
+		$$ = $2;
+	}
+	| expr PLUS expr
+	{
+		$$ = $1 + $3;
+	}
+	| expr MINUS expr
+	{
+		$$ = $1 - $3;
+	}
+	| expr MUL expr
+	{
+		$$ = $1 * $3;
+	}
+	| expr DIV expr
+	{
+			$$ = $1 / $3;
+	}
+	| MINUS expr  %prec UMINUS
+	{
+		$$ = -$2;
+	}
+	| LETTER
+	{
+		$$ = regs[$1];
+	}
+	|  number
+	;
 
-   number    :   DIGIT
-             {
-                    $$ = $1; base = ($1==0) ? 8 : 10;
-             }
-             |   number DIGIT
-             {
-                    $$ = base * $1 + $2;
-             }
-             ;
-   
+number:
+	DIGIT
+	{
+		$$ = $1; base = ($1==0) ? 8 : 10;
+	}
+	| number DIGIT
+	{
+		$$ = base * $1 + $2;
+	}
+	;
 %%
 
-int yyerror() 
+int yyerror()
 {
 	printf("ERROR\n");
 	return 0;
 }
 
-int yywrap() 
+int yywrap()
 {
 	return 1;
 }