-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCLIB.c
114 lines (106 loc) · 2.83 KB
/
LCLIB.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
_ _____ _______________
| | / /| \/ || ___ \ ___ \
| |/ / | . . || |_/ / |_/ /
| \ | |\/| || __/| __/
| |\ \| | | || | | |
\_| \_/\_| |_/\_| \_|
[+]MPP is an interpreter for mpp language using Mint(naper interpreter) and tinyCC
[+]Author : Naper & XDarker
[+]Web site : www.naper.eu
[+]Web site : mpp-project.org
*/
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
extern char *prog; /* points to current location in program */
extern char token[80]; /* holds string representation of token */
extern char token_type; /* contains type of token */
extern char tok; /* holds the internal representation of token */
enum tok_types {DELIMITER, IDENTIFIER, NUMBER, COMMAND, STRING,
QUOTE, VARIABLE, BLOCK, FUNCTION};
/* These are the constants used to call sntx_err() when
a syntax error occurs. Add more if you like.
NOTE: SYNTAX is a generic error message used when
nothing else seems appropriate.
*/
enum error_msg
{SYNTAX, UNBAL_PARENS, NO_EXP, EQUALS_EXPECTED,
NOT_VAR, PARAM_ERR, SEMI_EXPECTED,
UNBAL_BRACES, FUNC_UNDEF, TYPE_EXPECTED,
NEST_FUNC, RET_NOCALL, PAREN_EXPECTED,
WHILE_EXPECTED, QUOTE_EXPECTED, NOT_STRING,
TOO_MANY_LVARS};
int get_token(void);
void sntx_err(int error), eval_exp(int *result);
void putback(void);
/* Get a character from console. (Use getchar()) if
your compiler does not support getche().) */
call_getche()
{
int ch;
struct termios origterm, tmpterm;
tcgetattr ( STDIN_FILENO, &origterm );
tmpterm = origterm;
tmpterm.c_lflag &= ~( ICANON | ECHO );
tcsetattr ( STDIN_FILENO, TCSANOW, &tmpterm );
ch = getchar();
tcsetattr ( STDIN_FILENO, TCSANOW, &origterm );
return ch;
}
/* Put a character to the display. (Use putchar()
if your compiler does not support putch().) */
call_putch()
{
int value;
eval_exp(&value);
printf("%c", value);
return value;
}
/* Call puts(). */
call_puts(void)
{
get_token();
if(*token!='(') sntx_err(PAREN_EXPECTED);
get_token();
if(token_type!=QUOTE) sntx_err(QUOTE_EXPECTED);
puts(token);
get_token();
if(*token!=')') sntx_err(PAREN_EXPECTED);
get_token();
if(*token!=';') sntx_err(SEMI_EXPECTED);
putback();
return 0;
}
/* A built-in console output function. */
int print(void)
{
int i;
get_token();
if(*token!='(') sntx_err(PAREN_EXPECTED);
get_token();
if(token_type==QUOTE) { /* output a string */
printf("%s ", token);
}
else { /* output a number */
putback();
eval_exp(&i);
printf("%d ", i);
}
get_token();
if(*token!=')') sntx_err(PAREN_EXPECTED);
get_token();
if(*token!=';') sntx_err(SEMI_EXPECTED);
putback();
return 0;
}
/* Read an integer from the keyboard. */
getnum(void)
{
char s[80];
gets(s);
while(*prog!=')') prog++;
prog++; /* advance to end of line */
return atoi(s);
}