Pascal language subsequators analyzer

xiaoxiao2021-03-11  206

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 #include #include #include #define MAX_WD_LEN 255 # define MAX_INT 32767 # define MAX_SRC_LEN 1000 # define MAX_WD_CNT 100 # define KWD_CNT 6 / * ****************************************************** /

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 = 1 && W.Syn <= 10) || W.Syn == 18 || W.Syn == 21 || W.SYN == 22 || W. SYN == 24) Printf ("% D / T |% S / N", W.Syn, W.Value.s); Else If (w.Syn == 11) Printf ("% D / T |% D /1 ",w.syn ,w.value.d); Else Printf ("% D / T |% C / N ", W.Syn, w.Value.c);} return;} void tell_err ()} Printf ("ERROR IN LINE% D / N", LINE); EXIT (1); Return;} void scan () {Word_Type W; CHAR C; INT J = 0; if (Isdigit (c = source [ip]) ) {W.Syn = 11; / * DD * * / w.Value.d = c-'0 '; while (isdigit (c = source [ ip]) w.Value.d = w.value. D * 10 c-'0 '; if (! isalpha (c)) Word_stack [Wtop ] = W; ELSE TELL_ERR (); Return;} if (isalpha (c = source [ip])) {w.syn = 10; / * (ll | d) * / w.Value.s [0] = C; While (isalpha (c = source [ IP]) || Isdigit (c)) W.Value.s [ J] = C; W.Value.s [j 1] = '/ 0'; for (j = 0; J

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;

转载请注明原文地址:https://www.9cbs.com/read-128957.html

New Post(0)