1. expression parser (simple) in EU
- Posted by "Robert J. Zydenbos" <zydenbos at BLR.VSNL.NET.IN> Jan 24, 1998
- 806 views
Here's a snippet I wrote some time ago from what is to be my Euphoria version of a database program I originally wrote in Forth. This takes a text string (e.g., a line of commands entered by the user), removes spaces and tabs and puts the items in that string away in a sequence, where the program can easily test the string for various criteria (e.g., whether the string is grammatically correct; so it can also be used in programs for processing natural languages, etc.). I've written a few lines around the function to test / demonstrate its use. Maybe this function is useful for all those Euphorians out there who are writing language interpreters etc. (I've written such functions in Forth, Pascal, Modula-2, C, Basic, but... Euphoria is Progress. The Euphorian 'sequence', combined with practically unlimited memory, makes this kind of thing easy to write.) ---SNIP--- -- exper. for testing the fnc. 'dissect' sequence invoer sequence uitkomst function dissect(sequence entry) --takes a string 'entry' and returns either {0} or --{number_of_words,{{word},{word}...}} --by Robert Zydenbos, Mysore (India) --version date 29.7.1997 sequence arg --contains the words found in 'entry' sequence a --word being found integer wel --boolean: are we in the middle of a word being found? integer l --length of 'entry' object kar --character taken from 'entry' arg = {} a = {} wel = 0 l = length(entry) for x=1 to l-1 do kar = entry[x] --the next line was just for debugging: --printf(1,"kar = %s\n",kar) if kar=' ' or kar=9 then if wel then arg = arg & {a} wel = 0 a = {} end if else if not wel then wel = -1 end if a = a & kar end if end for if length(a) then arg = arg & {a} end if if not length(arg) then return {0} else return {length(arg)} & {arg} end if end function --main portion clear_screen() puts(1,"Enter some text: ") invoer = gets(0) printf(1,"The entered text was: %s\n\n",{invoer}) --now comes what all this is about: uitkomst = dissect(invoer) puts(1,"Result:\n") ? uitkomst if uitkomst[1] then puts(1,"I.e. (with a vertical bar after each item):\n") for x=1 to uitkomst[1] do printf(1,"%s|\n", {uitkomst[2][x]}) if not compare(uitkomst[2][x],"-") then puts(1,"This was a dash.\n") end if end for end if ---SNIP---
2. expression parser (simple) in EU
- Posted by Fernando Ariel Gont <Gstuff at SISCOR.BIBNAL.EDU.AR> Jan 25, 1998
- 772 views
Hi! EU>Here's a snippet I wrote some time ago from what is to be my Euphoria EU>version of a database program I originally wrote in Forth. This takes a Well, may be that this snippet was posted mainly for someone, and not for me. But as I tralked about the snippets, could it be included in "my" magazine? Bye! :) Fernando Ariel Gont Good Stuff! Magazine Editor
3. Re: expression parser (simple) in EU
- Posted by "Robert J. Zydenbos" <zydenbos at BLR.VSNL.NET.IN> Jan 26, 1998
- 769 views
- Last edited Jan 27, 1998
Fernando Ariel Gont wrote: > Well, may be that this snippet was posted mainly for someone, and > not for me. > But as I tralked about the snippets, could it be included in "my" > magazine? Sure. (Can you put me on the mailing list too?) RZ