Have time to write a comment ^ o ^
Test PASCAL code snippet becom2a: = 9; if x> = 0 THEN x: = x 1; while a = 0 DO B: = a * x / 33455; end #
-------------------------------------------------- ------------------- Test results syn | value ________ | ________ 1 | begin10 | AB2A18 |: = 11 | 926 |; 2 | IF10 | x24 | = 11 | 03 | THEN10 | X18 |: = 10 | X14 | 11 | 126 |; 4 | While10 | A25 | = 11 | 05 | DO10 | B18 |: = 10 | A16 | * 10 | X17 | / 11 | 3345526 | End0 | #press any key to contact
Analytics C Code ------------------------------------------- ---------------------------------------------
#include
Union value_type {INT D; char C; char s [MAX_WD_LEN];
Typedef struct {int syn; union value_type value;} Word_Type;
/ ******************************************************** / Char * keywords [20] = {"begin", "if", "life", "while", "do", "end"}; char Source [max_src_len]; word_type word_stack [max_wd_cnt]; int line = 1, Wtop = 0, IP = 0;
/ ******************************************************** / Void p_word_stack () {INT i; Word_Type W; Printf ("SYN / T | Value / N"); Printf ("____________________ / n"); for (i = 0; I Return;} switch (c = source [ip]) {case ' ': w.Syn = 14; / * ' ' * / w.Value.c = ' '; Word_Stack [wtop ] = W; IP ; Break; case '-': w.Syn = 15; / * '-' * / w.value.c = '-'; Word_Stack [wtop ] = W; IP ; Break; Case '*': w.Syn = 16; / * '*' * / w.Value.c = '*'; Word_Stack [wtop ] = W; IP ; Break; Case '/': w.Syn = 17; w.Value.c = '/' Word_stack [WTOP ] = W; IP ; Break; Case ':': w.Syn = 19; w.Value.c = ':'; if ((c = source [ ip))! = '=' ) {Word_stack [wtop ] = W; } Else if (c == '=') {structure (w.value.s, ": ="); w.Syn = 18; Word_stack [wtop ] = W; IP ;} Break; Case '<': w .syn = 20; w.value.c = '<'; if ((c = source [ ip))! = '>' && c! = '=') {Word_Stack [wtop ] = W;} else IF (c == '>) {w.Syn = 21; strcpy (w.Value.s, "<>"); word_stack [wtop ] = W; IP ;} else if (c ==' = ') {W.Syn = 22; strcpy (w.value.s, "<="); word_stack [wtop ] = W; IP ;} Break; case '>': w.Syn = 23; w.Value.c = '>; if ((c = source [ ip])! =' = ') {Word_stack [Wtop ] = W;} ELSE IF (c == '=') {w.syn = 24; strcpy (w.value.s, "> = "); Word_stack [wtop ] = W; IP ;} Break; case '=': w.Syn = 25; w.Value.c = '='; Word_stack [Wtop ] = W; IP ; Break; Case '; ': W.Syn = 26; w.Value.c ='; '; Word_Stack [wtop ] = W; IP ; Break; Case' (': w.syn = 27; w.value.c =' ('; Word_stack [WTOP ] = W; IP ; Break; Case ')') ': w.Syn = 28; W.Value.c =') '; Word_stack [Wtop ] = W; IP ; Break; Case': While (Source [ ip] == '); Break; Case '/ N': line ; while (Source [ IP] == '/ n') line ; Break;