Derleyici Tasarımı
Yüklüyor...
Arıyor...
Eşleşme Yok
bc-grammar.h
Bu dosyanın dokümantasyonuna git.
1
6#ifndef BC_GRAMMAR_H
7#define BC_GRAMMAR_H
8
9
10#include "tokenizer.h"
11
13#include <rdesc/grammar.h>
14
16#define BC_NT_COUNT 22
18#define BC_MAX_ALT_COUNT 13
20#define BC_MAX_ALT_SIZE 10
21
25 TK_PLUS, TK_MINUS, TK_STAR, TK_SLASH, TK_PERCENT, TK_CARET,
26 TK_PLUSEQ, TK_MINUSEQ, TK_STAREQ, TK_SLASHEQ, TK_PERCENTEQ, TK_CARETEQ, TK_EQ,
27 TK_PLUSPLUS, TK_MINUSMINUS,
28 TK_LT, TK_GT, TK_EQEQ, TK_EXCLEQ, TK_LTEQ, TK_GTEQ,
29 TK_LPAREN, TK_RPAREN, TK_LCURLY, TK_RCURLY, TK_SEMI, TK_COMMA,
30 TK_DEFINE, TK_BREAK, TK_QUIT, TK_PRINT,
31 TK_RETURN, TK_FOR, TK_IF, TK_WHILE, TK_CST,
32 /* TK_IDENT, TK_INT ve TK_FLOAT tokenizer tarafından tanımlanır */
33};
34
37 NT_STMT, NT_STMTS,
38
39 NT_ADD_OP, NT_MUL_OP,
40 NT_ASGN_OP, NT_REL_OP,
41 NT_UNARY_OP, NT_INCR_DECR_OP, NT_OPT_INCR_DECR_OP,
42
43 NT_ADD_EXPR, NT_ADD_EXPR_REST,
44 NT_MUL_EXPR, NT_MUL_EXPR_REST,
45 NT_EXP_EXPR, NT_EXP_EXPR_REST,
46 NT_FACTOR, NT_ATOM,
47 NT_ASGN_EXPR, NT_REL_EXPR, NT_REL_EXPR_OPT_REL,
48 NT_OPT_EXPR,
49
50 NT_EXPR,
51};
52
54/* Bu string karşılıkları tokenizer'a punctuation ve keyword eklemek için
55 * kullanacağız. */
56const char *bc_tk_names[] = {
57 "+", "-", "*", "/", "%", "^",
58 "+=", "-=", "*=", "/=", "%=", "^=", "=",
59 "++", "--",
60 "<", ">", "==", "!=", "<=", ">=",
61 "(", ")", "{", "}", ";", ",",
62 "define", "break", "quit", "print",
63 "return", "for", "if", "while", "cst",
64
65 /* librdesc'in dump_bnf fonksiyonuyla gramer yapımızı birazdan print
66 * edeceğiz. */
67 [TK_INT] = "@int", [TK_FLOAT] = "@float", [TK_IDENT] = "@ident",
68};
69
71/* Nonterminal isimleri ve yukarıdaki [] içindeki token isimleri, dump_bnf
72 * özelligi için. */
73const char *bc_nt_names[] = {
74 "stmt", "stmts",
75
76 "add_op", "mul_op",
77 "asgn_op", "rel_op",
78 "unary_op", "incr_decr_op", "opt_incr_decr_op",
79
80 "add_expr", "add_expr_rest",
81 "mul_expr", "mul_expr_rest",
82 "exp_expr", "exp_expr_rest",
83 "factor", "atom",
84 "asgn_expr", "rel_expr", "rel_expr_opt_rel",
85 "opt_expr",
86
87 "expr",
88};
90
92/* Gramer tanımını tutacak struct'ı declare ediyoruz.*/
93extern struct rdesc_grammar_symbol bc_production_rules
96
99
100
101#endif
struct rdesc_grammar_symbol bc_production_rules[BC_NT_COUNT][BC_MAX_ALT_COUNT+1][BC_MAX_ALT_SIZE+1]
[Token/nonterminal ID]
#define BC_MAX_ALT_COUNT
Definition bc-grammar.h:18
const char * bc_tk_names[]
Definition bc-grammar.h:56
#define BC_NT_COUNT
[Gramer declaration]
Definition bc-grammar.h:16
bc_nt_id
Nonterminal ID.
Definition bc-grammar.h:36
bc_tk_id
Token ID.
Definition bc-grammar.h:24
const char * bc_nt_names[]
Definition bc-grammar.h:73
void bc_tokenizer_init(struct tokenizer *tokenizer)
[Gramer declaration]
#define BC_MAX_ALT_SIZE
Definition bc-grammar.h:20
tokenizer.
Definition tokenizer.h:33
Tokenizer
#define TK_IDENT
Identifier token ID'si.
Definition tokenizer.h:28
#define TK_INT
Tam sayı token ID'si.
Definition tokenizer.h:22
#define TK_FLOAT
Ondalık sayı token ID'si.
Definition tokenizer.h:25