Compare commits
2 Commits
e674f93fea
...
deaab50a6d
Author | SHA1 | Date |
---|---|---|
fsan | deaab50a6d | |
fsan | 6723f51f83 |
2
build.sh
2
build.sh
|
@ -1,2 +1,2 @@
|
|||
#!/bin/sh
|
||||
g++ -g main.cpp interpreter.cpp lexer.cpp parser.cpp
|
||||
g++ -g main.cpp interpreter.cpp lexer.cpp parser.cpp utilities.cpp
|
||||
|
|
20
info
20
info
|
@ -8,4 +8,22 @@ exp -> numero (literal) -> number
|
|||
exp -> id (idExp) -> id
|
||||
exp -> exp op exp (operacion) -> opexp
|
||||
op -> + (suma) -> plus
|
||||
op -> - (resta) -> minus
|
||||
op -> - (resta) -> minus
|
||||
|
||||
IR:
|
||||
example:
|
||||
a = 2 + 2
|
||||
=>
|
||||
a = 4
|
||||
=>
|
||||
MOV a, 0x0004
|
||||
|
||||
a = b + 2
|
||||
=>
|
||||
MOV r1, [b]
|
||||
ADD r1, 0x0002
|
||||
MOV a, r1
|
||||
=>
|
||||
MOV r1, [0xf000]
|
||||
ADD r1, 0x0002
|
||||
MOV 0xf001, r1
|
36
main.cpp
36
main.cpp
|
@ -42,40 +42,4 @@ main(){
|
|||
inter->evalSTM(end);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
print_tokens(std::vector<struct token> tokens){
|
||||
for(struct token tok : tokens) {
|
||||
std::cout << str_token(tok) << " ";
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
std::string
|
||||
str_token(struct token tok){
|
||||
switch (tok.t) {
|
||||
case token::TOK_ID:
|
||||
return "ID(" + tok.value + ")";
|
||||
case token::TOK_NUM:
|
||||
return "NUM(" + tok.value + ")";
|
||||
case token::TOK_OP:
|
||||
return "OP(" + tok.value + ")";
|
||||
case token::TOK_ASSIGN:
|
||||
return "ASSIGN ";
|
||||
case token::TOK_SEMI:
|
||||
return "SEMI ";
|
||||
case token::STM_ASSIGN:
|
||||
return "STM_ASSIGN( " + str_token(*tok.lvalue) + ", " + str_token(*tok.rvalue) + ")";
|
||||
case token::STM_COMPOUND:
|
||||
return "STM_COMPOUND( " + str_token(*tok.lvalue) + ", " + str_token(*tok.rvalue) + ")";
|
||||
case token::EXP_NUMBER:
|
||||
return "EXP_NUMBER(" + tok.value + ")";
|
||||
case token::EXP_OPERATION:
|
||||
return "EXP_OPERATION( " + str_token(*tok.lvalue) + " " + tok.value + " " + str_token(*tok.rvalue) +")";
|
||||
case token::EXP_ID:
|
||||
return "EXP_ID ";
|
||||
default:
|
||||
return "SOMETHING";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#include "orga-comp.h"
|
||||
|
||||
void
|
||||
print_tokens(std::vector<struct token> tokens){
|
||||
for(struct token tok : tokens) {
|
||||
std::cout << str_token(tok) << " ";
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
std::string
|
||||
str_token(struct token tok){
|
||||
switch (tok.t) {
|
||||
case token::TOK_ID:
|
||||
return "ID(" + tok.value + ")";
|
||||
case token::TOK_NUM:
|
||||
return "NUM(" + tok.value + ")";
|
||||
case token::TOK_OP:
|
||||
return "OP(" + tok.value + ")";
|
||||
case token::TOK_ASSIGN:
|
||||
return "ASSIGN ";
|
||||
case token::TOK_SEMI:
|
||||
return "SEMI ";
|
||||
case token::STM_ASSIGN:
|
||||
return "STM_ASSIGN( " + str_token(*tok.lvalue) + ", " + str_token(*tok.rvalue) + ")";
|
||||
case token::STM_COMPOUND:
|
||||
return "STM_COMPOUND( " + str_token(*tok.lvalue) + ", " + str_token(*tok.rvalue) + ")";
|
||||
case token::EXP_NUMBER:
|
||||
return "EXP_NUMBER(" + tok.value + ")";
|
||||
case token::EXP_OPERATION:
|
||||
return "EXP_OPERATION( " + str_token(*tok.lvalue) + " " + tok.value + " " + str_token(*tok.rvalue) +")";
|
||||
case token::EXP_ID:
|
||||
return "EXP_ID ";
|
||||
default:
|
||||
return "SOMETHING";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue