fork download
  1. lex_by_file( FileName ) :-
  2. get_input_from_file( FileName, TokenList ),
  3. lex( TokenList, OutputList ),
  4. %write_output( OutputList ), !.
  5. maplist(writeln,OutputList),!.
  6.  
  7. %% atom_number(atom, number)
  8. lex([],[]).
  9. lex(['int' | T], ['TYPE: int' | R]) :- lex(T, R).
  10. lex(['bool' | T], ['TYPE: bool'] | R) :- lex(T, R).
  11. lex([',' | T], ['COMMA: ,'] | R) :- lex(T, R).
  12. lex([X | T], [X | R]) :- lex(T, R).
  13.  
Success #stdin #stdout #stderr 0.03s 6804KB
stdin
#include <stdio.h>
#include <string.h>

void generateThreeAddressCode(char *expression) {
    char *token;
    token = strtok(expression, " ");
    while (token != NULL) {
        if (strcmp(token, "+") == 0 || strcmp(token, "-") == 0) {
            char *operand1 = strtok(NULL, " ");
            char *operand2 = strtok(NULL, " ");
            printf("t0 = %s %c %s\n", operand1, token[0], operand2);
        }
        token = strtok(NULL, " ");
    }
}

int main() {
    char expression[100];
    printf("Enter an arithmetic expression: ");
    fgets(expression, sizeof(expression), stdin);
    generateThreeAddressCode(expression);
    return 0;
}
```
stdout
Standard output is empty
stderr
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ?    Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?    Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: Unknown option (h for help)
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: Can't ignore goal at this port
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?    Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ?       [3] program
   Exception: (3) program ?    Call: (3) program ? ERROR: Unknown option (h for help)
   Call: (3) program ? EOF: exit