Beruflich Dokumente
Kultur Dokumente
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// Constants
#define MAX_SYMBOL_TABLE_SIZE 50
#define MAX_LITERAL_TABLE_SIZE 50
// Token types
typedef enum {
TOKEN_IDENTIFIER,
TOKEN_LITERAL,
TOKEN_OPERATOR,
TOKEN_DELIMITER,
TOKEN_ERROR
} TokenType;
// Token structure
typedef struct {
TokenType type;
char lexeme[20];
} Token;
typedef struct {
char name[20];
int address;
} SymbolEntry;
typedef struct {
char value[20];
int address;
} LiteralEntry;
typedef struct {
char value[20];
int address;
} PoolEntry;
// Function prototypes
void printSymbolTable();
void printLiteralTable();
void printPoolTable();
// Global variables
SymbolEntry symbolTable[MAX_SYMBOL_TABLE_SIZE];
int symbolTableSize = 0;
LiteralEntry literalTable[MAX_LITERAL_TABLE_SIZE];
int literalTableSize = 0;
PoolEntry poolTable[MAX_LITERAL_TABLE_SIZE];
int poolTableSize = 0;
int main() {
char code[MAX_CODE_LENGTH];
Token currentToken;
if (isalpha(token[0])) {
currentToken.type = TOKEN_IDENTIFIER;
} else if (isdigit(token[0])) {
currentToken.type = TOKEN_LITERAL;
currentToken.type = TOKEN_OPERATOR;
currentToken.type = TOKEN_DELIMITER;
} else {
currentToken.type = TOKEN_ERROR;
strcpy(currentToken.lexeme, token);
switch (currentToken.type) {
case TOKEN_IDENTIFIER:
break;
case TOKEN_LITERAL:
break;
default:
break;
printf("\nSymbol Table:\n");
printSymbolTable();
printf("\nLiteral Table:\n");
printLiteralTable();
printf("\nPool Table:\n");
printPoolTable();
return 0;
SymbolEntry entry;
strcpy(entry.name, lexeme);
entry.address = address;
symbolTable[symbolTableSize++] = entry;
} else {
}
// Function to add an entry to the literal table
LiteralEntry entry;
strcpy(entry.value, value);
entry.address = address;
literalTable[literalTableSize++] = entry;
} else {
if (strcmp(poolTable[i].value, value) == 0) {
PoolEntry entry;
strcpy(entry.value, value);
entry.address = address;
poolTable[poolTableSize++] = entry;
} else {
void printSymbolTable() {
printf("Name\tAddress\n");
void printLiteralTable() {
printf("Value\tAddress\n");
void printPoolTable() {
printf("Value\tAddress\n");
Enter the source code: START 100 L1 READ A SUB AREG =5 BC GT L1 STOP A DS 1
Symbol Table:
Name Address
START 1000
L1 1001
READ 1002
A 1003
SUB 1004
AREG 1005
BC 1006
GT 1007
L1 1008
STOP 1009
A 1010
DS 1011
Literal Table:
Value Address
100 2000
1 2001
Pool Table:
Address
3001
3002
PS D:\c Language>