~crm/uni

589b111f08cbc5d928bdc414ed9edff9ff27ea6a — Christos Margiolis 2 months ago 049691a master
donecompilers done
32 files changed, 207 insertions(+), 0 deletions(-)

A lex_yacc_compilers/part4/02_B1_PART_B3.pdf
A lex_yacc_compilers/part4/Makefile
A lex_yacc_compilers/part4/input.txt
A lex_yacc_compilers/part4/lex.l
A lex_yacc_compilers/part4/output.txt
A lex_yacc_compilers/part4/syntax.y
R c_security/ex1/doc/doc.pdf => security/ex1/doc/doc.pdf
R c_security/ex1/doc/doc.tex => security/ex1/doc/doc.tex
R c_security/ex1/doc/doc.toc => security/ex1/doc/doc.toc
R c_security/ex1/doc/res/uniwalogo.png => security/ex1/doc/res/uniwalogo.png
R c_security/ex1/src/Makefile => security/ex1/src/Makefile
R c_security/ex1/src/atoh => security/ex1/src/atoh
R c_security/ex1/src/dat/c0.pem => security/ex1/src/dat/c0.pem
R c_security/ex1/src/dat/cert.in => security/ex1/src/dat/cert.in
R c_security/ex1/src/dat/decrypt.in => security/ex1/src/dat/decrypt.in
R c_security/ex1/src/dat/encrypt.in => security/ex1/src/dat/encrypt.in
R c_security/ex1/src/dat/priv.in => security/ex1/src/dat/priv.in
R c_security/ex1/src/dat/verify1_cor.in => security/ex1/src/dat/verify1_cor.in
R c_security/ex1/src/dat/verify1_inc.in => security/ex1/src/dat/verify1_inc.in
R c_security/ex1/src/dat/verify2.in => security/ex1/src/dat/verify2.in
R c_security/ex1/src/decrypt.c => security/ex1/src/decrypt.c
R c_security/ex1/src/encrypt.c => security/ex1/src/encrypt.c
R c_security/ex1/src/htoa => security/ex1/src/htoa
R c_security/ex1/src/priv.c => security/ex1/src/priv.c
R c_security/ex1/src/sign.c => security/ex1/src/sign.c
R c_security/ex1/src/tests => security/ex1/src/tests
R c_security/ex1/src/verify.c => security/ex1/src/verify.c
R c_security/ex2/Makefile => security/ex2/Makefile
R c_security/ex2/dash_shellcode.c => security/ex2/dash_shellcode.c
R c_security/ex2/exploit.c => security/ex2/exploit.c
R c_security/ex2/shellcode.c => security/ex2/shellcode.c
R c_security/ex2/stack.c => security/ex2/stack.c
A lex_yacc_compilers/part4/02_B1_PART_B3.pdf => lex_yacc_compilers/part4/02_B1_PART_B3.pdf +0 -0
A lex_yacc_compilers/part4/Makefile => lex_yacc_compilers/part4/Makefile +8 -0
@@ 0,0 1,8 @@
all:
	bison -d syntax.y
	flex lex.l
	cc syntax.tab.c lex.yy.c -lm -o uniclips
	./uniclips input.txt output.txt

clean:
	rm -f *.yy.c *.output *.tab.c *.tab.h uniclips *.core

A lex_yacc_compilers/part4/input.txt => lex_yacc_compilers/part4/input.txt +12 -0
@@ 0,0 1,12 @@
(printout "hello" "hello")
(bind ?var 1)
(bind ?var (+ 1 2))
(test (= 1 2))
(= 1 (+ 2 3))

(defrule move-up
	(+ 1 2)
	(- 1 (+ 1 (* 1 2)))
	(test (= 1 2))
	->
	(printout "hello"))

A lex_yacc_compilers/part4/lex.l => lex_yacc_compilers/part4/lex.l +48 -0
@@ 0,0 1,48 @@
%option noyywrap
%{
#include <stdlib.h>
#include "syntax.tab.h"

int	cw = 0;	/* correct words */
int	ww = 0;	/* wrong words */
%}

