fix nome pasta
This commit is contained in:
parent
c4b6c19b09
commit
cf4352b80d
3 changed files with 0 additions and 118 deletions
|
@ -1,22 +0,0 @@
|
||||||
/* factorial.p
|
|
||||||
-- 2023-03-20
|
|
||||||
-- by jcr
|
|
||||||
*/
|
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// Função que calcula o factorial dum número n
|
|
||||||
function fact(n){
|
|
||||||
int res = 1;
|
|
||||||
while res > 1 {
|
|
||||||
res = res * n;
|
|
||||||
res = res - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Programa principal
|
|
||||||
program myFact{
|
|
||||||
for i in [1..10]{
|
|
||||||
print(i, fact(i));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
/* max.p: calcula o maior inteiro duma lista desordenada
|
|
||||||
-- 2023-03-20
|
|
||||||
-- by jcr
|
|
||||||
*/
|
|
||||||
|
|
||||||
int i = 10, a[10] = {1,2,3,4,5,6,7,8,9,10};
|
|
||||||
|
|
||||||
// Programa principal
|
|
||||||
program myMax{
|
|
||||||
int max = a[0];
|
|
||||||
for i in [1..9]{
|
|
||||||
if max < a[i] {
|
|
||||||
max = a[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print(max);
|
|
||||||
}
|
|
79
tpc6/tpc6.py
79
tpc6/tpc6.py
|
@ -1,79 +0,0 @@
|
||||||
import ply.lex as lex
|
|
||||||
|
|
||||||
|
|
||||||
reserved = {
|
|
||||||
"function": "FUNC",
|
|
||||||
"program": "PROG",
|
|
||||||
"while": "WHILE",
|
|
||||||
"for": "FOR",
|
|
||||||
"in": "IN",
|
|
||||||
"if": "IF",
|
|
||||||
"else": "ELSE",
|
|
||||||
"int": "INT",
|
|
||||||
"float": "FLOAT",
|
|
||||||
}
|
|
||||||
|
|
||||||
states = (
|
|
||||||
('mlcom', "exclusive"),
|
|
||||||
)
|
|
||||||
|
|
||||||
tokens = ["ID", "NUM","GT", "LT", "COMMENT","OPENCOM","CLOSECOM","DDOT"] + list(reserved.values())
|
|
||||||
literals = ",=*+-;{}[]()"
|
|
||||||
|
|
||||||
|
|
||||||
def t_ID(t):
|
|
||||||
r"[a-zA-Z_][a-zA-Z_0-9]*"
|
|
||||||
t.type = reserved.get(t.value, "ID")
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_NUM(t):
|
|
||||||
r"\d+(\.\d+)?"
|
|
||||||
if "." in t.value:
|
|
||||||
t.value = float(t.value)
|
|
||||||
else:
|
|
||||||
t.value = int(t.value)
|
|
||||||
return t
|
|
||||||
def t_DDOT(t):
|
|
||||||
r"\.\."
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_GT(t):
|
|
||||||
r">"
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_LT(t):
|
|
||||||
r"<"
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_INITIAL_OPENCOM(t):
|
|
||||||
r"\/\*"
|
|
||||||
t.lexer.begin('mlcom')
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_mlcom_CLOSECOM(t):
|
|
||||||
r"\*\/"
|
|
||||||
t.lexer.begin("INITIAL")
|
|
||||||
return t
|
|
||||||
|
|
||||||
def t_COMMENT(t):
|
|
||||||
r"\/\/.*"
|
|
||||||
pass
|
|
||||||
|
|
||||||
def t_mlcom_COMMENT(t):
|
|
||||||
r"[^*]+"
|
|
||||||
pass
|
|
||||||
|
|
||||||
t_ANY_ignore = " \t\n"
|
|
||||||
|
|
||||||
def t_ANY_error(t):
|
|
||||||
print("Illegal character '%s'" % t.value[0])
|
|
||||||
t.lexer.skip(1)
|
|
||||||
|
|
||||||
lexer = lex.lex()
|
|
||||||
|
|
||||||
f = open("example2","r")
|
|
||||||
|
|
||||||
lexer.input(f.read())
|
|
||||||
|
|
||||||
for tok in lexer:
|
|
||||||
print(tok)
|
|
Loading…
Add table
Add a link
Reference in a new issue