Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NodeTimes added and a function for resetting the current iterator for…

… a queue
  • Loading branch information...
commit fc32307371292fac7573e0346cbc0e194006bfc1 1 parent b6639e3
@thoefer2 thoefer2 authored
View
131 Main.c
@@ -0,0 +1,131 @@
+
+
+
+/*
+ #include <stdlib.h>
+ #include <string.h>
+ #include <stdio.h>
+ #include "hash_table.h"
+ #include "scanner.h"
+
+ int main(int argc, char *args[]) {
+
+ file_init();
+ char *word;
+ printf("starte...\n");
+ while ((word = next_word()) != NULL) {
+ struct bucket *result = lookup(word);
+ if(result == NULL) {
+ result = (struct bucket *) malloc(sizeof(struct bucket));
+ }
+ }
+ file_close();
+
+
+ return 0;
+
+ char key[10];
+
+ add("ro", "hier gehts um die stadt rosenheim");
+ add("grhh", "inhalt für grossholzhausen");
+
+ while (1) {
+ printf("DB-Abfrage: \n");
+ int result = scanf("%s", key);
+ if(result == 0) {
+ printf("Falsches Format!\n");
+ } else {
+ struct bucket *result = lookup(key);
+ if(result == NULL)
+ printf("no result\n");
+ else
+ printf("Value for %s: %s\n", key, result->value);
+ }
+ }
+
+ }
+ */
+
+
+
+
+/*
+
+
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include "array_list.h"
+ #include <string.h>
+
+
+ int main(int argc, const char *argv[]) {
+
+ while (1) {
+
+ char word[100];
+ int count;
+
+ int result = scanf("%s %d", word, &count);
+ if(result == 0) {
+ fflush(stdin);
+ continue;
+ }
+ if (strcmp(word, "info") == 0) {
+ ;
+ } else {
+ char *word2 = strdup(word);
+ list_insert(word2, count);
+ }
+ }
+ }
+
+ */
+
+
+
+
+/*
+ #include <stdio.h>
+ #include "bintree.h"
+
+
+ void success(char *name) {
+ printf("found: %s \n", name);
+ }
+
+ void error(char *bla) {
+ printf("found nothing :(");
+ }
+
+ typedef void (*Callback)(char *param);
+
+ int main (int argc, const char * argv[]) {
+
+ printf("starte...\n");
+ Callback funcs[2] = { success, error };
+
+ Ort ltk = { 8, "leutkirch" };
+ Ort rbl = { 10, "raubling" };
+ Ort ro = { 6, "rosenheim" };
+ Ort low = { 5, "low" };
+ Ort lower = { 1, "lower" };
+
+
+ printf("inserting...\n");
+ insert(&ltk);
+ insert(&rbl);
+ insert(&ro);
+ insert(&low);
+ insert(&lower);
+ insert_by_properties(12, "new york");
+ printf("searching...\n");
+
+ Ort *result = find(12);
+ if (result == NULL) {
+ (*funcs[0])(NULL);
+ } else {
+ (*funcs[0])(result->name);
+ }
+ return 0;
+ }
+ */
View
21 code2.txt
@@ -1,21 +0,0 @@
-str = "world";
-cat = "gorby";
-
-name = 7;
-test = 2;
-result = name + name * test - 11;
-
-is result == 10 (
- abc = 11;
- is 0 - 1 + abc + 1 - 1 * 2 + 2 == 10 + 1 (
- is 5 == 5 (
- is 9 == 9 (
- >> "hallo #{sstr}";
- innerVariable = 100 + abc;
- )
- )
- )
-)
-
->> innerVariable;
->> "miau, miau mr. #{ccat}, is angry & hungry!!";
View
13 example.strike
@@ -18,4 +18,15 @@ is result == 10 (
)
>> innerVariable;
->> "miau, miau mr. #{ccat}, is angry & hungry!!";
+>> "miau, miau mr. #{ccat}, is angry & hungry!!";
+
+
+
+count = 3;
+times 2 + count (
+ times 2 (
+ >> "you should see this 10 times...";
+ )
+)
+
+
View
57 parser.c
@@ -16,6 +16,7 @@ STMT_LIST ::= STMT STMT_LIST | EPSILON
STMT ::= id = E | id = STRING;
STMT ::= p EX; | p STRING;
STMT ::= is EX ( stmt_list )
+STMT ::= times EXPR ( STMT_LIST )
STRING ::= ""
EX ::= E cmp E
@@ -55,7 +56,7 @@ FIRST(V) = id number
#define RIGHT 1
enum types {
- AST_STMT_LIST, AST_ASSIGNMENT, AST_PRINT, AST_IS, AST_CMP
+ AST_STMT_LIST, AST_ASSIGNMENT, AST_PRINT, AST_IS, AST_CMP,AST_TIMES
};
struct Binary {
@@ -106,10 +107,15 @@ typedef struct {
Node *then;
} NodeCmp;
+
typedef struct {
QHandle *stmts;
} NodeStmtList;
+typedef struct {
+ struct NExpr *times;
+ Node *block;
+} NodeTimes;
@@ -124,6 +130,7 @@ void parse_assignment(NodeStmtList *stmt_list);
void parse_print(NodeStmtList *stmt_list);
void parse_is(NodeStmtList *stmt_list);
void parse_expr(void);
+void parse_times(NodeStmtList *stmt_list);
void parse_a(void);
void parse_p(void);
void parse_b(void);
@@ -430,6 +437,7 @@ void interpret_node(Node *node) {
NodePrint *print;
NodeAssign *assign;
NodeCmp *cmp;
+ NodeTimes *times;
Node *current;
switch (node->type) {
@@ -484,6 +492,16 @@ void interpret_node(Node *node) {
}
}
break;
+ case AST_TIMES:
+ times = node->ref;
+ int i;
+ int iter = interpret_expr(times->times);
+ NodeStmtList *stmts = times->block->ref;
+ for (i = 1; i <= iter; i++) {
+ interpret_node(times->block);
+ queue_reset(stmts->stmts);
+ }
+ break;
default:
break;
}
@@ -523,6 +541,10 @@ void parse_stmt_list(NodeStmtList *stmt_list) {
parse_is(stmt_list);
parse_stmt_list(stmt_list);
break;
+ case TOK_TIMES:
+ parse_times(stmt_list);
+ parse_stmt_list(stmt_list);
+ break;
case TOK_PAREN_CLOSE:
case TOK_TERMINATE:
@@ -533,6 +555,39 @@ void parse_stmt_list(NodeStmtList *stmt_list) {
}
+void parse_times(NodeStmtList *stmt_list) {
+
+ switch (lookahead->tok_type) {
+ case TOK_TIMES:
+
+ match(TOK_TIMES);
+ expr_queue_state = queue_new();
+ parse_expr();
+ struct NExpr *expr = shunting_yard();
+ match(TOK_PAREN_OPEN);
+
+ NodeStmtList *stmt_list_block = malloc(sizeof(NodeStmtList));
+ stmt_list_block->stmts = queue_new();
+ parse_stmt_list(stmt_list_block);
+ Node *node_block = generate_node(AST_STMT_LIST, stmt_list_block);
+
+ match(TOK_PAREN_CLOSE);
+ NodeTimes *node_times = malloc(sizeof(NodeTimes));
+ node_times->times = expr;
+ node_times->block = node_block;
+
+ Node *n = generate_node(AST_TIMES, node_times);
+ queue_enqueue(stmt_list->stmts, n);
+
+ break;
+
+ default:
+ break;
+ }
+
+}
+
+
void parse_is(NodeStmtList *stmt_list) {
switch (lookahead->tok_type) {
View
5 queue.c
@@ -45,6 +45,11 @@ void *queue_dequeue(struct QState *state) {
}
+void queue_reset(struct QState *state) {
+ state->traversal = state->head;
+}
+
+
void queue_test(struct QState *state, void (*callback)(void *it)) {
void *it;
struct QState *initial_state = &(*state);
View
1  queue.h
@@ -12,4 +12,5 @@ typedef struct QState QHandle;
struct QState *queue_new(void);
void queue_enqueue(struct QState *state, void *item);
void *queue_dequeue(struct QState *state);
+void queue_reset(struct QState *state);
void queue_test(struct QState *state, void (*callback)(void *it));
View
10 scanner/scanner.c
@@ -96,7 +96,12 @@ Token *scanner() {
token->tok_type = TOK_IS;
token->lexem_one = lexem;
token->line = line;
- token->row = row;
+ token->row = row;
+ } else if(strcmp(lexem, "ttimes") == 0) {
+ token->tok_type = TOK_TIMES;
+ token->lexem_one = lexem;
+ token->line = line;
+ token->row = row;
} else {
token->tok_type = TOK_ID;
token->lexem_one = lexem;
@@ -235,6 +240,9 @@ char *tok_type_tostring(int tok_type) {
case TOK_STRING:
result = "TOK_STRING";
break;
+ case TOK_TIMES:
+ result = "TOK_TIMES";
+ break;
default:
printf("error, no token description available");
}
View
3  scanner/scanner.h
@@ -1,5 +1,6 @@
enum Tokens {
- TOK_ID, TOK_EQ, TOK_NUMBER, TOK_BINOP, TOK_SEMICOLON, TOK_TERMINATE, TOK_PAREN_OPEN, TOK_PAREN_CLOSE, TOK_MINUS, TOK_P, TOK_IS, TOK_CMP, TOK_STRING
+ TOK_ID, TOK_EQ, TOK_NUMBER, TOK_BINOP, TOK_SEMICOLON, TOK_TERMINATE, TOK_PAREN_OPEN, TOK_PAREN_CLOSE, TOK_MINUS, TOK_P, TOK_IS, TOK_CMP, TOK_STRING,
+ TOK_TIMES
};
typedef struct {
View
44 scanner2.c
@@ -1,44 +0,0 @@
-//
-// scanner.c
-// BinTree
-//
-// Created by tom hoefer on 27.01.12.
-// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
-//
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "scanner.h"
-
-static FILE *fp;
-
-
-void file_init() {
- fp = fopen("/Users/tom/tom/NetBeansProjects/xcode/C-Progr/BinTree/BinTree/code.txt", "r");
- if(fp == NULL)
- printf("fehler, datei konnte nicht geöffnet werden\n");
-}
-
-void file_close() {
- fclose(fp);
-}
-
-char *next_word() {
-
- char c;
- char *word = (char *) malloc(sizeof(char *));
-
- while ((c = fgetc(fp)) != EOF) {
- if(c >= 'a' && c <= 'z') {
- strcat(word, &c);
- } else if(c == ' ') {
- return word;
- } else {
- printf("blöd gelaufen...");
- }
- }
-
- return NULL;
-
-}
View
3  scanner2.h
@@ -1,3 +0,0 @@
-void file_init();
-void file_close();
-char *next_word();
Please sign in to comment.
Something went wrong with that request. Please try again.