/*
 * Με βάση το μέρος Α2, υλοποιούμε τις κανονικές εκφράσεις και τις
 * αντιστοιχούμε στα κατάλληλα tokens.
 */
ARITH		"+"|"-"|"*"|"/"|"="
DELIM		[ \t\n]+
INT		0|[+-]?[1-9]+[0-9]*
FLOAT		[+-]?[0-9]+((\.[0-9]+)([eE][+-]?[0-9]*)?|([eE][+-]?[0-9]*)?)
STR		\"[^\"\\]*(?:\\.[^\"\\]*)*\"
DEFIN		[A-Za-z]+[A-Za-z0-9_-]*
VAR		\?[A-Za-z0-9]+
COMMENT		;.*

/*
 * Όταν βρίσκει οποιοδήποτε token, επιστρέφει την αντίστοιχη κατηγορία στο
 * οποίο ανήκει
 */
%%
"deffacts"	{ cw++;  return DEFFACTS; }
"defrule"	{ cw++;  return DEFRULE; }
"bind"		{ cw++;  return BIND; }
"read"		{ cw++;  return READ; }
"printout"	{ cw++;  return PRINT; }
"test"		{ cw++;  return TEST; }
"="		{ cw++;  return COMP; }
"("		{ return LPAR; }
")"		{ return RPAR; }
"->"		{ return ARROW; }
{ARITH}		{ cw++;  return ARITH; }
{INT}		{ cw++;  return INT; }
{FLOAT}		{ cw++;  return FLOAT;}
{STR}		{ cw++;  return STR; }
{DEFIN}		{ cw++; return DEFIN; }
{VAR}		{ cw++; return VAR; }
{DELIM}		{ /* ignore whitespace */ }
{COMMENT}	{ /* skip comments */ }
"\n"		{ return NEWLINE; }
.		{ ww++; return UNKNOWN; }
%%

A lex_yacc_compilers/part4/output.txt => lex_yacc_compilers/part4/output.txt +6 -0
@@ 0,0 1,6 @@
input.txt: success

correct words: 38
correct expressions: 12
wrong words: 0
wrong expressions: 0

A lex_yacc_compilers/part4/syntax.y => lex_yacc_compilers/part4/syntax.y +133 -0
@@ 0,0 1,133 @@
%{
#include <err.h>
#include <stdio.h>
#include <stdlib.h>

/* Silence warnings... */
extern int	yylex(void);

/* Input and output files. */
extern FILE	*yyin, *yyout;

extern int	cw;	/* correct words */
extern int	ww;	/* wrong words */
int		ce = 0;	/* correct expressions */
int		we = 0;	/* wrong expressions */

void	yyerror(const char *);
%}

/* Tokens declared from flex. */
%token DEFFACTS DEFRULE BIND READ PRINT TEST ARITH INT FLOAT COMP
%token STR DEFIN VAR LPAR RPAR ARROW NEWLINE UNKNOWN

%start prog

%%
/* Start here. */
prog:
	| prog NEWLINE
	| prog expr
	;

/*
 * Declare numbers. Variables only accept numerical values so add them here as
 * well.
 */
num:
	INT
	| FLOAT
	| VAR
	;

/* Accept any number of strings (for use in printout) */
str:
	STR
	| str STR
	;

/* (= (expr)) */
cmp:
	LPAR COMP expr expr RPAR
	;

/* (test (= (expr))) */
test:
	LPAR TEST cmp RPAR
	;

/* (prinout (str)...) */
print:
	LPAR PRINT str RPAR
	;

fact:
	expr
	| fact expr
	;

/* We match expressions here. */
expr:
	num						/* numbers */
	| cmp				{ ce++; }	/* comparisons */
	| test				{ ce++; }	/* test keyword */
	| print				{ ce++; }	/* (printout "str"...) */
	| LPAR READ RPAR		{ ce++; }	/* (read) */
	| LPAR ARITH expr expr RPAR	{ ce++; }	/* (arithmetic_op (expr)...) */
	| LPAR BIND VAR expr RPAR	{ ce++; }	/* (bind ?var (expr)) */
	| LPAR DEFFACTS DEFIN fact RPAR { ce++; }	/* (deffacts DEF facts...) */
	/* (defrule DEF
	 *	(facts)
	 *	...
	 *	(test)
	 *	->
	 *	(printout))
	 */
	| LPAR DEFRULE DEFIN fact test ARROW print RPAR { ce++; }
	| error				{ we++; if (ce > 0) ce--; }
	;
