Jump to content


parsing text


17 replies to this topic

#1 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 27 February 2011 - 11:18 PM

hi
i was jus wondering if i should use boost regexp to ease my parsing of the bsp entities text
i think in quake3 they are just using regular c string functions to parse this
but that is just simply way too much code
and could be done way faster with reg exp help
but installing boost c++ libs to get reg exp is like 240mb
why is boost asking for that much room?
how should i parse this?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 27 February 2011 - 11:41 PM

Boost is a notorious dependency nightmare. There are probably lighter-weight regex libraries out there. I'm not familiar with the "bsp entities text" so I can't advise on whether regex parsing would be an appropriate solution for that, though.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 28 February 2011 - 12:46 AM

well all the entities are like this

{
"name" "value"
"name2" "value2"
}

so w preg_match i would just do

entities[] = preg_match(/{.*?}/)

entities[i].lines[] = explode(entities[i], "\n")

preg_match(/(\".*?\")\s+?(\".*?\")/, entities[i].lines[i], entities[i].nameandvaluearray)

#4 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 28 February 2011 - 02:45 AM

It's a very simple format, with a clearly defined syntax, so using regex for it, seems a bit drastic. You can always look at the Q3A source, to see how they did it.
"Stupid bug! You go squish now!!" - Homer Simpson

#5 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 28 February 2011 - 05:45 AM

well i said i think in my post but i was looking at the quake 3 source haha
its just that quake source is using only using c string function and logic i guess
so i thot it be way less code to do it with regex

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 28 February 2011 - 06:22 AM

Given that C++ doesn't have regex functionality built-in, it's probably easier to just parse it manually.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 28 February 2011 - 11:04 AM

If I recall correctly I implemented a Quake 1 BSP reader using merely scanf. Of course, it didn't have any error detection mechanism so the file had to be to spec, but other than that it was very easy to implement.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#8 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 28 February 2011 - 11:09 AM

what is scanf
and no i dont need error detection
the less code the better
ill add that stuff later

#9 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 698 posts

Posted 28 February 2011 - 11:28 AM

scanf is the inverse of printf, more or less. google.

#10 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2718 posts

Posted 28 February 2011 - 01:32 PM

I'm going to be doing a bit of parsing myself, soon, because ill be writing a scripting engine for my ai and gameplay code.

My plan to make things simpler is to do a precompile to reduce everything in the typed code to simple 2 variable + one operator instructions, then interpreting after that will be really simple.

Just like .oisyn says, little more than scanf is all you need. :)
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#11 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 01 March 2011 - 02:09 AM

ok but i find it a bit backwards for the most flexible and advanced language like c++ not to have preg_match out of the box
this is a perfect place to use it and i would like to have it anyways
i also mad at c++ strings because i cant printf them
it tells me that printf is expecting a string and my string is an int, wtfff
so i tried converting string to char and it wont let me do that either
what is wrong with u c++ lol
c++ is acting like c--
maybe even an f+

#12 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 01 March 2011 - 05:10 AM

C++ is a low-level language - it's "advanced" because you need to be an advanced programmer to use it well. :D Anyway, it's a valid complaint that it lacks some of the "productivity" features of more modern languages. You could look at C# and D for contrasting design approaches.

By the way, C-- is an actual language, although one designed more as an intermediate language for compilers than a language for humans.
reedbeta.com - developer blog, OpenGL demos, and other projects

#13 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 01 March 2011 - 07:23 AM

enjoycrf said:

i also mad at c++ strings because i cant printf them
You can, but you need to send the correct data to the function. "%s" means that printf will interpret the variable passed as a string of characters, and not as a class from the stl, which contains a string and other data. So you would need to write 'printf("%s", str.c_str());'.

In C++, you shouldn't even use the C I/O functions, but the STL counterpart, like 'cout << str;'. See here for more info, and here for why you should avoid printf and the likes.

enjoycrf said:

like c++ not to have preg_match out of the box
C++0x has the <regex> header you can use. Video tutorial, for your viewing pleasure: http://channel9.msdn...rary-STL-8-of-n
"Stupid bug! You go squish now!!" - Homer Simpson

#14 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 01 March 2011 - 08:29 AM

whoa thx for all the l33t info

hmm this looks very familiar
lets try this again

#15 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 01 March 2011 - 08:37 AM

omgomg i jus looked on ubuntu forums and it said to remove the .h from iostream and it compiled hahaha
could that possibly be windows code?
i migrated from windows
plus i get code from dif sources

#16 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 01 March 2011 - 08:40 AM

omg all these compiled too now
wow i am a total nuub
i guess i just found that i am doing c style file handling too?

#include <fstream> // Include this to use ifstream
#include <vector> // Include this to use STL vectors

#17 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 01 March 2011 - 08:41 AM

Could you try editing your post rather than placing multiple posts in quick succession?
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#18 enjoycrf

    Banned

  • Banned
  • PipPip
  • 52 posts

Posted 01 March 2011 - 08:50 AM

wow i just think i added stl regex support

g++ %f -o nice -lGLU -lGL -lglut -lfmodex -std=c++0x
slim, mean and lean cuisine lol

let me kno if theres something beter or i should be using





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users