Esempio n. 1
0
struct verilog_module *verilog_parse_fd(FILE *fd)
{
	struct scanner *s;
	int tok;
	void *p;
	char *stoken;
	struct verilog_module *m;

	//ParseTrace(stdout, "parser: ");
	s = scanner_new(fd);
	m = verilog_new_module();
	p = ParseAlloc(malloc);
	assert(p != NULL);
	tok = scanner_scan(s);
	while(tok != TOK_EOF) {
		stoken = scanner_get_token(s);
		Parse(p, tok, stoken, m);
		tok = scanner_scan(s);
	}
	Parse(p, TOK_EOF, NULL, m);
	ParseFree(p, free);
	scanner_free(s);

	return m;
}
Esempio n. 2
0
enum TOKEN
scanner_peek_token ()
{
  if (have_peek)
    return scan_peek;

  scan_peek = scanner_get_token ();
  have_peek = true;
  return scan_peek;
}
Esempio n. 3
0
/**
 *
 * Testovaci modul pre scanner.c
 */
int main( int argc, char *argv[] )
{
    if( argc != 2 )
    {
        fprintf( stderr, "Error: No input file specified !\n" );
        return E_OTHER;
    }

    E_ERROR_TYPE ret_val;
    char *handle_subor;     /**< abstrakcia zdrojoveho handle_suboru */
    unsigned file_size;       /**< velkost suboru */
    
    ret_val = mmap_file( argv[1], &handle_subor, &file_size );

    if ( ret_val != E_OK )
        return E_INTERPRET_ERROR;
    
    char *subor = handle_subor;
    
    if ( check_file_header( &subor ) != E_OK ) // kontrola '<?php ' na zaciatku handle_suboru
    {
        fprintf( stderr, "Error: Invalid source file.\n" );
        free(handle_subor);
        return E_SYNTAX;
    }
    
    
    T_token token;
    token.ttype = E_INVLD;
    
    scanner_init( subor, file_size - 5); // scanner dostava subor o 6 znakov mensi koli '<?php '
        
        
    printf("---------------------------");
    while(token.ttype != E_EOF)
    {
        scanner_get_token(&token);
        print_token(&token);
        getchar();
    }
    printf("---------------------------\n");
    
    free( handle_subor );
    return EXIT_SUCCESS;
}
Esempio n. 4
0
int TESTMAIN (int argc, const char* argv[])
{
  if (argc<2)
    die (EXIT_FAILURE, 0, _("missing script (among arguments)"));

  scanner_set_input_from_argv (argc-1, argv+1);

  enum TOKEN tok;
  while ( (tok = scanner_get_token ()) != TOK_END )
  {
    switch (tok)
    {
    case TOK_IDENTIFIER:
      printf ("TOK_IDENTIFIER: '%s'\n", scanner_identifier);
      break;

    case TOK_INTEGER:
      printf ("TOK_INTEGER: %lu ('%s')\n", scan_val_int, scanner_identifier);
      break;

    case TOK_FLOAT:
      printf ("TOK_FLOAT: %Lf ('%s')\n", scan_val_float, scanner_identifier);
      break;

    case TOK_COMMA:
      printf ("TOK_COMMA\n");
      break;

    case TOK_DASH:
      printf ("TOK_DASH\n");
      break;

    case TOK_COLONS:
      printf ("TOK_COLONS\n");
      break;

    default:
      die (EXIT_FAILURE, 0 ,_("unknown token %d\n"),tok);
    }
  }

  return 0;
}
Esempio n. 5
0
void dc_get_arg(uint type)
{
	scanner_get_token();

	Dc_command_line = scanner_bufferp;
	Dc_arg_org = scanner_token_string;
	Dc_arg = scanner_word_string;

	if (Dc_debug_on) {
		dc_printf( "next arg is '%s', was originally '%s'\n", Dc_arg, Dc_arg_org );
		dc_printf( "Rest of the command line is '%s'\n", Dc_command_line );
	}

	if ( scanner_token == NO_TOKEN ) {
		Dc_arg_type = ARG_NONE;
	} else if ( scanner_token == IDENTIFIER ) {
		Dc_arg_type = ARG_STRING;
	} else if ( scanner_token == STRING ) {
		Dc_arg_type = ARG_QUOTE;
	} else {
		Dc_arg_type = ARG_STRING;
	}

	if ( Dc_arg_type & ARG_STRING ) {
		int i, num_digits, len;

		len = strlen(Dc_arg);
		num_digits = 0;

		for (i=0; i<len; i++) {
			if ( scanner_char_table[Dc_arg[i]] == DIGIT ) {
				num_digits++;
			}

			if ( num_digits==len ) {
				Dc_arg_type |= ARG_FLOAT;
				Dc_arg_float = (float)atof(Dc_arg);
				if ( !strchr( Dc_arg, '.' )) {
					Dc_arg_type |= ARG_INT;
					Dc_arg_int = atoi(Dc_arg);
					Dc_arg_type |= ARG_UBYTE;
					Dc_arg_ubyte = (ubyte)atoi(Dc_arg);
				}
			} else {
				if ( (Dc_arg[0] == '0') && (Dc_arg[1] == 'x') ) {
					char *p;
					int n;
					n = strtol(Dc_arg,&p,0);
					if ( *p == 0 ) {
						Dc_arg_type |= ARG_INT|ARG_HEX;
						Dc_arg_int = n;
					}
				}
			}
		}

		if (Dc_debug_on) {
			if ( Dc_arg_type & ARG_FLOAT ) {
				dc_printf( "Found float number! %f\n", Dc_arg_float );
			}

			if ( Dc_arg_type & ARG_INT ) {
				dc_printf( "Found int number! %d\n", Dc_arg_int );
			}

			if ( Dc_arg_type & ARG_UBYTE ) {
				dc_printf( "Found ubyte number! %d\n", Dc_arg_ubyte );
			}

			if ( Dc_arg_type & ARG_HEX ) {
				dc_printf( "Found hex number! 0x%x\n", Dc_arg_int );
			}
		}

		if ( !stricmp( Dc_arg, "on" ) ) {
			Dc_arg_type |= ARG_TRUE;
		}
		if ( !stricmp( Dc_arg, "true" ) ) {
			Dc_arg_type |= ARG_TRUE;
		}
		if ( !stricmp( Dc_arg, "off" ) ) {
			Dc_arg_type |= ARG_FALSE;
		}
		if ( !stricmp( Dc_arg, "false" ) ) {
			Dc_arg_type |= ARG_FALSE;
		}

		if ( !stricmp( Dc_arg, "+" ) ) {
			Dc_arg_type |= ARG_PLUS;
		}

		if ( !stricmp( Dc_arg, "-" ) ) {
			Dc_arg_type |= ARG_MINUS;
		}

		if ( !stricmp( Dc_arg, "," ) ) {
			Dc_arg_type |= ARG_COMMA;
		}
	}

	if ( Dc_arg_type & ARG_INT) {
		if ( Dc_arg_int ) {
			Dc_arg_type |= ARG_TRUE;
		} else {
			Dc_arg_type |= ARG_FALSE;
		}
	}

	if ( Dc_arg_type & ARG_UBYTE) {
		if ( Dc_arg_ubyte ) {
			Dc_arg_type |= ARG_TRUE;
		} else {
			Dc_arg_type |= ARG_FALSE;
		}
	}

	if ( !(Dc_arg_type&type) ) {
		if ( (Dc_arg_type & ARG_NONE) && !(type & ARG_NONE) ) {
			dc_printf( "Error: Not enough parameters.\n" );
		} else {
			dc_printf( "Error: '%s' invalid type\n", Dc_arg );
			longjmp(dc_bad_arg,1);
		}
	}
}