%%

/* Print errors. */
void
yyerror(const char *s)
{
	fprintf(stderr, "%s\n", s);
}

int
main(int argc, char *argv[])
{
	/* We need at least 1 input and 1 output file... */
	if (argc < 3) {
		fprintf(stderr, "usage: %s input... output\n", *argv);
		return (-1);
	}

	/* Open last file as output. */
	if ((yyout = fopen(argv[--argc], "w")) == NULL)
		err(1, "fopen(%s)", argv[argc]);

	/* Parse all input files in reverse order. */
	while (argc-- > 1) {
		if ((yyin = fopen(argv[argc], "r")) == NULL)
			err(1, "fopen(%s)", argv[argc]);
		/* Parse file */
		if (yyparse() == 0)
			fprintf(yyout, "%s: success\n", argv[argc]);
		else
			fprintf(yyout, "%s: failure\n", argv[argc]);
		fclose(yyin);
	}

	/* Print results. */
	fprintf(yyout, "\n");
	fprintf(yyout, "correct words: %d\n", cw);
	fprintf(yyout, "correct expressions: %d\n", ce);
	fprintf(yyout, "wrong words: %d\n", ww);
	fprintf(yyout, "wrong expressions: %d\n", we);

	fclose(yyout);

	return (0);
}

R c_security/ex1/doc/doc.pdf => security/ex1/doc/doc.pdf +0 -0
R c_security/ex1/doc/doc.tex => security/ex1/doc/doc.tex +0 -0
R c_security/ex1/doc/doc.toc => security/ex1/doc/doc.toc +0 -0
R c_security/ex1/doc/res/uniwalogo.png => security/ex1/doc/res/uniwalogo.png +0 -0
R c_security/ex1/src/Makefile => security/ex1/src/Makefile +0 -0
R c_security/ex1/src/atoh => security/ex1/src/atoh +0 -0
R c_security/ex1/src/dat/c0.pem => security/ex1/src/dat/c0.pem +0 -0
R c_security/ex1/src/dat/cert.in => security/ex1/src/dat/cert.in +0 -0
R c_security/ex1/src/dat/decrypt.in => security/ex1/src/dat/decrypt.in +0 -0
R c_security/ex1/src/dat/encrypt.in => security/ex1/src/dat/encrypt.in +0 -0
R c_security/ex1/src/dat/priv.in => security/ex1/src/dat/priv.in +0 -0
R c_security/ex1/src/dat/verify1_cor.in => security/ex1/src/dat/verify1_cor.in +0 -0
R c_security/ex1/src/dat/verify1_inc.in => security/ex1/src/dat/verify1_inc.in +0 -0
R c_security/ex1/src/dat/verify2.in => security/ex1/src/dat/verify2.in +0 -0
R c_security/ex1/src/decrypt.c => security/ex1/src/decrypt.c +0 -0
R c_security/ex1/src/encrypt.c => security/ex1/src/encrypt.c +0 -0
R c_security/ex1/src/htoa => security/ex1/src/htoa +0 -0
R c_security/ex1/src/priv.c => security/ex1/src/priv.c +0 -0
R c_security/ex1/src/sign.c => security/ex1/src/sign.c +0 -0
R c_security/ex1/src/tests => security/ex1/src/tests +0 -0
R c_security/ex1/src/verify.c => security/ex1/src/verify.c +0 -0
R c_security/ex2/Makefile => security/ex2/Makefile +0 -0
R c_security/ex2/dash_shellcode.c => security/ex2/dash_shellcode.c +0 -0
R c_security/ex2/exploit.c => security/ex2/exploit.c +0 -0
R c_security/ex2/shellcode.c => security/ex2/shellcode.c +0 -0
R c_security/ex2/stack.c => security/ex2/stack.c +0 -0