recursive_compiler.c
changeset 31 c95a6a7e305c
parent 30 d037c433ec3e
child 48 b94d657a9acb
equal deleted inserted replaced
30:d037c433ec3e 31:c95a6a7e305c
     1 /**
     1 /**
     2  * Ein-Pass-Compiler
     2  * Ein-Pass-Compiler
     3  *
     3  * Adapted from: http://de.wikipedia.org/wiki/Compiler
     4  */
     4  */
     5 
     5 
     6 #include <stdlib.h>
     6 #include <stdlib.h>
     7 #include <stdio.h>
     7 #include <stdio.h>
     8 #include <string.h>
     8 #include <string.h>
     9 
     9 
    10 #define MODE_POSTFIX   0
    10 #define MODE_POSTFIX   0
    11 #define MODE_ASSEMBLY  1
    11 #define MODE_ASSEMBLY  1
       
    12 #define MAX           20
    12 
    13 
    13 char lookahead;
    14 char lookahead;
    14 int pos;
    15 int pos;
    15 int compile_mode;
    16 int compile_mode;
    16 char expression[20 + 1];
    17 char expression[MAX + 1];
    17 
    18 
    18 void error ()
    19 void error ()
    19 {
    20 {
    20     printf ("Syntaxfehler!\n");
    21     printf ("Syntaxfehler!\n");
    21 }
    22 }
    93 }
    94 }
    94 
    95 
    95 int main (int argc, char **argv)
    96 int main (int argc, char **argv)
    96 {
    97 {
    97     printf ("Bitte geben Sie einen Ausdruck in Infix-Notation ein:\n\n\t");
    98     printf ("Bitte geben Sie einen Ausdruck in Infix-Notation ein:\n\n\t");
    98     fgets (expression, 20, stdin);
    99     fgets (expression, MAX, stdin);
    99 
   100 
   100     printf ("\nCompilierter Ausdruck in Postfix-Notation:\n\n\t");
   101     printf ("\nCompilierter Ausdruck in Postfix-Notation:\n\n\t");
   101     compile_mode = MODE_POSTFIX;
   102     compile_mode = MODE_POSTFIX;
   102     pos = 0;
   103     pos = 0;
   103     lookahead = *expression;
   104     lookahead = *expression;