[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4787: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4789: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4790: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4791: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
InsideQC Forums • View topic - Compiling Parenthesis Without Recursion

Compiling Parenthesis Without Recursion

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

Compiling Parenthesis Without Recursion

Postby Baker » Tue Mar 10, 2015 6:50 pm

Here is the short story.

I hate regex/posix search, it is cryptic. I am writing some code to search source code in real time.

1) I'm using what basically looks like natural language ...
2) Find: red -black +blue -"const blue"
3) I then compile the expression to bytes, the type of compare is an enum (compare_equals = 1, compare_equals_caseless = 2, compare_starts_with, compare_partial, ...)

Parenthesis?
4) john and (fred or bob)

How can I evaluate parenthesis without recursion? My goal is for the byte code to be reversible back into text.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Compiling Parenthesis Without Recursion

Postby ericw » Tue Mar 10, 2015 7:31 pm

Whenever you hit an opening paren, push something on to a stack that says "opening paren at character X".
When you hit a closing paren, you know it's closing the top paren on the stack, so pop that off.
ericw
 
Posts: 92
Joined: Sat Jan 18, 2014 2:11 am

Re: Compiling Parenthesis Without Recursion

Postby Baker » Wed Mar 11, 2015 12:26 am

Haha, I came to that conclusion and then read this! I'm a bit happy I worked through it myself.

This problem had been ticking me off. Truth is, there isn't an easy way to avoid the recursion (it can be done by reordering, but then I'm destroying the reversibility back to text) and using a stack is technically recursion (whether you dodge it with a stack and a for loop) but that is what is really going on so.

And it made me see that any time you have a () in an equation it is a virtual function, no wonder languages came up with the idea of throwing a name before the () and creating the idea of named functions.

Well, 2 weeks ago the idea of how to write my own pattern matching was a bit of a mystery and now I'm first and goal from the 5 yard line. :D

(I didn't expect I'd be writing byte code to solve this a couple of weeks ago, but the idea of reinterpreting a string over and over again is quite redundant.)
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Compiling Parenthesis Without Recursion

Postby frag.machine » Wed Mar 11, 2015 12:41 am

This reminds me about the venerable .
IIRC there's a non-recursive expression evaluator there, may be worth to check it for ideas.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2120
Joined: Sat Nov 25, 2006 1:49 pm

Re: Compiling Parenthesis Without Recursion

Postby Baker » Wed Mar 11, 2015 9:02 pm

The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Compiling Parenthesis Without Recursion

Postby revelator » Sat Mar 14, 2015 1:08 am

Aye old style basic ain't all that bad :) freebasic still works that way but can link to and use C or C++ libraries.
I actually started coding in basic way way back but i havent used it for much in the later years so i forgot most of the syntax :) i do remember the goto's though hehe.
Was a pretty hardcore language back then also cause there was no such thing as debuggers so if you screwed up you could pretty much start over ;).
took around 14 days to write a ping pong game hehe.

asm jmp ;) yep correct thats a goto.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Compiling Parenthesis Without Recursion

Postby Baker » Sat Mar 14, 2015 5:26 am

I did some quick checking.

BASIC (1964) is older than C (1972).
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: Compiling Parenthesis Without Recursion

Postby revelator » Sun Mar 15, 2015 10:13 am

does not surprise me i first heard of C/C++ way later :) damn basic is older than me Oo im from 68.
I think even cobol is older than C i had one of the piccolo's (early PC) which used an OS built in cobol way back in the early 90's, newer learned the language and the OS was weird as hell to get around in.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Compiling Parenthesis Without Recursion

Postby revelator » Sun Mar 15, 2015 3:52 pm

Ah no remembered wrong the piccolo used a language called comal80.
But cobol is also older than C 1969 :) it was an industrial language, and easy to learn but it had some drawbacks like not being able to construct advanced structures.
Comal80 (1973) was invented by some of my countrymen Benedict Løfstedt and Børge Christensen, same as C++ (early 80's) which was invented by bjarne stroustrup guess us danes are not so stupid after all ;).
Should have kept that old piece of junk, its worth a fortune today hehe.
Productivity is a state of mind.
User avatar
revelator
 
Posts: 2605
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 2 guests