- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Page 729 in Software
Page 729 Paint QR Code 2d Barcode In None Using Barcode creation for Software Control to generate, create QR image in Software applications. Quick Response Code Scanner In None Using Barcode decoder for Software Control to read, scan read, scan image in Software applications. is also called by other routines in the interpreter whenever an error occurs The sntx_err( ) function is shown here: QR Code JIS X 0510 Creator In Visual C#.NET Using Barcode creator for Visual Studio .NET Control to generate, create QR Code image in VS .NET applications. Encode Denso QR Bar Code In VS .NET Using Barcode drawer for ASP.NET Control to generate, create Denso QR Bar Code image in ASP.NET applications. /* Display an error message */ void sntx_err(int error) { char *p, *temp; int linecount = 0; register int i; static char *e[]= { ''syntax error", "unbalanced parentheses", "no expression present", "equals sign expected", "not a variable", "parameter error", "semicolon expected", "unbalanced braces", "function undefined", "type specifier expected", "too many nested function calls", "return without call", "parentheses expected", "while expected", "closing quote expected", "not a string", "too many local variables", "division by zero" }; printf("\n%s", e[error]); p = p_buf; while(p ! = prog) { /* find line number of error */ p++; if(*p == '\r') { linecount++; } } printf(" in line %d\n", linecount); temp = p; for(i=0; i < 20 && p > p_buf && *p != '\n'; i++, p--); Paint QR Code ISO/IEC18004 In VS .NET Using Barcode encoder for VS .NET Control to generate, create QR Code image in .NET framework applications. Encoding QR In VB.NET Using Barcode generation for .NET framework Control to generate, create Quick Response Code image in .NET applications. Page 730 for(i=0; i < 30 && p <= temp; i++, p++) printf("%c", *p); longjmp(e_buf, 1); /* return to safe point */ } Generate Data Matrix 2d Barcode In None Using Barcode creator for Software Control to generate, create Data Matrix 2d barcode image in Software applications. UCC-128 Generator In None Using Barcode creation for Software Control to generate, create EAN / UCC - 14 image in Software applications. Notice that sntx_err( ) also displays the line number in which the error was detected (which may be one line after the error actually occurred) and displays the line in which it occurred Further, notice that sntx_err( ) ends with a call to longjmp( ) Because syntax errors are frequently encountered in deeply nested or recursive routines, the easiest way to handle an error is simply to jump to a safe place Although it is possible to set a global error flag and interrogate the flag at various points in each routine, this adds unnecessary overhead The Little C Recursive-Descent Parser The entire code for the Little C recursive-descent parser is shown here, along with some necessary support functions, global data, and data types This code, as shown, is designed to go into its own file For the sake of discussion, call this file PARSERC (Because of its size, the Little C interpreter is spread among three separate files) Creating Bar Code In None Using Barcode creation for Software Control to generate, create bar code image in Software applications. Bar Code Generator In None Using Barcode encoder for Software Control to generate, create bar code image in Software applications. /* Recursive descent parser for integer expressions which may include variables and function calls */ #include <setjmph> #include <mathh> #include <ctypeh> #include <stdlibh> #include <stringh> #include <stdioh> #define #define #define #define #define #define #define NUM_FUNC NUM_GLOBAL_VARS NUM_LOCAL_VARS ID_LEN FUNC_CALLS PROG_SIZE FOR_NEST 100 100 200 31 31 10000 31 Encode UPC-A In None Using Barcode generation for Software Control to generate, create GS1 - 12 image in Software applications. USS Code 39 Encoder In None Using Barcode generator for Software Control to generate, create Code-39 image in Software applications. enum tok_types {DELIMITER, IDENTIFIER, NUMBER, KEYWORD, TEMP, STRING, BLOCK}; enum tokens {ARG, CHAR, INT, IF, ELSE, FOR, DO, WHILE, Generate Case Code In None Using Barcode maker for Software Control to generate, create UPC Shipping Container Symbol ITF-14 image in Software applications. UPC-A Supplement 5 Maker In .NET Using Barcode encoder for Visual Studio .NET Control to generate, create UPC Symbol image in .NET framework applications. Team-Fly
Printing Matrix 2D Barcode In Visual Basic .NET Using Barcode encoder for .NET framework Control to generate, create 2D Barcode image in Visual Studio .NET applications. Painting Bar Code In VB.NET Using Barcode encoder for .NET Control to generate, create barcode image in .NET applications. AM FL Y
Recognize Barcode In Java Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications. UCC - 12 Reader In Visual Basic .NET Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications. Page 731 SWITCH, RETURN, EOL, FINISHED, END}; enum double_ops {LT=1, LE, GT, GE, EQ, NE}; /* 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_TEMP, TOO_MANY_LVARS, DIV_BY_ZERO}; extern char *prog; /* current location in source code */ extern char *p_buf; /* points to start of program buffer */ extern jmp_buf e_buf; /* hold environment for longjmp() */ /* An array of these structures will hold the info associated with global variables */ extern struct var_type { char var_name[32]; int v_type; int value; } global_vars[NUM_GLOBAL_VARS]; /* This is the function call stack */ extern struct func_type { char func_name[32]; int ret_type; char *loc; /* location of function entry point in file */ } func_stack[NUM_FUNC]; /* Keyword table */ extern struct commands { char command[20]; char tok; } table[]; Decode GS1 - 12 In None Using Barcode reader for Software Control to read, scan read, scan image in Software applications. Data Matrix 2d Barcode Creator In None Using Barcode maker for Microsoft Word Control to generate, create Data Matrix image in Microsoft Word applications. Page 732 /* "Standard library" functions are declared here so they can be put into the internal function table that follows */ int call_getche(void), call_putch(void); int call_puts(void), print(void), getnum(void); struct intern_func_type { char *f_name; /* function name */ int (*p)(); /* pointer to the function */ } intern_func[] = { ''getche", call_getche, "putch", call_putch, "puts", call_puts, "print", print, "getnum", getnum, "", 0 /* null terminate the list */ }; extern char token[80]; /* string representation of token */ extern char token_type; /* contains type of token */ extern char tok; /* internal representation of token */ extern int ret_value; /* function return value */ void eval_exp0(int *value); void eval_exp(int *value); void eval_exp1(int *value); void eval_exp2(int *value); void eval_exp3(int *value); void eval_exp4(int *value); void eval_exp5(int *value); void atom(int *value); void sntx_err(int error), putback(void); void assign_var(char *var_name, int value); int isdelim(char c), look_up(char *s), iswhite(char c); int find_var(char *s), get_token(void); int internal_func(char *s); int is_var(char *s); char *find_func(char *name); void call(void) Page 733 /* Entry point into parser */ void eval_exp(int *value) { get_token(); if(!*token) { sntx_err(NO_EXP); return; } if(*token == ';') { *value = 0; /* empty expression */ return; } eval_exp0 (value); putback(); /* return last token read to input stream */ } /* Process an assignment expression */ void eval_exp0(int *value) { char temp [ID_LEN]; /* holds name of var receiving the assignment */ register int temp_tok; if(token_type == IDENTIFIER) { if(is_var(token)) { /* if a var, see if assignment */ strcpy(temp, token); temp_tok = token_type; get_token(); if(*token == '=') { /* is an assignment */ get_token(); eval_exp0(value); /* get value to assign */ assign_var(temp, *value); /* assign the value */ return; } else { /* not an assignment */ putback(); /* restore original token */ strcpy(token, temp); token_type = temp_tok; } } } eval_exp1(value); Page 734 } /* Process relational operators */ void eval_exp1(int *value) { int partial_value; register char op; char relops[7] = { LT, LE, GT, GE, EQ, NE, 0 }; eval_exp2(value); op = *token; if(strchr(relops, op)) { get_token(); eval_exp2(&partial_value); switch(op) { /* perform the relational operation */ case LT: *value = *value < partial_value; break; case LE: *value = *value <= partial_value; break; case GT: *value = *value > partial_value; break; case GE: *value = *value >= partial_value; break; case EQ: *value = *value == partial_value; break; case NE: *value = *value != partial_value; break; } } } /* Add or subtract two terms */ void eval_exp2(int *value) { Page 735 register char op; int partial_value; eval_exp3(value); while((op = *token) == '+' || op == '-') { get_token(); eval_exp3(&partial_value); switch(op) { /* add or subtract */ case '-': *value = *value - partial_value; break; case '+': *value = *value + partial_value; break; } } } /* Multiply or divide two factors */ void eval_exp3(int *value) { register char op; int partial_value, t; eval_exp4 (value); while((op = *token) == '*' || op == '/' || op == '%') { get_token (); eval_exp4 (&partial_value); switch(op) { /* mul, div, or modulus */ case '*': *value = *value * partial_value; break; case '/': if(partial_value == 0) sntx_err(DIV_BY_ZERO); *value = (*value) / partial_value; break; case '%': t = (*value) / partial_value; *value = *value-(t * partial_value); break; } } Page 736 } /* Is a unary + or - * void eval_exp4(int *value) { register char op; op = '\0'; if(*token == '+' || *token == '-') { op = *token; get_token(); } eval_exp5(value); if(op) if(op == '-') *value = -(*value); } /* Process parenthesized expression */ void eval_exp5(int *value) { if((*token == '(')) { get_token(); eval_exp0(value); /* get subexpression */ if(*token != ')') sntx_err(PAREN_EXPECTED); get_token(); } else atom(value); } /* Find value of number, variable, or function */ void atom(int *value) { int i; switch(token_type) { case IDENTIFIER: i = internal_func(token); if(i!= -1) { /* call ''standard library" function */ *value = (*intern_func[i]p)(); } else Page 737 if(find_func(token)) { /* call user-defined function */ call(); *value = ret_value; } else *value = find_var(token); /* get var's value */ get_token(); return; case NUMBER: /* is numeric constant */ *value = atoi(token); get_token(); return; case DELIMITER: /* see if character constant */ if(*token == '\'') { *value = *prog; prog++; if (*prog!='\'') sntx_err(QUOTE_EXPECTED); prog++; get_token(); return } if(*token==')') return; /* process empty expression */ else sntx_err(SYNTAX); /* syntax error */ default: sntx_err(SYNTAX); /* syntax error */ } } /* Display an error message */ void sntx_err(int error) { char *p, *temp; int linecount = 0; register int i; static char *e[]= { ''syntax error", "unbalanced parentheses", "no expression present", "equals sign expected", "not a variable", "parameter error", "semicolon expected", Page 738 "unbalanced braces", ''function undefined", "type specifier expected", "too many nested function calls", "return without call", "parentheses expected", "while expected", "closing quote expected", "not a string", "too many local variables", "division by zero" }; printf("\n%s", e[error]); p = p_buf; while(p != prog) { /* find line number of error */ p++; if(*p == '\r') { linecount++; } } printf(" in line %d\n", linecount); temp = p; for(i=0; i < 20 && p > p_buf && *p != '\n'; i++, p--); for(i=0; i < 30 && p <= temp; i++, p++) printf("%c", *p); longjmp(e_buf, 1); /* return to safe point */ } /* Get a token */ int get_token(void) { register char *temp; token_type = 0; tok = 0; temp = token; *temp = '\0'; /* skip over white space */ while(iswhite(*prog) && *prog) ++prog; Page 739 if(*prog == '\r') { ++prog; ++prog; /* skip over white space */ while(iswhite(*prog) && *prog) ++prog; } if(*prog == '\0') { /* end of file */ *token = '\0'; tok = FINISHED; return (token_type = DELIMITER); } if(strchr("{}", *prog)) { /* block delimiters */ *temp = *prog; temp++; *temp = '\0'; prog++; return (token_type = BLOCK); } /* look for comments */ if(*prog == '/') if(*(prog+1) == '*') { /* is a comment */ prog += 2; do { /* find end of comment */ while(*prog != *') prog++; prog++; } while (*prog != '/'); prog++; } if(strchr("!<>=", *prog)) { /* is or might be a relational operator */ switch(*prog) { case '=': if(*(prog+1) == '=') { prog++; prog++; *temp = EQ; temp++; *temp = EQ; temp++; *temp = '\0'; } break; Page 740 case '!': if(*(prog+1) == '=') { prog++; prog++; *temp = NE; temp++; *temp = NE; temp++; *temp = \0'; } break; case '<': if(*(prog+1) == '=') { prog++; prog++; *temp = LE; temp++; *temp = LE; } else { prog++; *temp = LT; } temp++; *temp = '\0'; break; case '>': if(*(prog+1) == '=') { prog++; prog++; *temp = GE; temp++; *temp = GE; } else { prog++; *temp = GT; } temp++; *temp = '\0'; break; } if(*token) return(token_type = DELIMITER); } if(strchr("+-*^/%=;(),'", *prog)){ /* delimiter */ *temp = *prog; prog++; /* advance to next position */ temp++; *temp = '\0'; return (token_type = DELIMITER); } if(*prog=='"') { /* quoted string */
|
|